Last active
September 21, 2021 17:46
-
-
Save g3tr1ght/94b9f8c12ab8d1088cf7ae237d07c74a to your computer and use it in GitHub Desktop.
Dynamic whole-sale polyfilling example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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