Vue打包时候build移除左右的console

大兔子大兔子 提交于 2020-10-03 05:16:08

推荐插件:babel-plugin-transform-remove-console

Install:

 npm install babel-plugin-transform-remove-console --save-dev

 

通过.babelrc (推荐)       vue-cli3.0/babel.config.js中定义plugins:[]


// without options   这个就可以
{
  "plugins": ["transform-remove-console"]
}

// with options
{
  "plugins": [ ["transform-remove-console", { "exclude": [ "error", "warn"] }] ]
}

 

module.exports = {
  'presets': [
    '@vue/app'
  ],
  'plugins': [
    [
      'component',
      {
        'libraryName': 'element-ui',
        'styleLibraryName': 'theme-chalk'
      }
    ],
    transform-remove-console
  ]
}

 

如果只想在发布阶段生效,开发阶段不生效,需要判断:

// 项目开发阶段用到的babel插件
const prodPlugins = []
if (process.env.NODE_ENV === 'production') {
  prodPlugins.push('transform-remove-console')
}

module.exports = {
  'presets': [
    '@vue/app'
  ],
  'plugins': [
    [
      'component',
      {
        'libraryName': 'element-ui',
        'styleLibraryName': 'theme-chalk'
      }
    ],
    // 发布产品时候的插件数组
    ...prodPlugins
  ]
}

 

 

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!