首页 > 编程语言 >Javascript打包后移除console语句

Javascript打包后移除console语句

时间:2023-02-07 09:25:02浏览次数:59  
标签:console plugin babel Javascript transform remove 后移 plugins

NodeJS项目安装包

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

配置Babel

const plugins = []
//如果不是开发环境则启用
if (process.env.NODE_ENV !== 'development') {
  //禁用console功能,但允许console.error
  plugins.push(["transform-remove-console", { "exclude": [ "error"] }])
}

module.exports = {
  presets: [
    '@vue/cli-plugin-babel/preset'
  ],
  plugins: plugins
}

参考链接

https://babeljs.io/docs/en/babel-plugin-transform-remove-console/
https://www.npmjs.com/package/babel-plugin-transform-remove-console

标签:console,plugin,babel,Javascript,transform,remove,后移,plugins
From: https://www.cnblogs.com/cqpanda/p/17093268.html

相关文章