-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.prod.js
44 lines (39 loc) · 1.24 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
const path = require("path");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const MiniCSSExtractPlugin = require("mini-css-extract-plugin");
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
const TerserPlugin = require("terser-webpack-plugin");
const commonConfig = require("./webpack.common");
const commonPlugins = commonConfig.plugins;
const commonRules = commonConfig.module.rules;
commonRules[0].use.unshift(MiniCSSExtractPlugin.loader); // external css
commonRules.push({
test: /\.js$/i,
exclude: /(node_modules)/,
use: {
loader: "babel-loader",
options: {
presets: ["@babel/preset-env"],
},
},
});
commonPlugins.push(
new CleanWebpackPlugin(),
new MiniCSSExtractPlugin({
filename: "assets/style.[chunkhash].css",
})
);
const config = {
output: {
path: path.resolve(__dirname, "docs"),
filename: "assets/[name].[chunkhash].js",
chunkFilename: "assets/[name].[chunkhash].js",
},
mode: "production",
optimization: {
splitChunks: { chunks: "all" },
minimize: true,
minimizer: [new CssMinimizerPlugin(), new TerserPlugin()],
},
};
module.exports = Object.assign({}, commonConfig, config);