clean-debugger-plugin

1.0.0 • Public • Published

目标

移除上线前 debug 代码的 plugins

使用方式

# 1. 项目中执行
npm install -D remove-debugger-plugin

# 2. babelrc中添加
{
  plugins: ["no-debugging"]
}

这个插件默认会移除 debugger;  console 调用。

这个插件可以移除 debugger  console  alert  自定义的调试函数调用和定义。

为保证在开发阶段不转换代码,记得将这个插件只配置在发布阶段:

# babelrc
{
 {
  "env": {
    "publish": {
      "presets": [
        "@babel/preset-env"
      ],
      "plugins": ["no-debugging"]
    }
  }
}

# package.json script
{
  "scripts": {
    "build": "cross-env BABEL_ENV=publish webpack", # 类似
  },
}

options

Property Type Default Description
debugger Boolean true 移除断点调试 debugger 代码
console Boolean true 函数调用
alert Boolean null 函数调用
debugFn String null 指定的自定义调试代码函数(包括调试函数声明和调用)

使用

例子

  1. 使用默认配置
.babelrc

{
  plugins: [
    [
      "no-debugging"
    ]
  ]
}

转换前:

const a = 12
const b = 13

function add(m, n) {
  debugger
  return m + n
}

const result = add(a, b)

console.log(result)

转换后:

const a = 12
const b = 13

function add(m, n) {
  return m + n
}

const result = add(a, b)
  1. 自定义配置 移除 alert
.babelrc

{
  plugins: [
    [
      "no-debugging",
      {
        alert: true,
        console: false
      }
    ]
  ]
}

转换前:

const a = 12
const b = 13

function add(m, n) {
  debugger
  return m + n
}

alert(result)

const result = add(a, b)

console.log(result)

转换后:

const a = 12
const b = 13

function add(m, n) {
  return m + n
}

const result = add(a, b)

console.log(result)

Readme

Keywords

Package Sidebar

Install

npm i clean-debugger-plugin

Weekly Downloads

1

Version

1.0.0

License

ISC

Unpacked Size

5.66 kB

Total Files

5

Last publish

Collaborators

  • muzhang