{"id":19501318,"url":"https://github.com/self-denial-cy/babel-exercise","last_synced_at":"2025-06-22T11:36:57.005Z","repository":{"id":144544386,"uuid":"567642235","full_name":"self-denial-cy/babel-exercise","owner":"self-denial-cy","description":"personal babel exercise","archived":false,"fork":false,"pushed_at":"2022-11-24T11:31:51.000Z","size":13,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-25T21:33:25.055Z","etag":null,"topics":["babel","polyfill"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/self-denial-cy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2022-11-18T08:35:17.000Z","updated_at":"2022-12-07T09:56:23.000Z","dependencies_parsed_at":null,"dependency_job_id":"c008459b-e042-491a-ae5a-af4fb4e8b404","html_url":"https://github.com/self-denial-cy/babel-exercise","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/self-denial-cy/babel-exercise","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/self-denial-cy%2Fbabel-exercise","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/self-denial-cy%2Fbabel-exercise/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/self-denial-cy%2Fbabel-exercise/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/self-denial-cy%2Fbabel-exercise/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/self-denial-cy","download_url":"https://codeload.github.com/self-denial-cy/babel-exercise/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/self-denial-cy%2Fbabel-exercise/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261288983,"owners_count":23136044,"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","polyfill"],"created_at":"2024-11-10T22:12:19.534Z","updated_at":"2025-06-22T11:36:51.994Z","avatar_url":"https://github.com/self-denial-cy.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Babel\n\n## Babel 中的 Preset\n\n所谓 Preset 就是一些 Plugin 的集合，可以理解为一系列 Plugin 的整合包\n\n以下是三个最常用的 Preset：\n\n### @babel/preset-env\n\n它是一个智能预设，可以将高版本的 Javascript 根据内置规则转译为低版本的 Javascript\n\n它内部集成了绝大多数的转译 Plugin（State \u003e 3），根据对应的参数进行转译\n\n\u003e 它不会包含任何低于 State3 的 Javascript 语法提案，如果需要兼容低于 State3 的语法则需要额外引入对应的 Plugin 进行转译\n\n\u003e 注意：该预设仅仅针对语法的转译，比如说转译箭头函数、const、let 语法\n\u003e\n\u003e 针对一些 API、新增特性是无法进行转译的，这些需要通过 polyfill 处理\n\n### @babel/preset-react\n\n顾名思义，适用于 React 开发的预设（暂时没深入接触过 React，跳过先）\n\n### @babel/preset-typescript\n\n对于 Typescript，有两种方式将其编译为 Javascript\n\n- 使用 tsc 命令，结合 cli 命令行参数或 tsconfig 配置文件进行编译\n- 使用 babel，通过该预设进行编译\n\n## Babel 中的 Plugin\n\n常见的 Plugin 大多数已经集成在 @babel/preset-env 预设中，当项目中需要支持更新的 Javascript 语法时，可以去 [Babel 官网](https://babeljs.io/docs/en/plugins-list) 找到对应的 Plugin 引入\n\n## Polyfill\n\n首先理清楚三个概念：\n\n- 最新 ES 语法：箭头函数、let、const 等\n- 最新 ES API：Promise 等\n- 最新 ES 实例/静态方法：Array.from、arr.includes 等\n\n@babel/preset-env 仅仅只会转译最新的 ES 语法，并不会转译相应的 API 和实例/静态方法，这时就得引入 polyfill 实现相应的 API 和方法\n\n语法层面的转译 @babel/preset-env 完全可以胜任，但是一些内置方法模块，仅仅通过 @babel/preset-env 的语法转译是无法进行识别转化的，所以就需要一系列类似 【垫片】 的工具进行补充实现这部分内容的低版本代码实现，这就是 polyfill\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fself-denial-cy%2Fbabel-exercise","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fself-denial-cy%2Fbabel-exercise","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fself-denial-cy%2Fbabel-exercise/lists"}