-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.prod.js
104 lines (101 loc) · 3.69 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
const merge = require("webpack-merge");
const common = require("./webpack.common.js");
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin");
function getUglifyOptions() {
const uglifyCompressOptions = {
pure_getters: true,
// PURE comments work best with 3 passes.
// See https://github.com/webpack/webpack/issues/2899#issuecomment-317425926.
passes: 3,
};
return {
ecma: 6,
warnings: true, // disable verbose?
ie8: false,
mangle: true,
compress: uglifyCompressOptions,
output: {
ascii_only: true,
comments: false
},
beautify: false // set to true for debugging
};
}
module.exports = merge(common, {
mode: "production",
/**
* Stats lets you precisely control what bundle information gets displayed
* reference: https://webpack.js.org/configuration/stats/
*/
stats: {
chunkModules: true,
chunkOrigins: true,
reasons: true,
maxModules: Infinity, // examine all modules (ModuleConcatenationPlugin debugging)
optimizationBailout: true, // display bailout reasons (ModuleConcatenationPlugin debugging)
},
performance: {
hints: "warning",
},
// reference: https://medium.com/webpack/webpack-4-mode-and-optimization-5423a6bc597a
optimization: {
removeAvailableModules: true,
removeEmptyChunks: true,
mergeDuplicateChunks: true,
flagIncludedChunks: true,
occurrenceOrder: true,
providedExports: true,
usedExports: true,
sideEffects: true,
concatenateModules: true,
runtimeChunk: true,
noEmitOnErrors: true,
minimizer: [
// minimization libraries to use
/**
* Plugin: UglifyJsPlugin
* Description: Minimize all JavaScript output of chunks.
* Loaders are switched into minimizing mode.
*
* See: https://github.com/webpack-contrib/uglifyjs-webpack-plugin
*/
new UglifyJsPlugin({
parallel: true, // use multi-process parallel running to improve the build speed (default concurrent processes: os.cpus().length - 1)
sourceMap: true, // useful to still be able to debug in production
uglifyOptions: getUglifyOptions(),
exclude: [
/\/prettier\/parser-.*/, // prettier parsers are the biggest chunks and are already minified :p
/\/prettier\/standalone\.js/ // also one of the prettier's biggest chunks
],
cache: true,
}),
new OptimizeCSSAssetsPlugin({}),
],
splitChunks: {
// reference: https://webpack.js.org/plugins/split-chunks-plugin/
chunks: "all", // include all types of chunks (async or not)
cacheGroups: {
// assign modules to cache groups
// cache group for all modules from node_modules that are duplicated in at least 2 chunks
vendors: {
test: /[\\/]node_modules[\\/]/,
name: "vendor",
chunks: "all",
priority: -10,
},
styles: {
name: "styles",
test: /\.css$/,
chunks: "all",
enforce: true,
},
default: {
minChunks: 2,
priority: -20,
reuseExistingChunk: true,
}
}
}
},
});