-
Notifications
You must be signed in to change notification settings - Fork 2
/
webpack.config.prod.js
62 lines (61 loc) · 1.83 KB
/
webpack.config.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
const merge = require("webpack-merge");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const CompressionWebpackPlugin = require("compression-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const baseConfig = require("./webpack.config");
module.exports = merge(baseConfig, {
mode: "production",
devtool: "source-map",
optimization: {
splitChunks: {
chunks: "async",
minSize: 30000,
maxSize: 0,
minChunks: 1,
maxAsyncRequests: 5,
maxInitialRequests: 3,
automaticNameDelimiter: "~",
name: false,
cacheGroups: {
vendors: {
name: `chunk-vendors`,
test: /[\\/]node_modules[\\/]/,
priority: -10,
chunks: "initial"
},
common: {
name: `chunk-common`,
minChunks: 2,
priority: -20,
chunks: "initial",
reuseExistingChunk: true
}
}
}
},
plugins: [
new CleanWebpackPlugin(),
new CompressionWebpackPlugin({
algorithm: "brotliCompress", // 压缩算法,Node 11.7.0 对 Brotli 有内置支持
test: /\.(js|css)(\?.*)?$/i, // 压缩 js 和 css
threshold: 10240, // 大于 10kb 的资源才会压缩
minRatio: 0.8 // 压缩比大于 0.8 的资源才会压缩
}),
new HtmlWebpackPlugin({
title: "web-im",
template: "./src/index.html",
favicon: "./src/favicon.ico",
hash: true, //防止缓存
minify: {
removeComments: true, //删除Html注释
collapseWhitespace: true, //去除空格
removeAttributeQuotes: true //去除属性引号
}
}),
new MiniCssExtractPlugin({
filename: "static/css/index.[hash].css",
chunkFilename: "static/chunks/[id].css"
})
]
});