Babel has a polyfill library based on core js which has polyfills for a lot of such ES6/ES2015 features.
But you don't want to include the entire polyfill library in your application if you are only using a couple of polyfills.
Here is a handy way to include just the polyfills you need using webpack:
1) Add babel-polyfill to your dev dependencies:
This file contains 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
npm install babel-polyfill -D |
2) And then include the required polyfills in your webpack config:
This file contains 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
module.exports = { | |
entry: ["core-js/fn/object/assign", | |
"core-js/fn/promise", | |
"./Scripts/src/app.tsx"] | |
//other webpack stuff | |
} |
This will make sure that only the polyfills you need are included in your webpack bundle.
More info here:
https://github.com/zloirock/core-js#commonjs
https://babeljs.io/docs/usage/polyfill/
Hope you find this useful!
No comments:
Post a Comment