Bootstrap

vue使用babel-plugin-transform-remove-console解决项目打包时去除console语句

vue项目打包时出现警告:warning Unexpected console statement no-console
在这里插入图片描述

解决方案:

1、安装babel-plugin-transform-remove-console插件

在这里插入图片描述
在这里插入图片描述

2、在配置文件中添加transform-remove-console使其只在生产环境中生效

在vue项目中找到babel.config.js文件添加配置

// 这是项目发布阶段需要用到的 babel 插件
const prodPlugins = []
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
  ]
}

在这里插入图片描述
重新打包项目console警告问题解决:
在这里插入图片描述

;