setting up the babel plugin for spread operator correctly

天大地大妈咪最大 提交于 2020-01-16 18:55:53

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!