{"id":27324086,"url":"https://github.com/qinzhen001/babel7-demo","last_synced_at":"2026-04-26T23:30:59.934Z","repository":{"id":218726811,"uuid":"747108850","full_name":"QinZhen001/babel7-demo","owner":"QinZhen001","description":":hammer: babel7-demo","archived":false,"fork":false,"pushed_at":"2024-12-29T06:12:12.000Z","size":120,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-12T10:56:35.904Z","etag":null,"topics":["babel","babel7"],"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/QinZhen001.png","metadata":{"files":{"readme":"README.md","changelog":null,"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,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-01-23T09:31:53.000Z","updated_at":"2024-12-29T06:12:15.000Z","dependencies_parsed_at":null,"dependency_job_id":"74fadbc7-df77-4d7a-baaa-b3083cfd5a17","html_url":"https://github.com/QinZhen001/babel7-demo","commit_stats":null,"previous_names":["qinzhen001/babel7-demo"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/QinZhen001/babel7-demo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/QinZhen001%2Fbabel7-demo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/QinZhen001%2Fbabel7-demo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/QinZhen001%2Fbabel7-demo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/QinZhen001%2Fbabel7-demo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/QinZhen001","download_url":"https://codeload.github.com/QinZhen001/babel7-demo/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/QinZhen001%2Fbabel7-demo/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32317162,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-26T23:26:28.701Z","status":"ssl_error","status_checked_at":"2026-04-26T23:26:25.802Z","response_time":129,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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","babel7"],"created_at":"2025-04-12T10:54:38.592Z","updated_at":"2026-04-26T23:30:59.915Z","avatar_url":"https://github.com/QinZhen001.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# babel7-demo\n\n[https://juejin.cn/post/6984020141746946084#heading-7](https://juejin.cn/post/6984020141746946084#heading-7)\n\nbabel7-demo\n\n可以将下面的 .babelrc 内容替换 运行 build 命令，查看 dist 输出文件，对比差异\n\n## .babelrc\n\n`@babel/preset-env`和`plugin-transform-runtime`二者都可以设置使用`corejs`来处理`polyfill`，二者各有使用场景，在项目开发和类库开发的时候可以使用不同的配置。\n\n### 真实项目\n\n如果用到 @babel/preset-env 的 useBuiltIns 需要安装 core-js\n\n`useBuiltIns`使用`usage`，尽量使用社区广泛使用的优质库以优化打包体积，不使用暂未进入规范的特性。`plugin-transform-runtime`只使用其移除内联复用的辅助函数的特性，减小打包体积。\n\n```ts\n{\n  \"presets\": [\n    [\n      \"@babel/preset-env\",\n      {\n        \"targets\": {\n          \"browsers\": [\n            \"last 2 versions\",\n            \"ie \u003e= 11\"\n          ]\n        },\n        \"corejs\":{\n          \"version\": 3,\n          \"proposals\": false\n        },\n        \"useBuiltIns\": \"usage\"\n      }\n    ]\n  ],\n  \"plugins\": [\n     // 需要安装 @babel/runtime\n    \"@babel/plugin-transform-runtime\"\n  ]\n}\n```\n\n### 第三方库\n\n**不需要 安装 core-js**\n\n**需要安装 @babel/runtime-corejs3**\n\n类库开发尽量不使用污染全局环境的`polyfill`，因此`@babel/preset-env`只发挥语法转换的功能，`polyfill`由`plugin-transform-runtime`来处理\n\n```ts\n{\n  \"presets\": [\n    [\n      \"@babel/preset-env\"\n    ]\n  ],\n  \"plugins\": [\n    [\n      \"@babel/plugin-transform-runtime\",\n      {\n        \"corejs\": {\n          \"version\": 3,\n          \"proposals\": false\n        }\n      }\n    ]\n  ]\n}\n```\n\n## @babel/preset-env\n\n[https://babeljs.io/docs/babel-preset-env#install](https://babeljs.io/docs/babel-preset-env#install)\n\n### debug\n\n[https://babeljs.io/docs/babel-preset-env#debug](https://babeljs.io/docs/babel-preset-env#debug)\n\nOutputs to `console.log` the polyfills and transform plugins enabled by `preset-env` and, if applicable, which one of your targets that needed it.\n\n打印出来相关的 polyfills and transform plugins\n\n### useBuiltIns\n\nhttps://babeljs.io/docs/babel-preset-env#usebuiltins\n\nThis option configures how `@babel/preset-env` handles polyfills.\n\n`\"usage\"` | `\"entry\"` | `false`, defaults to `false`.\n\nWhen either the `usage` or `entry` options are used, `@babel/preset-env` will add direct references to `core-js` modules as bare imports (or requires). This means `core-js` will be resolved relative to the file itself and needs to be accessible.\n\n**当设置了 useBuiltIns 需要安装 core-js**\n\n```ts\nyarn add core-js@3\n```\n\n## @babel/plugin-transform-runtime\n\n### default options\n\n[https://babeljs.io/docs/babel-plugin-transform-runtime#options](https://babeljs.io/docs/babel-plugin-transform-runtime#options)\n\n```ts\n{\n  \"plugins\": [\n    [\n      \"@babel/plugin-transform-runtime\",\n      {\n        \"absoluteRuntime\": false,\n        \"corejs\": false,\n        \"helpers\": true,\n        \"regenerator\": true,\n        \"version\": \"7.0.0-beta.0\"\n      }\n    ]\n  ]\n}\n```\n\n### @babel/runtime-corejs3\n\n\u003e 需要安装在 dependencies\n\u003e 它是 `@babel/runtime` 的升级版，它不仅仅包含 `@babel/runtime` 的所有内容，还包含 3 号主版本的 `core-js` 。\n\n### polyfill\n\n**TIP: This option was removed in v7.**\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqinzhen001%2Fbabel7-demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fqinzhen001%2Fbabel7-demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqinzhen001%2Fbabel7-demo/lists"}