1、安装插件 babel-plugin-transform-remove-console
2、在项目根目录中找到 babel.config.js 文件
3、添加配置
(注意,不能将插件名直接写在"plugins"数组中,那样在开发环境和生产环境下都生效; 在上方判断,只有是生产环境,才能调用该插件)
// 这是项目发布阶段需要用到的 babel 插件,默认为空
const prodPlugins=[]
// 在node进程中,当前环境如果是生产环境,将该插件推进数组中,
// 在下面的plugins数组中展开,调用该插件,清除console
if(process.env.NODE_ENV==='production'){
prodPlugins.push('transform-remove-console')
}
module.exports = {
"presets": [
"@vue/cli-plugin-babel/preset"
],
"plugins": [
[
"component",
{
"libraryName": "element-ui",
"styleLibraryName": "theme-chalk"
}
],
// 发布产品时候的插件数组
...prodPlugins,
]
}