question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is babel-polyfill more than just a polyfill?

See original GitHub issue

The 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:closed
  • Created 8 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

7reactions
mikemaccanacommented, Nov 25, 2015

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.

2reactions
mikemaccanacommented, Nov 24, 2015

@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)

require("core-js"); 

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:

require("babel-polyfill"); 
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found