美文网首页
vue-cli 3.0生产环境中去除console的插件

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

作者: 时光已翩然轻擦 | 来源:发表于2020-09-15 14:58 被阅读0次

一、推荐插件:

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
    }
  }
}

三、参考资料

相关文章

网友评论

      本文标题:vue-cli 3.0生产环境中去除console的插件

      本文链接:https://www.haomeiwen.com/subject/gessrktx.html