{"id":13671389,"url":"https://github.com/huruji/babel-plugin-no-debugging","last_synced_at":"2025-04-10T16:12:25.910Z","repository":{"id":97309287,"uuid":"158013815","full_name":"huruji/babel-plugin-no-debugging","owner":"huruji","description":"上线前去掉调试代码的Babel插件","archived":false,"fork":false,"pushed_at":"2018-11-20T09:33:48.000Z","size":26,"stargazers_count":19,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-01T22:14:56.134Z","etag":null,"topics":["babel","babel-plugin"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/huruji.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-11-17T18:38:39.000Z","updated_at":"2023-05-10T23:42:05.000Z","dependencies_parsed_at":null,"dependency_job_id":"f95fdf54-e652-4c63-a612-7974ac9567aa","html_url":"https://github.com/huruji/babel-plugin-no-debugging","commit_stats":{"total_commits":28,"total_committers":2,"mean_commits":14.0,"dds":0.0357142857142857,"last_synced_commit":"fff4438d7fa3b144f2945f99772499669ee37804"},"previous_names":["huruji/babel-plugin-no-dubugging"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huruji%2Fbabel-plugin-no-debugging","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huruji%2Fbabel-plugin-no-debugging/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huruji%2Fbabel-plugin-no-debugging/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huruji%2Fbabel-plugin-no-debugging/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/huruji","download_url":"https://codeload.github.com/huruji/babel-plugin-no-debugging/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248251122,"owners_count":21072685,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["babel","babel-plugin"],"created_at":"2024-08-02T09:01:08.250Z","updated_at":"2025-04-10T16:12:25.897Z","avatar_url":"https://github.com/huruji.png","language":"JavaScript","readme":"# babel-plugin-no-debugging\n上线前去掉调试代码的Babel插件\n\n## 安装\n\n```js\nnpm install -D babel-plugin-no-debugging\n```\n\n## 使用\n\n`.babelrc`\n```js\n{\n  plugins: [\"no-debugging\"]\n}\n```\n\n这个插件默认会移除 `debugger;` 和 `console` 调用。\n\n这个插件可以移除 `debugger` 、 `console` 、 `alert` 和 自定义的调试函数调用和定义。自定义的debugger函数常常在不好调试的端环境中使用，如在可抓包环境下发起一个简单请求判断代码是否运行到某个位置\n\n\u003e 注意：据笔者了解 `alert` 函数调用仍然大量存在于各类管理后台系统中，开启时需要注意。\n\n为保证在开发阶段不转换代码，记得将这个插件只配置在发布阶段：\n\n`.babelrc`\n\n```js\n{\n {\n  \"env\": {\n    \"publish\": {\n      \"presets\": [\n        \"@babel/preset-env\"\n      ],\n      \"plugins\": [\"no-debugging\"]\n    }\n  }\n}\n```\n\n在项目的 `package.json` 中配置好 `scripts` 会更加方便：\n\n```\n{\n  \"scripts\": {\n    \"build\": \"cross-env BABEL_ENV=publish webpack\",\n  },\n}\n```\n\n## options\n\n\n| Property | Type    | Default | Description                                             |\n| -------- | ------- | ------- | ------------------------------------------------------- |\n| debugger | Boolean | true    | 移除断点调试 `debugger;` 代码                           |\n| console  | Boolean | true    | 移除 `console` 函数调用                                 |\n| alert    | Boolean | null    | 移除 `alert` 函数调用                                   |\n| debugFn  | String  | null    | 移除 指定的自定义调试代码函数（包括调试函数声明和调用） |\n\n\n## 例子\n\n### 使用默认配置：\n\n`.babelrc`\n\n```js\n{\n  plugins: [\n    [\n      \"no-debugging\"\n    ]\n  ]\n}\n```\n\n转换前：\n\n```js\nconst a = 12;\nconst b = 13;\n\nfunction add(m, n) {\n  debugger;\n  return m + n;\n}\n\nconst result = add(a, b);\n\nconsole.log(result);\n```\n\n转换后：\n\n```js\nconst a = 12;\nconst b = 13;\n\nfunction add(m, n) {\n  return m + n;\n}\n\nconst result = add(a, b);\n\n```\n\n### 自定义配置\n\n移除 `alert` 和 自定义的 debugger 函数\n\n`.babelrc`\n\n```js\n{\n  plugins: [\n    [\n      \"no-debugging\",\n      {\n        alert: true,\n        debugFn: \"requestDebug\",\n        console: false\n      }\n    ]\n  ]\n}\n```\n\n转换前：\n\n```js\n\nconst a = 12;\nconst b = 13;\n\nfunction requestDebug(name) {\n  const debugjs = 'https://example.com/debugger.js'\n  request(`${debugjs}?name=${name}`).then(()=\u003e{\n    // your code\n  })\n}\n\nfunction add(m, n) {\n  debugger;\n  return m + n;\n}\n\nalert(result);\n\nconst result = add(a, b);\n\nconsole.log(result);\n\nrequestDebug(result);\n\n```\n\n转换后：\n\n```js\nconst a = 12;\nconst b = 13;\n\n\nfunction add(m, n) {\n  return m + n;\n}\n\n\nconst result = add(a, b);\n\nconsole.log(result);\n\n```","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhuruji%2Fbabel-plugin-no-debugging","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhuruji%2Fbabel-plugin-no-debugging","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhuruji%2Fbabel-plugin-no-debugging/lists"}