Skip to content

Commit

Permalink
Update usage.md to include usage of core-js polyfill
Browse files Browse the repository at this point in the history
Update the documentation to state first how to poliyfill with core-js. Solves babel#2240, babel#2163, babel#2332 and babel#2006
  • Loading branch information
danBamikiya authored Apr 11, 2021
1 parent ab54c54 commit 629270a
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ Now the `env` preset will only load transformation plugins for features that are
## Polyfill
> 🚨 As of Babel 7.4.0, this package has been deprecated in favor of directly including `core-js/stable` (to polyfill ECMAScript features) and `regenerator-runtime/runtime` (needed to use transpiled generator functions):
> 🚨 <span id="polyfill-deprecated">As</span> of Babel 7.4.0, this package has been deprecated in favor of directly including `core-js/stable` (to polyfill ECMAScript features) and `regenerator-runtime/runtime` (needed to use transpiled generator functions):
>
> ```js
> import "core-js/stable";
Expand Down Expand Up @@ -231,7 +231,34 @@ require("core-js/modules/es.promise.finally");
Promise.resolve().finally();
```
If we weren't using the `env` preset with the `"useBuiltIns"` option set to `"usage"` we would've had to require the full polyfill _only once_ in our entry point before any other code.
If we weren't using the `env` preset with the `"useBuiltIns"` option set to `"usage"` (defaults to "false") we would've had to require the full polyfill _only once_ in our entry point before any other code.
For example:
```json
{
"presets": [
[
"@babel/env",
{
"targets": {
"edge": "17",
"firefox": "60",
"chrome": "67",
"safari": "11.1"
},
"useBuiltIns": "entry"
}
]
]
}
```
Then import [core-js](https://github.com/zloirock/core-js) and [regenerator runtime](https://github.com/facebook/regenerator/blob/master/packages/regenerator-runtime/runtime.js) first, in our entry file to emulate a full ES2015+ environment since [@babel/polyfill](polyfill.md) has been <a href="#response-schema">deprecated</a>:
```js
import "core-js/stable";
import "regenerator-runtime/runtime";
```
## Summary
Expand Down

0 comments on commit 629270a

Please sign in to comment.