使用插件 babel-plugin-transform-remove-console
1. 安装
npm install babel-plugin-transform-remove-console --save-dev
2. 使用
// babel.config.js
const productPlugins = [] // 项目发布阶段所需要的 babel 插件
if (process.env.NODE_ENV === 'production') {
// 发布模式下使用插件
productPlugins.push('transform-remove-console')
}
module.exports = {
presets: [
'@vue/cli-plugin-babel/preset'
],
plugins: [
[
'component',
{
libraryName: 'element-ui',
styleLibraryName: 'theme-chalk'
}
],
...productPlugins
]
}