-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.prod.cjs
55 lines (53 loc) · 1.31 KB
/
webpack.prod.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
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin')
const CopyPlugin = require('copy-webpack-plugin')
const TerserPlugin = require('terser-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')
const IS_ANALYZE = process.env.IS_ANALYZE === 'true'
module.exports = () => {
const config = {
plugins: [
new CopyPlugin({
patterns: [
{
from: 'public',
globOptions: {
gitignore: true,
ignore: ['**/index.html']
}
}
]
}),
new MiniCssExtractPlugin({
filename: 'static/css/[name].[contenthash:8].css'
})
],
// 优化项配置
optimization: {
// 是否压缩
minimize: true,
// 压缩工具
minimizer: [
new TerserPlugin({
terserOptions: {
format: {
comments: false
}
},
// 是否将注释剥离到单独的文件中
extractComments: false
}),
new CssMinimizerPlugin()
]
}
}
if (IS_ANALYZE) {
config.plugins.unshift(
new BundleAnalyzerPlugin({
generateStatsFile: true
})
)
config.performance = false
}
return config
}