Best place in a project to host a polyfill file for cross-browser JavaScript support

Satisfying space in a React / Redux application (created with create-react-app) is the best place to place / place any files that will serve as custom polyfiles for browsers that lack support. In particular, I need to be able to use Array.prototype.includesand String.prototype.startsWith, as well as several other methods that are not supported in Internet Explorer or Microsoft Edge. Any suggestions are welcome!

+4
source share
3 answers

After ejectyour React / Redux application (created using create-react-app), you should find the folder polyfills.jsin /config.

You can then add your polyfill codes or use the ones offered by the Mozilla Developer Network:

Array.prototype.includes ()

String.prototype.startsWith ()

Hope the above helps.

+4
source

If you use core-js , it will be installed using npm, and the code will be in the folder node_modules.

You can import it from the application entry point:

require('core-js')
+1
source

index.js , !

import 'core-js/es6/';

import React from 'react';
import ReactDOM from 'react-dom';
import App from './app';

ReactDOM.render(<App />, document.getElementById('root'));
0

Source: https://habr.com/ru/post/1676791/


All Articles