webpack项目发布阶段移除所有console

使用插件 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
  ]
}

猜你喜欢

转载自blog.csdn.net/tyoubinn/article/details/108931029