Friday, 23 September, 2016 UTC


Summary

As of version 6, Babel supports presets, sets of features that can be enabled together. This blog post looks at three new useful Babel presets.

Complementing babel-preset-es2015

These two presets are useful complements to babel-preset-es2015 (for ES6):
  • babel-preset-es2016 gives you the two features of ECMAScript 2016: the exponentiation operator and Array.prototype.includes().
  • babel-preset-es2017 gives you:
    • babel-plugin-syntax-trailing-function-commas: optional trailing commas in parameter lists and function/method calls.
    • babel-plugin-transform-async-to-generator: async functions. This is the one feature after ES6 that I’m most looking forward to.
Note that if you want all of ES2017 (that Babel currently supports) then you need three presets: es2015, es2016, es2017.

ES2015 on Node.js

The following preset is a replacement for babel-preset-es2015 on Node.js:
  • babel-preset-es2015-node only adds those ES6 plugins and transforms whose functionality is missing from Node.js (very few in the latest versions).

More information

  • Configuring Babel: “Setting up ES6”
  • Tracking ES2017: “Feature watch: ECMAScript 2017” (accepted and upcoming features)
  • ES2016 and ES2017: “Exploring ES2016 and ES2017”
  • ECMAScript features supported by Node.js: node.green