Instale o plug-in terser-webpack-plugin
Site oficial do plug-in terser-webpack-plugin: https://www.npmjs.com/package/terser-webpack-plugin
Primeiro, você precisa instalar o terser-webpack-plugin :
npm install terser-webpack-plugin --save-dev
Em seguida, adicione o plugin ao arquivo de configuração do webpack. Por exemplo:
webpack.config.js:
const TerserPlugin = require("terser-webpack-plugin");
module.exports = {
configureWebpack: config => {
config.optimization = {
minimize: true,
minimizer: [new TerserPlugin({
terserOptions: {
mangle: {
safari10: true,
},
compress: {
// 是否在UglifyJS删除没有用到的代码时输出警告信息,默认为输出,可以设置为false关闭这些作用不大的警告
warnings: false,
// 是否删除代码中所有的console语句,默认为不删除,开启后,会删除所有的console语句
drop_console: true,
pure_funcs: ['console.log'] // 移除console
}
}
})],
}
}
O acima contém algumas configurações comumente usadas
- Exclua todas
console
as instruções no código -drop_console: true
;