{"id":16293661,"url":"https://github.com/badsyntax/babel-builtin-polyfills","last_synced_at":"2025-07-11T09:40:19.824Z","repository":{"id":136892915,"uuid":"109481456","full_name":"badsyntax/babel-builtin-polyfills","owner":"badsyntax","description":"A project showing the \"usage\" feature of babel/env","archived":false,"fork":false,"pushed_at":"2017-11-04T09:24:37.000Z","size":19,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-15T05:15:11.676Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/badsyntax.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}},"created_at":"2017-11-04T09:11:25.000Z","updated_at":"2017-11-04T09:12:35.000Z","dependencies_parsed_at":"2023-04-14T01:31:08.749Z","dependency_job_id":null,"html_url":"https://github.com/badsyntax/babel-builtin-polyfills","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/badsyntax%2Fbabel-builtin-polyfills","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/badsyntax%2Fbabel-builtin-polyfills/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/badsyntax%2Fbabel-builtin-polyfills/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/badsyntax%2Fbabel-builtin-polyfills/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/badsyntax","download_url":"https://codeload.github.com/badsyntax/babel-builtin-polyfills/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248027412,"owners_count":21035594,"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":[],"created_at":"2024-10-10T20:11:59.574Z","updated_at":"2025-04-09T11:13:48.352Z","avatar_url":"https://github.com/badsyntax.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Babel 7 Builtin polyfills\n\nBabel can provide polyfills for your env but also only provide polyfills that are _actually used_. This is pretty awesome as it can \nreduce your bundle file size.\n\nThis can be achieved with the options [`\"useBuiltIns\": \"usage\"`](https://github.com/babel/babel/tree/master/experimental/babel-preset-env#usebuiltins-usage) for the `@babel/env` preset. \n\nAdditionally, we can use the `transform-runtime` plugin to transform polyfills to the local module scope, to avoid potential \nglobal conflicts. This will not work for instance methods though, eg `String.prototype.includes`, and so Babel will provide \nglobal polyfills for those.\n\nAdditionally, now that Babel can provide polyfills based on usage, we want to avoid using Babel helpers. For example, we can \nconfigure the `transform-object-rest-spread` plugin to use builtIns: `\"useBuiltIns\": true`. The results in the plugin using \n`Object.assign` instead of `_extends` (and then `Object.assign` might be pollyfilled based on your env).\n\nI haven't found a nice automatic solution for polyfilling browser/DOM specific features like `fetch`.\n\nInput:\n\n```\nclass Foo {}\nconst bar = () =\u003e {};\nconst a = [...['a', 'b', 'c'], 'foo'];\nconst b = { a: 'b', ...{ a: 'c' } };\nfetch();\nnew Promise();\nnew Set();\nnew Map();\n''.includes('');\n[].includes('');\n```\n\n\nOutput:\n\n```\n$ ./node_modules/.bin/babel index.js\n@babel/preset-env: `DEBUG` option\n\nUsing targets:\n{\n  \"ie\": \"8\"\n}\n\nUsing modules transform: false\n\nUsing plugins:\n  check-constants { \"ie\":\"8\" }\n  transform-arrow-functions { \"ie\":\"8\" }\n  transform-block-scoped-functions { \"ie\":\"8\" }\n  transform-block-scoping { \"ie\":\"8\" }\n  transform-classes { \"ie\":\"8\" }\n  transform-computed-properties { \"ie\":\"8\" }\n  transform-destructuring { \"ie\":\"8\" }\n  transform-duplicate-keys { \"ie\":\"8\" }\n  transform-for-of { \"ie\":\"8\" }\n  transform-function-name { \"ie\":\"8\" }\n  transform-literals { \"ie\":\"8\" }\n  transform-object-super { \"ie\":\"8\" }\n  transform-parameters { \"ie\":\"8\" }\n  transform-shorthand-properties { \"ie\":\"8\" }\n  transform-spread { \"ie\":\"8\" }\n  transform-sticky-regex { \"ie\":\"8\" }\n  transform-template-literals { \"ie\":\"8\" }\n  transform-typeof-symbol { \"ie\":\"8\" }\n  transform-unicode-regex { \"ie\":\"8\" }\n  transform-new-target { \"ie\":\"8\" }\n  transform-regenerator { \"ie\":\"8\" }\n  transform-exponentiation-operator { \"ie\":\"8\" }\n  transform-async-to-generator { \"ie\":\"8\" }\n\nUsing polyfills with `usage` option:\n\n[index.js] Added following polyfills:\n  es6.string.includes { \"ie\":\"8\" }\n  es7.array.includes { \"ie\":\"8\" }\nimport \"@babel/polyfill/lib/core-js/modules/es7.array.includes\";\nimport \"@babel/polyfill/lib/core-js/modules/es6.string.includes\";\n\nvar _Map = require(\"babel-runtime/core-js/map\");\n\nvar _Set = require(\"babel-runtime/core-js/set\");\n\nvar _Promise = require(\"babel-runtime/core-js/promise\");\n\nvar _Object$assign = require(\"babel-runtime/core-js/object/assign\");\n\nvar _classCallCheck = require(\"babel-runtime/helpers/classCallCheck\");\n\nvar Foo = function Foo() {\n  _classCallCheck(this, Foo);\n};\n\nvar bar = function bar() {};\n\nvar a = ['a', 'b', 'c'].concat(['foo']);\n\nvar b = _Object$assign({\n  a: 'b'\n}, {\n  a: 'c'\n});\n\nfetch();\nnew _Promise();\nnew _Set();\nnew _Map();\n''.includes('');\n[].includes('');\n```\n\n## create-react-app\n\nAt the moment `create-react-app` uses the [babel-preset-react-app](https://github.com/facebookincubator/create-react-app/tree/master/packages/babel-preset-react-app) preset which uses `babel-preset-env@1.6.1` which does not support this `usage` feature, \nwhich was added with [2.0](https://github.com/babel/babel-preset-env/pull/241).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbadsyntax%2Fbabel-builtin-polyfills","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbadsyntax%2Fbabel-builtin-polyfills","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbadsyntax%2Fbabel-builtin-polyfills/lists"}