-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.prod.js
More file actions
85 lines (81 loc) · 2.15 KB
/
Copy pathwebpack.prod.js
File metadata and controls
85 lines (81 loc) · 2.15 KB
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
const path = require("path");
const webpack = require("webpack");
const merge = require("webpack-merge");
const baseConfig = require("./webpack.base");
const ManifestPlugin = require("webpack-manifest-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const ParallelUglifyPlugin = require("webpack-parallel-uglify-plugin");
const BundleAnalyzerWebpackPlugin = require("webpack-bundle-analyzer")
.BundleAnalyzerPlugin;
const prodConfig = {
entry: {
main: ["@babel/polyfill", "./src/index.js"],
},
mode: "production",
devtool: "cheap-module-source-map",
output: {
path: path.resolve(__dirname, "./dist"),
filename: "[name].[contenthash:8].js",
chunkFilename: "[name].[contenthash:8].chunk.js",
},
module: {
rules: [
{
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader,
"css-loader",
"postcss-loader",
],
},
{
test: /\.scss$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: "css-loader",
options: {
modules: false,
importLoaders: 2, // 这里的importLoaders: 2 是在css-loader 之后指定2个数量的loader(即 postcss-loader)来处理import进来的资源
},
},
"sass-loader",
"postcss-loader",
],
},
],
},
plugins: [
new MiniCssExtractPlugin({
filename: "[name].[contenthash:8].css",
chunkFilename: "[id].[contenthash:8].css",
}),
new ManifestPlugin(),
],
optimization: {
splitChunks: {
chunks: "all",
},
minimizer: [
new ParallelUglifyPlugin({
cacheDir: ".cache/",
uglifyJS: {
output: {
comments: false,
beautify: false,
},
compress: {
drop_console: true,
collapse_vars: true,
reduce_vars: true,
},
},
}),
],
},
};
// 判断环境变量,是否开启分析报告
if (process.env.npm_config_report) {
prodConfig.plugins.push(new BundleAnalyzerWebpackPlugin());
}
module.exports = merge(baseConfig, prodConfig);