问题
Attempting to use babel-plugin-transform-es2015-spread in my project. Installed the module.
npm install --save-dev babel-plugin-transform-es2015-spread
.babelrc looks like.
{
"presets": [
["env", {
"include": ["babel-plugin-transform-es2015-spread"]
}]
]
}
Registering babel in my main.js
// babel
require('babel-core/register')
require('babel-polyfill')
But the below code snippet still throws (Unexpected token) error
return {
...state,
hoverTrend: action.trend,
}
回答1:
The plugin babel-plugin-transform-object-rest-spread seemed to work fine for me. So basically first install it,
npm install --save-dev babel-plugin-transform-object-rest-spread
And then add to .babelrc
{
"plugins": ["transform-object-rest-spread"],
"presets": [
"env"
]
}
来源:https://stackoverflow.com/questions/51229628/setting-up-the-babel-plugin-for-spread-operator-correctly