-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.prod.js
71 lines (65 loc) · 1.94 KB
/
webpack.prod.js
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
import VARS from '../vars';
import WEBPACK_OPTIONS from './webpack.options';
/* ---------------------------------------------------------------------------------------------- */
export default () => ({
// Controls if and how source maps are generated.
// https://webpack.js.org/configuration/devtool/
devtool: 'nosources-source-map',
// Tell Webpack to use its built-in optimizations accordingly.
// https://webpack.js.org/configuration/mode/
mode: 'production',
// Optimize assets.
// https://webpack.js.org/configuration/optimization/
optimization: {
// Minimize the bundle using the TerserPlugin or the plugin(s) specified in optimization.minimizer.
minimize: true,
// Override the default minimizer.
minimizer: [
WEBPACK_OPTIONS.PLUGINS.TERSER, //
WEBPACK_OPTIONS.PLUGINS.OPTIMIZE_CSS,
],
runtimeChunk: 'single',
splitChunks: {
cacheGroups: {
commons: {
chunks: 'initial',
maxInitialRequests: 5,
minChunks: 2,
minSize: 0,
},
styles: {
chunks: 'all',
enforce: true,
name: 'styles',
test: /\.css$/,
},
vendor: {
chunks: 'all',
name: (module) => {
const packageName = module.context.match(
/[\\/]node_modules[\\/](.*?)([\\/]|$)/,
)[1];
return `npm.${packageName.replace('@', '')}`;
},
test: /[\\/]node_modules[\\/]/,
},
},
chunks: 'all',
maxInitialRequests: Infinity,
minSize: 0,
},
},
// How and where to output bundles, assets and anything else bundled or loaded with Webpack.
// https://webpack.js.org/configuration/output/
output: {
chunkFilename: `${VARS.DIR.SCRIPT}/[id].[contenthash].chunk.js`,
filename: `${VARS.DIR.SCRIPT}/[name].[contenthash].js`,
},
// Additional plugins to customize the webpack build.
// https://webpack.js.org/configuration/plugins/
plugins: [
WEBPACK_OPTIONS.PLUGINS.MINI_CSS_EXTRACT,
WEBPACK_OPTIONS.PLUGINS.COMPRESSION,
WEBPACK_OPTIONS.PLUGINS.HASHED_MODULE_IDS,
],
});