-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.cjs
76 lines (63 loc) · 1.64 KB
/
webpack.config.cjs
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
const path = require('path');
const DotEnvPlugin = require('dotenv-webpack');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const { env } = require('process');
const nodeEnv = env.NODE_ENV || 'development';
const isProd = env.NODE_ENV === 'production';
const isProfile = env.PROFILE === 'true';
const minify = env.MINIFY == 'true' || isProd;
let plugins = [
new DotEnvPlugin({ defaults: true })
];
if (isProfile) {
plugins.unshift(new BundleAnalyzerPlugin());
}
let conf = {
mode: nodeEnv,
devtool: isProd ? false : 'inline-source-map',
entry: {
main: './src/client/index.js',
polyfills: './src/client/polyfills.js'
},
output: {
path: path.resolve(__dirname, 'build'),
filename: '[name].js'
},
resolve: {
alias: {
'@mui/styled-engine': '@mui/styled-engine-sc'
},
},
module: {
rules: [
{ test: /\.(js|jsx)$/, exclude: /node_modules/, loader: 'babel-loader' }
]
},
optimization: {
splitChunks: {
chunks: 'all',
cacheGroups: {
vendors: {
name: 'deps',
test: (mod, chunks) => {
let context = mod.context || '';
return context.indexOf('node_modules') >= 0 && !chunks.some(chunk => chunk.name === 'polyfills');
}
},
default: {
name: 'main',
minChunks: 2,
priority: -20,
reuseExistingChunk: true,
test: (mod) => {
let context = mod.context || '';
return context.indexOf('node_modules') < 0;
}
}
}
},
usedExports: minify
},
plugins
};
module.exports = conf;