ES2015 preset

Only compiles ES2015 to ES5

If you want to stay up to date, use the env preset

This preset includes the following plugins:

Basic Setup (with the CLI)

You can also check out the React Getting Started page

For more info, check out the setup page on the cli and the usage docs.

Install the CLI and this preset

npm install --save-dev babel-cli babel-preset-es2015

Make a .babelrc config file with the preset

echo '{ "presets": ["es2015"] }' > .babelrc

Create a file to run on

echo 'console.log([1, 2, 3].map(n => n + 1))' > index.js

Run it

./node_modules/.bin/babel index.js

安装

npm install --save-dev babel-preset-es2015

使用

通过 .babelrc (推荐)

.babelrc

{
  "presets": ["es2015"]
}

通过 CLI

babel script.js --presets es2015

通过 Node API

require("babel-core").transform("code", {
  presets: ["es2015"]
});

选项

loose

boolean, 默认 false.

为该预设中允许它们的任何插件启用“loose”转换.

modules

"amd" | "umd" | "systemjs" | "commonjs" | false, 默认 "commonjs".

启用将es6模块语法转换为另一个模块类型.

将其设置为false将不会转换任何模块.

spec

boolean, 默认false.

为该预设中允许它们的任何插件启用“spec”转换.