terser-webpack-plugin
terser-webpack-plugin 是一个优化和压缩 JS 资源的插件
准备
-
安装
terser-webpack-plugin
依赖yarn add terser-webpack-plugin -D
语法
-
webpack.config.js
配置webpack.mode
配置项,将mode
设置为none
mode: "none",
-
webpack.config.js
配置optimization
, 在optimization.minimizer
添加TerserWebpackPlugi
插件optimization: {
nodeEnv: false,
minimize: true,
minimizer: [new TerserWebpackPlugin()],
} -
webpack.config.js
完整配置如下所示:const TerserWebpackPlugin = require('terser-webpack-plugin');
module.exports = {
mode: "none",
optimization: {
nodeEnv: false,
minimize: true,
minimizer: [new TerserWebpackPlugin()],
},
};
}