为传播操作员正确设置babel插件 [英] setting up the babel plugin for spread operator correctly

查看:140
本文介绍了为传播操作员正确设置babel插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试在我的项目中使用babel-plugin-transform-es2015-spread.安装模块.

Attempting to use babel-plugin-transform-es2015-spread in my project. Installed the module.

npm install --save-dev babel-plugin-transform-es2015-spread

.babelrc看起来像.

.babelrc looks like.

{
    "presets": [
      ["env", {
        "include": ["babel-plugin-transform-es2015-spread"]
      }]
    ]
  }

在main.js中注册babel

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,
  }

推荐答案

插件 babel-plugin-transform-object-rest-spread 似乎对我来说很好.所以基本上首先安装它,

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

然后添加到.babelrc

And then add to .babelrc

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

这篇关于为传播操作员正确设置babel插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆