使用babel-plugin-transform-remove-console
插件
首先安装此插件:
npm install babel-plugin-transform-remove-console --save-dev
OR
yarn add babel-plugin-transform-remove-console
重点:
babel.config.js配置如下:
const plugins = ["@vue/babel-plugin-transform-vue-jsx"]
// 生产环境移除console
if(process.env.NODE_ENV === 'production') {
plugins.push("transform-remove-console")
}
module.exports = {
plugins: plugins,
presets: [
[
'@vue/app',
{
useBuiltIns: 'entry'
}
]
]
}