vue-cli 3.0生产环境中去除console的插件

一、推荐插件:

babel-plugin-transform-remove-console

1. 安装
$ npm install babel-plugin-transform-remove-console -D
# 或者
$  yarn add babel-plugin-transform-remove-console --dev
2. 配置

【babel.config.js】中配置如下:

const plugins = []
// 生产环境移除console
if (process.env.NODE_ENV === 'production') {
  plugins.push('transform-remove-console')
}
module.exports = {
  plugins: [...plugins]
}

二、其他插件

terser-webpack-plugin

1. 安装
$ npm install terser-webpack-plugin -D
2. 配置

【vue.config.js】中配置如下

module.export = {
  configureWebpack: (config)=>{
    if(process.env.NODE_ENV === 'production'){
      config.optimization.minimizer[0].options.terserOptions.compress.drop_console = true
    }
  }
}

三、参考资料

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。