Skip to content

Commit a10b372

Browse files
committed
Move polyfill control to user land
1 parent 9690bc8 commit a10b372

File tree

6 files changed

+39
-35
lines changed

6 files changed

+39
-35
lines changed

packages/react-scripts/config/polyfills.js

-30
This file was deleted.

packages/react-scripts/config/webpack.config.dev.js

-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ module.exports = {
5656
// This means they will be the "root" imports that are included in JS bundle.
5757
// The first two entry points enable "hot" CSS and auto-refreshes for JS.
5858
entry: [
59-
// We ship a few polyfills by default:
60-
require.resolve('./polyfills'),
6159
// Include an alternative client for WebpackDevServer. A client's job is to
6260
// connect to WebpackDevServer by a socket and get notified about changes.
6361
// When you save a file, the client will either apply hot updates (in case

packages/react-scripts/config/webpack.config.prod.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ module.exports = {
7979
// We generate sourcemaps in production. This is slow but gives good results.
8080
// You can exclude the *.map files from the build during deployment.
8181
devtool: shouldUseSourceMap ? 'source-map' : false,
82-
// In production, we only want to load the polyfills and the app code.
83-
entry: [require.resolve('./polyfills'), paths.appIndexJs],
82+
// In production, we only want to load the app code.
83+
entry: paths.appIndexJs,
8484
output: {
8585
// The build folder.
8686
path: paths.appBuild,

packages/react-scripts/scripts/utils/createJestConfig.js

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ module.exports = (resolve, rootDir, srcRoots) => {
2525
// in Jest configs. We need help from somebody with Windows to determine this.
2626
const config = {
2727
collectCoverageFrom: ['src/**/*.{js,jsx,mjs}'],
28-
setupFiles: [resolve('config/polyfills.js')],
2928
setupTestFrameworkScriptFile: setupTestsFile,
3029
testMatch: [
3130
'**/__tests__/**/*.{js,jsx,mjs}',

packages/react-scripts/template/src/index.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import React from 'react';
22
import ReactDOM from 'react-dom';
3+
// Include the default polyfills to enable modern javascript features
4+
// in legacy browsers. Learn more: http://bit.ly/2Bt1Yjk
5+
import './polyfills';
36
import './index.css';
47
import App from './App';
58
import * as serviceWorker from './serviceWorker';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* Polyfills enable javascript features in web browsers that do not support
3+
* the feature. Learn more: https://en.wikipedia.org/wiki/Polyfill_(programming)
4+
*
5+
* Depending on which browsers you are targeting with your app you may want
6+
* to adjust which polyfills you are using.
7+
*
8+
* If you need other polyfills such as babel-polyfill or babel-runtime
9+
* you can add it to this file.
10+
*
11+
*/
12+
13+
// Enables Promise, support in legacy browsers such as IE11 and below
14+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
15+
if (typeof Promise === 'undefined') {
16+
// Rejection tracking prevents a common issue where React gets into an
17+
// inconsistent state due to an error, but it gets swallowed by a Promise,
18+
// and the user has no idea what causes React's erratic future behavior.
19+
require('promise/lib/rejection-tracking').enable();
20+
window.Promise = require('promise/lib/es6-extensions.js');
21+
}
22+
23+
// Enables fetch() polyfill for making API calls support in
24+
// legacy browsers such as IE11 and below
25+
// https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API
26+
require('whatwg-fetch');
27+
28+
// Object.assign() is commonly used with React.
29+
// It will use the native implementation if it's present and isn't buggy.
30+
// It's not supported in legacy browsers such as IE11 and below.
31+
// In some cases you can remove it even if you are targeting IE by using
32+
// Spread opertor syntax instead.
33+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_operator
34+
Object.assign = require('object-assign');

0 commit comments

Comments
 (0)