babel-plugin-transform-remove-console插件(vue优化build时消除console.log)

官方npm文档:     https://www.npmjs.com/package/babel-plugin-transform-remove-console
下载安装:        npm install babel-plugin-transform-remove-console --save-dev

安装之后在bable.config.js文件中进行设置

可以直接 

'transform-remove-console'

但是这样会导致开发时也不能正常使用console.log!

所以我们判定

const prodPlugins = []
if (process.env.NODE_ENV === 'production') {
  prodPlugins.push('transform-remove-console')  
}

module.exports = {
  
  presets: [],
      //发布产品时候的插件数组
  ...prodPlugins,  
}

 

posted @ 2020-09-21 20:05  缔造cool  阅读(1327)  评论(0)    收藏  举报