-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.production.js
64 lines (63 loc) · 1.57 KB
/
webpack.production.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
const webpack = require('webpack');
const CompressionPlugin = require("compression-webpack-plugin");
const { merge } = require('webpack-merge');
const common = require('./webpack.common');
const zlib = require("zlib");
module.exports = merge(common, {
mode: 'production',
plugins: [
new webpack.LoaderOptionsPlugin({
minimize: true,
}),
new CompressionPlugin({
filename: "[path][base].gz",
algorithm: "gzip",
test: /\.js$|\.css$|\.html$/,
threshold: 10240,
minRatio: 0.8,
}),
new CompressionPlugin({
filename: "[path][base].br",
algorithm: "brotliCompress",
test: /\.(js|css|html|svg)$/,
compressionOptions: {
params: {
[zlib.constants.BROTLI_PARAM_QUALITY]: 11,
},
},
threshold: 10240,
minRatio: 0.8,
}),
],
optimization: {
runtimeChunk: true,
minimize: true,
splitChunks: {
chunks: 'async',
maxInitialRequests: Infinity,
minSize: 1000,
minChunks:1,
maxAsyncRequests: 4,
maxInitialRequests: 2,
name: true,
automaticNameDelimiter: '~',
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name(module) {
const packageName = module.context.match(
/[\\/]node_modules[\\/](.*?)([\\/]|$)/
)[1];
return `pkg.${packageName.replace('@', '')}`;
},
chunks: 'all'
},
default: {
minChunks: 2,
priority: -20,
reuseExistingChunk: true,
},
},
},
},
});