Skip to content

Commit 07c5ceb

Browse files
committed
feat: Add a polyfill for Promise and fetch
1 parent 707e2ac commit 07c5ceb

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,
@@ -256,10 +256,8 @@ module.exports = {
256256
}
257257
]
258258
},
259-
260259
plugins: [
261-
new webpack.DefinePlugin(env.stringified),
262-
260+
// Generates an `index.html` file with the <script> injected.
263261
new HtmlWebpackPlugin({
264262
inject: true,
265263
template: paths.appHtml,
@@ -291,8 +289,8 @@ module.exports = {
291289
new MiniCssExtractPlugin({
292290
// Options similar to the same options in webpackOptions.output
293291
// both options are optional
294-
filename: 'static/js/[name].[chunkhash:8].css',
295-
chunkFilename: 'static/js/[name].[chunkhash:8].chunk.css'
292+
filename: 'static/css/[name].[contenthash:8].css',
293+
chunkFilename: 'static/css/[name].[contenthash:8].chunk.css',
296294
}),
297295
// Generate a manifest file which contains a mapping of all asset filenames
298296
// to their corresponding output file so that tools can pick it up without
@@ -301,7 +299,6 @@ module.exports = {
301299
fileName: 'asset-manifest.json',
302300
publicPath: publicPath
303301
}),
304-
305302
// Generate a service worker script that will precache, and keep up to date,
306303
// the HTML & assets that are part of the Webpack build.
307304
new SWPrecacheWebpackPlugin({

0 commit comments

Comments
 (0)