Skip to content

Commit 34f0148

Browse files
committed
feat: Add a polyfill for Promise and fetch
1 parent 2e2ce85 commit 34f0148

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

config/polyfills.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict';
2+
3+
if (typeof Promise === 'undefined') {
4+
// Rejection tracking prevents a common issue where React gets into an
5+
// inconsistent state due to an error, but it gets swallowed by a Promise,
6+
// and the user has no idea what causes React's erratic future behavior.
7+
require('promise/lib/rejection-tracking').enable();
8+
window.Promise = require('promise/lib/es6-extensions.js');
9+
}
10+
11+
// fetch() polyfill for making API calls.
12+
require('whatwg-fetch');
13+
14+
// Object.assign() is commonly used with React.
15+
// It will use the native implementation if it's present and isn't buggy.
16+
Object.assign = require('object-assign');

config/webpack.config.prod.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ module.exports = {
7777
// You can exclude the *.map files from the build during deployment.
7878
devtool: shouldUseSourceMap ? 'source-map' : false,
7979
// In production, we only want to load the polyfills and the app code.
80-
entry: [/*require.resolve('./polyfills'),*/ paths.appIndexJs],
80+
entry: [require.resolve('./polyfills'), paths.appIndexJs],
8181
output: {
8282
// The build folder.
8383
path: paths.appBuild,
@@ -279,10 +279,8 @@ module.exports = {
279279
}
280280
]
281281
},
282-
283282
plugins: [
284-
new webpack.DefinePlugin(env.stringified),
285-
283+
// Generates an `index.html` file with the <script> injected.
286284
new HtmlWebpackPlugin({
287285
inject: true,
288286
template: paths.appHtml,
@@ -314,8 +312,8 @@ module.exports = {
314312
new MiniCssExtractPlugin({
315313
// Options similar to the same options in webpackOptions.output
316314
// both options are optional
317-
filename: 'static/js/[name].[chunkhash:8].css',
318-
chunkFilename: 'static/js/[name].[chunkhash:8].chunk.css'
315+
filename: 'static/css/[name].[contenthash:8].css',
316+
chunkFilename: 'static/css/[name].[contenthash:8].chunk.css',
319317
}),
320318
// Generate a manifest file which contains a mapping of all asset filenames
321319
// to their corresponding output file so that tools can pick it up without
@@ -324,7 +322,6 @@ module.exports = {
324322
fileName: 'asset-manifest.json',
325323
publicPath: publicPath
326324
}),
327-
328325
// Generate a service worker script that will precache, and keep up to date,
329326
// the HTML & assets that are part of the Webpack build.
330327
new SWPrecacheWebpackPlugin({

0 commit comments

Comments
 (0)