From 629270a5556f8b9dab29106e957ef39193e2555f Mon Sep 17 00:00:00 2001 From: Dan Bamikiya Date: Sun, 11 Apr 2021 22:57:15 +0100 Subject: [PATCH] Update usage.md to include usage of core-js polyfill Update the documentation to state first how to poliyfill with core-js. Solves #2240, #2163, #2332 and #2006 --- docs/usage.md | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/docs/usage.md b/docs/usage.md index c4a835bf20..0be652283c 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -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): +> 🚨 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): > > ```js > import "core-js/stable"; @@ -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 deprecated: + +```js + import "core-js/stable"; + import "regenerator-runtime/runtime"; + ``` ## Summary