Require hook

To include it you will need to require it at the top of the entry point to your application.

require("babel-register");

If you are using ES6’s import syntax in your application’s entry point, you should instead import at the top of the entry point to ensure it is loaded first:

import"babel-register";

All subsequent files required by node with the extensions .es6, .es, .jsx and .js will be transformed by Babel. The polyfill specified in polyfill is also automatically required.

Not suitable for libraries

The require hook automatically hooks itself into all node requires. This will pollute the global scope and introduce conflicts. Because of this it's not suitable for libraries, if however you're writing an application then it's completely fine to use.

Sails

AVA

AVA ships with ES2015 support built-in using Babel 6 under the hood, so you can write test using ES2015 syntax right away.

The AVA default Babel configuration includes the "es2015" and "stage-2" presets, but you can customize any Babel option for transpiling test files with the "babel" option in AVA’s package.json configuration.

For example:

{"ava":{"babel":{"presets":["es2015","react"]}}}

Or you can simply "inherit" the Babel configuration from .babelrc or Babel’s package.json configuration, making test files use the same configuration as your source files:

{"ava":{"babel":"inherit"}}

Note that AVA always adds a few custom Babel plugins when transpiling your plugins see notes.

Arguments caveat

Calling nodemon with babel-node may lead to arguments getting parsed incorrectly if you forget to use a double dash. Using npm-scripts helpers prevent this. If you chose to skip using npm-scripts, it can be expressed as:

C# / .NET

varbabel=ReactEnvironment.Current.Babel;// Transpiles a file
// You can instead use `TransformFileWithSourceMap` if you want a source map too.
varresult=babel.TransformFile("foo.js");// Transpiles a piece of code
varresult=babel.Transform("class Foo { }");

Node Inspector

4 Create .babelrc configuration file

Great! You've configured Babel but you haven't made it actually do anything. Create a .babelrc config in your project root and enable some plugins.

To start, you can use the env preset, which enables transforms for ES2015+

npm install babel-preset-env --save-dev

In order to enable the preset you have to define it in your .babelrc file, like this:

{"presets":["env"]}

Note: Running a Babel 6.x project using npm 2.x can cause performance problems because of the way npm 2.x installs dependencies. This problem can be eliminated by either switching to npm 3.x or running npm 2.x with the dedupe flag. To check what version of npm you have run