Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does babel need es6-shim?

I mentioned on Twitter that I was moving from es6-shim to babel. Someone else mentioned:

the shims are still needed even with babel. they fix broken builtins, ones babel's output uses.

So:

  1. Does babel need es6-shim or similar?

  2. If it does, why doesn't babel require these things as a dependency?

Answers with references preferred over 'yes / no' with no supporting arguments!

like image 478
mikemaccana Avatar asked Oct 12 '15 11:10

mikemaccana


People also ask

Do I need babel polyfill?

So long story short, just using babel is not enough for your application to work because all the latest Javascript features are not supported in all browsers. So to fix this problem, we need to use a polyfill.

Does babel automatically polyfill?

Babel includes a polyfill that includes a custom regenerator runtime and core-js. This will emulate a full ES2015+ environment (no < Stage 4 proposals) and is intended to be used in an application rather than a library/tool. (this polyfill is automatically loaded when using babel-node ).

Why is babel polyfill?

Babel Polyfill adds support to the web browsers for features, which are not available. Babel compiles the code from recent ecma version to the one, which we want. It changes the syntax as per the preset, but cannot do anything for the objects or methods used.

Is babel a bundler?

Babel is a transpiler. It can translate all kinds of high version ECMAScript ( not only ECMAScript, but it's easy to understand) into ES5, which is more widely supported by browsers (especially older versions).


1 Answers

Babel, at its core, does a single thing: convert syntax from one form to another.

Some of Babel's syntax transformations introduce dependencies on ES6 library functionality. It doesn't concern itself with how that functionality got there because:

  • The system might already provide it
  • The user might only want to load specific pieces of a library
  • There are many polyfills and the user might have a specific one it wants to use.

It is the developers job to ensure that the transpiled code is running in an environment where all the functions it needs actually exist.

  • Babel should work fine with es6-shim if you'd like to keep using it.
  • Babel also exposes babel/polyfill as a dead simple way to load a polyfill, which loads core-js, another polyfill like es6-shim. Just:

    require('babel/polyfill');

like image 105
loganfsmyth Avatar answered Nov 05 '22 18:11

loganfsmyth