I\'m trying to configure Babel for Node v6.9.2. I want to use async
/await
constructs.
Because I\'m new to Babel and all Node infrastructur
Use Babel preset for Node 6.x:
To see what ES feature is supported in a given Node version, see:
For async
/await
support in particular, see:
If you use Node v7.x (the current version) then you can use the --harmony
flag and use async
/await
natively without transpilation.
Node v8.x (available as nightly builds) doesn't even need the --harmony
flag for that.
But note that Node doesn't support import
/export
- to know why see:
What preset should I use?
You don't need to use any preset. Presets are just a collection of plugins which makes it easier to use if you want to transpile a set of features (for instance all ES2015 with preset-es2015
). But when you want to transpile only a selection of these features, you only include the corresponding plugins.
What plugins should I include so I can use async/await?
Because Node 6 supports generators, you can use transform-async-to-generator
with the following .babelrc
:
{
"plugins": ["transform-async-to-generator"]
}
And of course you would need to add plugins if you need to transpile more unsupported features.
babel-preset-env
babel-preset-env automatically determines what plugins you need for the specified environment. This will not include any plugins that are not necessary. To specify your current Node version you would use this .babelrc
:
{
"presets": [
["env", {
"targets": {
"node": "current"
}
}]
]
}