Skip to content

Commit 6d7741e

Browse files
authored
Add Promise and fetch polyfills (#235)
1 parent 3a1ed7a commit 6d7741e

File tree

5 files changed

+18
-2
lines changed

5 files changed

+18
-2
lines changed

config/polyfills.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
if (typeof Promise === 'undefined') {
2+
// Rejection tracking prevents a common issue where React gets into an
3+
// inconsistent state due to an error, but it gets swallowed by a Promise,
4+
// and the user has no idea what causes React's erratic future behavior.
5+
require('promise/lib/rejection-tracking').enable();
6+
window.Promise = require('promise/lib/es6-extensions.js');
7+
}
8+
9+
require('whatwg-fetch');

config/webpack.config.dev.js

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ module.exports = {
1818
entry: [
1919
require.resolve('webpack-dev-server/client') + '?http://localhost:3000',
2020
require.resolve('webpack/hot/dev-server'),
21+
require.resolve('./polyfills'),
2122
path.join(paths.appSrc, 'index')
2223
],
2324
output: {

config/webpack.config.prod.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ if (!publicPath.endsWith('/')) {
2525
module.exports = {
2626
bail: true,
2727
devtool: 'source-map',
28-
entry: path.join(paths.appSrc, 'index'),
28+
entry: [
29+
require.resolve('./polyfills'),
30+
path.join(paths.appSrc, 'index')
31+
],
2932
output: {
3033
path: paths.appBuild,
3134
filename: '[name].[chunkhash:8].js',

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,13 @@
5353
"json-loader": "0.5.4",
5454
"opn": "4.0.2",
5555
"postcss-loader": "0.9.1",
56+
"promise": "7.1.1",
5657
"rimraf": "2.5.3",
5758
"style-loader": "0.13.1",
5859
"url-loader": "0.5.7",
5960
"webpack": "1.13.1",
60-
"webpack-dev-server": "1.14.1"
61+
"webpack-dev-server": "1.14.1",
62+
"whatwg-fetch": "1.0.0"
6163
},
6264
"devDependencies": {
6365
"bundle-deps": "1.0.0",

scripts/eject.js

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ prompt('Are you sure you want to eject? This action is permanent. [y/N]', functi
4747
path.join('config', 'flow', 'file.js.flow'),
4848
path.join('config', 'eslint.js'),
4949
path.join('config', 'paths.js'),
50+
path.join('config', 'polyfills.js'),
5051
path.join('config', 'webpack.config.dev.js'),
5152
path.join('config', 'webpack.config.prod.js'),
5253
path.join('scripts', 'build.js'),

0 commit comments

Comments
 (0)