This repository was archived by the owner on May 30, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
92 lines (86 loc) · 2.23 KB
/
Copy pathwebpack.config.js
File metadata and controls
92 lines (86 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
const CircularDependencyPlugin = require('circular-dependency-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const path = require('path');
const webpack = require('webpack');
const DEV_SERVER = process.argv.find(v => v.includes('serve'));
const MODE = process.env.NODE_ENV || 'production';
const config = {
entry: {
main: [
path.resolve(process.cwd(), 'src/index.ts'),
],
},
externals: [],
mode: MODE,
module: {
rules: [
{
exclude: /node_modules/,
test: /\.elm$/,
use: [{
loader: require.resolve('elm-webpack-loader'),
options: {
optimize: MODE === 'production',
},
}],
},
{
exclude: /node_modules/,
test: /\.(ts|tsx)$/,
use: [{
loader: require.resolve('babel-loader'),
}],
},
],
},
optimization: {
// https://webpack.js.org/plugins/split-chunks-plugin/#split-chunks-example-2
splitChunks: {
cacheGroups: {
commons: {
chunks: 'all',
name: 'vendors',
test: /[\\/]node_modules[\\/]/,
},
},
},
},
output: {
filename: '[name].js',
path: path.resolve(process.cwd(), 'dist'),
publicPath: '/',
},
plugins: [
new webpack.DefinePlugin([
'NODE_ENV',
].reduce((obj, key) => ({ ...obj, [`process.env.${key}`]: JSON.stringify(process.env[key]) }), {
'process.env.PACKAGE_VERSION': JSON.stringify(require('./package.json').version),
})),
new CircularDependencyPlugin({ exclude: /.elm|.html|node_modules/, failOnError: true }),
new HtmlWebpackPlugin({ filename: 'index.html', template: 'src/index.html' }),
],
resolve: {
extensions: ['.elm', '.js', '.json', '.jsx', '.ts', '.tsx'],
modules: [path.resolve(process.cwd(), 'node_modules'), 'node_modules', 'src'],
},
target: 'web',
};
if (DEV_SERVER) {
config.devServer = {
contentBase: path.join(__dirname, 'dist'),
historyApiFallback: true,
host: process.env.HOST || '0.0.0.0',
hot: true,
port: 3000,
publicPath: '/',
};
}
switch (MODE) {
case 'development':
config.devtool = 'eval-source-map';
break;
case 'production':
default:
break;
}
module.exports = config;