Skip to content

Instantly share code, notes, and snippets.

@davidgilbertson
Last active June 21, 2019 23:17
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save davidgilbertson/441e371720dee61df9751734bcb5dbe4 to your computer and use it in GitHub Desktop.
Save davidgilbertson/441e371720dee61df9751734bcb5dbe4 to your computer and use it in GitHub Desktop.
import loadPolyfills from './loadPolyfills';
import mountApp from './mountApp'; // the entry point for the rest of my app
loadPolyfills().then(mountApp);
import 'core-js/es6/promise';
export default function loadPolyfills() {
const fillFetch = () => new Promise((resolve) => {
if ('fetch' in window) return resolve();
require.ensure([], () => {
require('whatwg-fetch');
resolve();
}, 'fetch');
});
const fillIntl = () => new Promise((resolve) => {
if ('Intl' in window) return resolve();
require.ensure([], () => {
require('intl');
require('intl/locale-data/jsonp/en.js');
resolve();
}, 'Intl');
});
const fillCoreJs = () => new Promise((resolve) => {
if (
'startsWith' in String.prototype &&
'endsWith' in String.prototype &&
'includes' in Array.prototype &&
'assign' in Object &&
'keys' in Object
) return resolve();
require.ensure([], () => {
require('core-js');
resolve();
}, 'core-js');
});
return Promise.all([
fillFetch(),
fillIntl(),
fillCoreJs()
]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment