Do I really need Babel or other transpilers to use ES6 with React?

不羁岁月 提交于 2019-11-29 16:26:22

问题


Do I really need Babel or other transpilers to use ES6 in React?

I was looking at the chart https://kangax.github.io/compat-table/es6/

Seems like my current browser Chrome (latest stable version) supports almost all the ES6 features...

If I can use ES6 without Babel, how I should do it?


回答1:


Without babel you get the compatibility of the chart you linked to. But keep in mind if you want to use JSX you'll want to use babel to transpile that.




回答2:


If you want to:

  • use modules (with require() or import ...)
  • use JSX
  • support a lot of browsers
  • use more advanced features (async/await), some still in proposals (decorators, class properties..)

You must use Babel to be sure that everyone will be able to run your code, else you can develop without it.




回答3:


Absolutely can and do use ES6 W/O babel. All major browsers support the vast majority of features natively (see CanIUse.com), in fact the only major feature not supported is the import/export of modules.

For these you still have to manually import your modules in the correct order using script tags in the HTML. Client side only (Node needs the modules).

However, be aware that this is fine for dev but in production you'll need to concatenate and minimize all the JS into one module anyway so using a Babel/Webpack or Babel/Browserify style toolchain may ultimately be where you end up.



来源:https://stackoverflow.com/questions/38030907/do-i-really-need-babel-or-other-transpilers-to-use-es6-with-react

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