Skip to content

Instantly share code, notes, and snippets.

@CMCDragonkai
Last active January 8, 2024 16:45
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save CMCDragonkai/7fb6b279bb667f3c194994b2f2ccedae to your computer and use it in GitHub Desktop.
Save CMCDragonkai/7fb6b279bb667f3c194994b2f2ccedae to your computer and use it in GitHub Desktop.
Babel-Polyfill vs Babel-Transform-Runtime

https://babeljs.io/docs/usage/polyfill/ vs https://babeljs.io/docs/plugins/transform-runtime

The main difference is that polyfill works for all polyfills but must be installed as a production dependency. And you need to use import 'babel-polyfill'; to make it work. And it will pollute the global scope.

The transform-runtime provides many of the same features, but won't provide special functions like array.includes() or array.values(). So it's safer to use inside a library.

If you're building an app, you can use babel-polyfill. If you're building a library, make sure not to use babel-polyfill, and only the transform-runtime.

You'll need to find alternatives for implementing any of the functions like array.includes or array.values().

@weisiwu
Copy link

weisiwu commented Sep 26, 2018

thanks to your share! it's very useful to me.

@DongShi
Copy link

DongShi commented Oct 23, 2018

Nice and clear! Thanks!

@hadnet
Copy link

hadnet commented Feb 8, 2019

Well explained!

@kilgarenone
Copy link

kilgarenone commented Feb 28, 2019

Say I'm building an app: Besides using the @babel/polyfill, should I also use the transform-runtime to avoid the helper functions duplication, effectively reducing code size?

@jmlavoier
Copy link

Good explanation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment