-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathwebpack.prod.js
62 lines (61 loc) · 2.08 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
const { merge } = require('webpack-merge');
const common = require('./webpack.common.js');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const { WebpackManifestPlugin } = require('webpack-manifest-plugin');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const TerserPlugin = require('terser-webpack-plugin');
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const lightningcss = require('lightningcss');
const browserslist = require('browserslist');
module.exports = env => {
return merge(common(env), {
mode: 'production',
output: {
clean: true,
filename: 'js/[name].[contenthash].js',
chunkFilename: 'js/[name].[contenthash].js',
assetModuleFilename: 'assets/[name].[contenthash][ext]',
},
plugins: [
// 打包分析
// new BundleAnalyzerPlugin(),
// 生成 manifest.json
new WebpackManifestPlugin(),
// 将 css 从 js 中分离
new MiniCssExtractPlugin({
filename: "css/[name].[contenthash].css",
}),
],
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
parallel: true,
}),
new CssMinimizerPlugin({
minify: CssMinimizerPlugin.lightningCssMinify,
minimizerOptions: {
targets: lightningcss.browserslistToTargets(browserslist('>= 0.25%'))
},
}),
],
splitChunks: {
chunks: 'all',
cacheGroups: {
libAntd: {
test: /[\\/]node_modules[\\/]antd[\\/]/, // 匹配 antd 库
name: 'lib-antd', // 输出的文件名
priority: 20, // 优先级,数值越大优先级越高
reuseExistingChunk: true, // 复用已存在的 chunk
},
libLodash: {
test: /[\\/]node_modules[\\/]antd[\\/]/, // 匹配 antd 库
name: 'lib-lodash', // 输出的文件名
priority: 20, // 优先级,数值越大优先级越高
reuseExistingChunk: true, // 复用已存在的 chunk
},
},
},
},
});
}