简体   繁体   English

在React App中设置Babel生成的EcmaScript版本

[英]Set version of EcmaScript generated by Babel, in react app

I'm using the latest ES8 features in my react code, for example, async and await. 我在我的React代码中使用了最新的ES8功能,例如async和await。 Because of misconfiguration problem in my webpack config, I cannot use source maps, and this slows down debugging. 由于我的webpack配置中的配置错误,我无法使用源映射,这会减慢调试速度。

A quick solution could be to locally compile source code into ES7 or ES8, and test in the latest Chrome. 一种快速的解决方案是将源代码本地编译为ES7或ES8,并在最新的Chrome中进行测试。 How can I set this in .babelrc ? 如何在.babelrc设置呢? Here's my current .babelrc: 这是我当前的.babelrc:

{
  "presets": [
     "react-app"
  ] 
}

Answered here , 在这里回答

{
  "presets": [
    "react",
    ["env", {
      "targets": {
        "chrome": 67
      }
    }]
  ]
}

As of Jul 2018, the above setting would not support spread operator in objects . 从2018年7月开始,以上设置将不支持object中的传播算子 To enable it, 要启用它,

npm install --save-dev babel-plugin-transform-object-rest-spread

Use the following configuration in .babelrc : .babelrc使用以下配置:

{
  "presets": [
    "react",
    ["env", {
      "targets": {
        "chrome": 67
      }
    }]
  ],
  "plugins": ["transform-object-rest-spread"]
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM