babel-plugin-transform-remove-console移除项目代码在中的console.*

1.安装

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

2.在babel.config.js的plugins中配置"transform-remove-console"

plugins: [
    [
      'component',
      {
        libraryName: 'element-ui',
        styleLibraryName: 'theme-chalk'
      }
    ],
    'transform-remove-console'
  ]

3.重新启动项目【我是重新启动了vscode】,执行npm run build打包后的文件中,console.*被移除

如果只在发布阶段移除所有的console,需要对配置做如下修改

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

module.exports = {
  presets: [
    '@vue/cli-plugin-babel/preset'
  ],
  plugins: [
    [
      'component',
      {
        libraryName: 'element-ui',
        styleLibraryName: 'theme-chalk'
      }
    ],
    ...prodPlugins
  ]
}

附:https://www.npmjs.com/package/babel-plugin-transform-remove-console

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容