GZIP 压缩

1
npm install compression-webpack-plugin --save-dev
1
2
3
const CompressionPlugin = require("compression-webpack-plugin");
// 使用
cfg.plugins.push(new CompressionPlugin());

ES6 压缩

使用 terser-webpack-plugin 插件对 es6 语法的 js 文件进行压缩。

1
npm install terser-webpack-plugin --save-dev
1
2
3
4
5
6
7
8
9
10
11
12
13
14
const TerserPlugin = require("terser-webpack-plugin");
// 使用
cfg.plugins.push(
new TerserPlugin({
cache: true,
parallel: true,
sourceMap: true,
terserOptions: {
compress: {
drop_debugger: true,
},
},
})
);

注意:使用 UglifyJs 打包会报错。
提示不能识别 const 等 ES6 的语法:

1
Unexpected token: keyword «const» [js/vendor.58d16842.js:46032,0]

评论