Learning Redux
上QQ阅读APP看书,第一时间看更新

Setting up Babel

Now webpack knows that it should compile JavaScript files with Babel, but we haven't even set up Babel yet! To do so perform the following steps:

First, let's install the Babel-related libraries:

npm install --save-dev babel-core babel-loader babel-preset-es2015
npm install --save-dev babel-plugin-transform-object-rest-spread

The preceding command includes babel-corebabel-loader for webpack, and the babel-preset for ES2015. We also installed the object rest/spread plugin, as it allows us to use rest/spread syntax with objects in addition to arrays. We will learn more about the rest/spread syntax later.

We still need to tell Babel which presets and plugins it should load. So, we will create a .babelrc file with the following content:

{
"presets":[ "es2015" ],
"plugins": [ "transform-object-rest-spread" ]
}

You can find more information about the Babel configuration on their API documentation page, at https://babeljs.io/docs/usage/api/#options.