Revert "Update to core-js@3"

This reverts commit 71149650ec.
This commit is contained in:
Ian Schmitz
2019-04-06 16:32:19 -07:00
parent 71149650ec
commit 278c62cf03
6 changed files with 43 additions and 69 deletions

View File

@@ -83,7 +83,7 @@ module.exports = function(api, opts, env) {
useBuiltIns: 'entry',
// Set the corejs version we are using to avoid warnings in console
// This will need to change once we upgrade to corejs@3
corejs: 3,
corejs: 2,
// Do not transform modules to CJS
modules: false,
// Exclude transforms that make all code slower

View File

@@ -3,6 +3,18 @@
This package includes polyfills for various browsers.
It includes minimum requirements and commonly used language features used by [Create React App](https://github.com/facebook/create-react-app) projects.
### Features
Each polyfill ensures the following language features are present:
1. `Promise` (for `async` / `await` support)
1. `window.fetch` (a Promise-based way to make web requests in the browser)
1. `Object.assign` (a helper required for Object Spread, i.e. `{ ...a, ...b }`)
1. `Symbol` (a built-in object used by `for...of` syntax and friends)
1. `Array.from` (a built-in static method used by array spread, i.e. `[...arr]`)
_If you need more features, you must include them manually._
### Usage
First, install the package using Yarn or npm:
@@ -17,19 +29,7 @@ or
yarn add react-app-polyfill
```
## Supporting Internet Explorer
You can import the entry point for the minimal version you intend to support to ensure that the minimum langauge features are present that are required to use Create React App. For example, if you import the IE9 entry point, this will include IE10 and IE11 support.
These modules ensures the following language features are present:
1. `Promise` (for `async` / `await` support)
1. `window.fetch` (a Promise-based way to make web requests in the browser)
1. `Object.assign` (a helper required for Object Spread, i.e. `{ ...a, ...b }`)
1. `Symbol` (a built-in object used by `for...of` syntax and friends)
1. `Array.from` (a built-in static method used by array spread, i.e. `[...arr]`)
_If you need more features, see the [Polyfilling other language features](#polyfilling-other-language-features) section below._
Now, you can import the entry point for the minimal version you intend to support. For example, if you import the IE9 entry point, this will include IE10 and IE11 support.
#### Internet Explorer 9
@@ -48,36 +48,3 @@ import 'react-app-polyfill/ie11';
// ...
```
## Polyfilling other language features
You can also polyfill stable language features not available in your target browsers. If you're using this in Create React App, it will automatically use the `browserslist` you've defined to only include polyfills needed by your target browsers when importing the `stable` polyfill. **Make sure to follow the Internet Explorer steps above if you need to support Internet Explorer in your application**.
```js
// This must be the first line in src/index.js
import 'react-app-polyfill/stable';
// ...
```
If you are supporting Internet Explorer 9/11 you should include both the `ie9`/`ie11` and `stable` modules:
For IE9:
```js
// These must be the first lines in src/index.js
import 'react-app-polyfill/ie9';
import 'react-app-polyfill/stable';
// ...
```
For IE11:
```js
// These must be the first lines in src/index.js
import 'react-app-polyfill/ie11';
import 'react-app-polyfill/stable';
// ...
```

View File

@@ -26,6 +26,6 @@ if (typeof window !== 'undefined') {
Object.assign = require('object-assign');
// Support for...of (a commonly used syntax feature that requires Symbols)
require('core-js/features/symbol');
require('core-js/es6/symbol');
// Support iterable spread (...Set, ...Map)
require('core-js/features/array/from');
require('core-js/fn/array/from');

View File

@@ -6,9 +6,31 @@
*/
'use strict';
require('./ie11');
if (typeof Promise === 'undefined') {
// Rejection tracking prevents a common issue where React gets into an
// inconsistent state due to an error, but it gets swallowed by a Promise,
// and the user has no idea what causes React's erratic future behavior.
require('promise/lib/rejection-tracking').enable();
window.Promise = require('promise/lib/es6-extensions.js');
}
// Make sure we're in a Browser-like environment before importing polyfills
// This prevents `fetch()` from being imported in a Node test environment
if (typeof window !== 'undefined') {
// fetch() polyfill for making API calls.
require('whatwg-fetch');
}
// Object.assign() is commonly used with React.
// It will use the native implementation if it's present and isn't buggy.
Object.assign = require('object-assign');
// Support for...of (a commonly used syntax feature that requires Symbols)
require('core-js/es6/symbol');
// Support iterable spread (...Set, ...Map)
require('core-js/fn/array/from');
// React 16+ relies on Map, Set, and requestAnimationFrame
require('core-js/features/map');
require('core-js/features/set');
require('core-js/es6/map');
require('core-js/es6/set');
require('raf').polyfill(window);

View File

@@ -13,15 +13,13 @@
"files": [
"ie9.js",
"ie11.js",
"jsdom.js",
"stable.js"
"jsdom.js"
],
"dependencies": {
"core-js": "3.0.1",
"core-js": "2.6.5",
"object-assign": "4.1.1",
"promise": "8.0.2",
"raf": "3.4.1",
"regenerator-runtime": "0.13.2",
"whatwg-fetch": "3.0.0"
}
}

View File

@@ -1,13 +0,0 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';
// Polyfill stable language features.
// It's recommended to use @babel/preset-env and browserslist
// to only include the polyfills necessary for the target browsers.
require('core-js/stable');
require('regenerator-runtime/runtime');