使用图形化界面vue ui运行build命令报错,Unexpected console statement
于是在开发依赖安装了 babel-plugin-transform-remove-console
并且在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
]
}
重新运行build命令依旧报错,还是Unexpected console statement
查了网上都是按这样配置就没问题,我配置了却不起作用?
希望能解决babel-plugin-transform-remove-console无法去除console的问题,实现去除
这里报错是因为eslint的校验规则报错的,可以在eslint的配置文件中关闭
https://segmentfault.com/a/1190000021582760
https://blog.csdn.net/qq_44690237/article/details/98471262
https://www.jianshu.com/p/4c7820851c90
https://blog.csdn.net/qq_44690237/article/details/98471262
// 如果是生产环境,则自动清理掉打印的日志,但保留error 与 warn
prodPlugin.push([
'transform-remove-console',
{
// 保留 console.error 与 console.warn
exclude: ['error', 'warn']
}
])
你现在的这个报错 应该是eslint报错吧, 关掉eslint的这条规则吧 no-console
babel-plugin-transform-remove-console 是打包时去掉,他并不会把你代码里面去掉的