1. 去除打印信息 terser-webpack-plugin: ^4.2.3
npm install -D terser-webpack-plugin@4.2.3
const TerserPlugin = require("terser-webpack-plugin");
module.exports = {
plugins: [
new TerserPlugin({
cache: true,
sourceMap: false,
parallel: true,
terserOptions: {
warnings: false,
compress: {
drop_console: true,
drop_debugger: false,
pure_funcs: ['console.log'],
},
},
});
]
}
2. 打包优化 happypack
npm install -D happypack
const HappyPack = require("happypack");
module.exports = {
module: {
rules: [{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
use: { loader: "happypack/loader?id=happyBabel" }
}]
},
plugins: [
new HappyPack({
id: "happyBabel",
loaders: ["babel-loader?cacheDirectory"],
threads: 5,
}),
]
}