第一种
安装插件
npm install babel-plugin-transform-remove-console --save
修改babel.config.js文件
let transformRemoveConsolePlugin = []
if (process.env.NODE_ENV === 'production') {
transformRemoveConsolePlugin = ['transform-remove-console']
}
module.exports = {
plugins: [
...transformRemoveConsolePlugin
]
}
第二种
安装插件
npm install terser-webpack-plugin --save
修改babel.config.js文件
const TerserPlugin = require('terser-webpack-plugin')
module.exports = {
configureWebpack: config => {
config.optimization = {
minimizer: [
new TerserPlugin({
terserOptions: {
compress: {
drop_console: true
}
}
})
]
}
}
}