Answer from this article:
The distinction between a babel transform plugin
versus
babel-polyfill / babel-runtime
is whether or not you can
reimplement the feature today, in ES5. For example, Array.from
can
be rewritten in ES5 but there is nothing I can write in ES5 to add
arrow function syntax to JavaScript. Therefore, there is a transform
for arrow functions but none for Array.from
. It will have to be
provided by a separate polyfill like babel-polyfill
, or
babel-runtime
.
As a side note, here is my current understanding of the babel eco-system.
Babel
is a javascript compiler: it parses, transforms and outputs transformed code.
babel-core
- This is the parse and output parts.
- It does not do any transformation.
- It can be used from the command line or from a bundler (webpack, rollup and co.)
babel-polyfill / babel-runtime
- Acts on the transform part by prepending es5 javascript to your code to emulate es2015+ functions (like Object.assign).
- Relies on Regenerator (to polyfill generators) and core-js (to polyfill all the rest).
- Difference between
babel-polyfill
and babel-runtime
: the former defines global methods (and pollutes the global scope) whereas the latter transforms your code to make the same functionnality available as explained in this answer.
babel plugins
- Transform the code you wrote.
babel syntax / transform plugins
: parse and transform es2015+ syntax (like arrow functions) to convert it to es5.
babel-plugins-stage-x
(from stage-0 to stage-4): transform future javascript syntax which is not in the JS specs yet, starting at stage-0 (just an idea) down to stage-4 (will land in the babel-plugins
soon).
babel-preset-env
babel-preset-env
determines the Babel plugins and polyfills needed for a specific environment.
- With no configuration, it will load all the plugins (including es2015, es2016 and es2017) required to transpile es2015+ to es5.
- With a
target
option, it loads only the plugins required to run on a specific target.
- With the
builtIn
option, it uses only the babel-polyfill
which are not built-in the target.
- Does not work with
babel-transform-runtime
yet (as of nov. 2017). (see this issue)