Skip to content

Instantly share code, notes, and snippets.

@g3tr1ght
Last active September 21, 2021 17:46
Show Gist options
  • Select an option

  • Save g3tr1ght/94b9f8c12ab8d1088cf7ae237d07c74a to your computer and use it in GitHub Desktop.

Select an option

Save g3tr1ght/94b9f8c12ab8d1088cf7ae237d07c74a to your computer and use it in GitHub Desktop.
Dynamic whole-sale polyfilling example
// polyfills.js
require('whatwg-fetch');
require('intl');
require('url-polyfill');
require('core-js/web/dom-collections');
require('core-js/es6/promise');
require('core-js/es6/map');
require('core-js/es6/string');
require('core-js/es6/array');
require('core-js/es6/object');
// main.js
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App/App';
import './index.css';
const render = () => {
ReactDOM.render(<App />, document.getElementById('root'));
}
if (
'fetch' in window &&
'Intl' in window &&
'URL' in window &&
'Promise' in window &&
'Map' in window &&
'forEach' in NodeList.prototype &&
'startsWith' in String.prototype &&
'endsWith' in String.prototype &&
'includes' in String.prototype &&
'includes' in Array.prototype &&
'assign' in Object &&
'entries' in Object &&
'keys' in Object
) {
render();
} else {
import('./polyfills').then(render);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment