1.安装 terser-webpack-plugin
2.修改 babel.config.js 文件
const TerserPlugin = require('terser-webpack-plugin')
module.exports = {
configureWebpack: config => {
config
.optimization = {
minimizer: [
new TerserPlugin({
terserOptions: {
compress: {
drop_console: true
}
}
})
]
}
}
}


网上找到这个方法报错,后来在webpack和vue-cli文档里找到configureWebpack配置方法
在vue.config.js里面配置
const TerserPlugin = require('terser-webpack-plugin')
module.exports = {
/**
*省略部分配置
。。。。。。。。。。
*/
configureWebpack(config) {
if (process.env.NODE_ENV === 'production') {
config.optimization = {
minimizer: [
new TerserPlugin({
terserOptions: {
compress: {
drop_console: true,
},
},
}),
],
}
}
config = {
...config,
name: name,
resolve: {
alias: {
'@': resolve('src'),
},
},
}
},
}
需要说明,terser-webpack-plugin不需要安装,因为vue脚手架也用到直接引用即可
网友评论