安装:
npm i -D uglifyjs-webpack-plugin
报错:
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! Found: webpack@5.64.1
npm ERR! node_modules/webpack
npm ERR! peer webpack@"4.x.x || 5.x.x" from @webpack-cli/configtest@1.1.0
npm ERR! node_modules/@webpack-cli/configtest
npm ERR! @webpack-cli/configtest@"^1.1.0" from webpack-cli@4.9.1
npm ERR! node_modules/webpack-cli
npm ERR! peer webpack-cli@"4.x.x" from @webpack-cli/configtest@1.1.0
npm ERR! 3 more (@webpack-cli/info, @webpack-cli/serve, the root project)
npm ERR! peer webpack@">=2" from babel-loader@8.2.3
使用terser-webpack-plugin替换uglify插件。具体步骤:
1. 安装
npm install terser-webpack-plugin -D
2. webpack.config.js配置
// 引入插件
const TerserWebpackPlugin = require("terser-webpack-plugin");
// 配置参数
module.exports = {
...
optimization: {
minimize: true,
minimizer: [new TerserWebpackPlugin ()],
},
};
3. 执行npm run dev,bundle.js中的代码被压缩
?
|