Is babel-polyfill more than just a polyfill?
See original GitHub issueThe docs for https://babeljs.io/docs/usage/polyfill/ are confusing:
Babel includes a polyfill that includes a custom regenerator runtime and core.js.
Since core.js is a polyfill for the missing methods (String.prototype.includes() etc), what does the ‘custom regenerator’ add?
If the ‘custom regenerator’ does code transformation like babel, wouldn’t everybody already be shipping ES5 code that’s been transformed by babel?
In short: if I just need a polyfill, and nothing else (since I’m already using babel during my build process), should I be using babel-polyfill
or core.js
? The current docs do nit make it clear.
Issue Analytics
- State:
- Created 8 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
babel/polyfill
Babel includes a polyfill that includes a custom regenerator runtime and core-js. This will emulate a full ES2015+ environment (no < Stage 4...
Read more >The end of @babel/polyfill: The more efficient alternative?
The @babel/polyfill package allows you to emulate an ES6+ environment. Effectively, it ensures your ES6+ code is backwards compatible with ...
Read more >Why do I need @babel/polyfill at all, using Babel?
Now another important distinction is that a polyfill will use the native feature if it exists, however transpilation will not.
Read more >Why you should add babel polyfill for every React application
So long story short, just using babel is not enough for your application to work because all the latest Javascript features are not...
Read more >BabelJS - Babel Polyfill - Tutorialspoint
Babel Polyfill adds support to the web browsers for features, which are not available. Babel compiles the code from recent ecma version to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks @thejameskyle . My previous impression was that the ES5 code was more plain, I now get what the babel runtime does.
Since most people who use Babel haven’t written a compiler before (and since ‘runtime’ is sometimes used as a synonym for VM) it could also be worth making ‘babel runtime’ a link explaining the same thing your comment does.
@thejameskyle assuming what @zloirock said is correct (and my own understanding is correct):
Polyfills
If you’re already transforming to ES6 during your build process
If you’re already using babel to transform your code during your build process, you can load the
core-js
polyfill to add the additional methods provided by ES6 and ES7. (Add details here)If you wish to transform ES5 to ES6 in the browser
If you are not using babel to transform your code as part of your build steps, and want to ship ES^ to the browser, you can use get both the systax transformations and the additional methods with: