Building Enterprise JavaScript Applications
上QQ阅读APP看书,第一时间看更新

Babel is a transpiler...and more!

Babel can transpile ES6/7/8/9 and ESNext syntax into syntax that works in the targeted environment. For example, let's say we have a module that uses arrow functions:

double = a => a * 2

If we want this to be available on the browser, Babel can transpile it to ES5:

double = function double(a) {
return a * 2;
};

However, if we are running Node v8.11.4, which natively supports arrow functions, it will leave the function unmodified.

Apart from supporting new ECMAScript versions, it also supports commonly used syntax such as JSX (used by React) and Flow static type annotations.