How to confirm if ES6 is being used (ReactJS + Redux)

时间:2016-07-11 20:47:39

标签: javascript reactjs ecmascript-6 redux

I have the following set up:

enter image description here

And I am trying to do the following:

case 'UPDATE_PASSWORD':
  return {
    ...state, //preserve current state, apply changes to it below
    password: action.password,
  }; 

but I am getting:

Unexpected token (5:8) at where '...' starts

What may be the issue? How do I check if I am using ES6?

1 个答案:

答案 0 :(得分:6)

This is a proposed ECMAScript feature (object spread) and can be enabled by adding stage-0 to your babel presets:

npm install --save-dev babel-preset-stage-0

Then, in your .babelrc or within your webpack.config.js query add the preset to your babel settings. Example .babelrc:

{
    "presets": [
        "es2015",
        "react",
        "stage-0"
    ]
}

Or, if you make use of the webpack babel-loader query string:

{
    test: /\.jsx?$/,
    loader: 'babel-loader',
    exclude: /node_modules/,
    query: {
        presets: ['es2015', 'react', 'stage-0']
    }
}

EDIT

Babel presets are an assortment of many transformations. As per zerkms' suggestion, you could use stage-2, which does not include/transpile many other features you may not be using at this time. If you really just want the object spread to work, you can also just install transform object rest spread.

相关问题