简体   繁体   English

在WebStorm上使用ECMAScript 6而不安装Babel

[英]Using ECMAScript 6 on WebStorm without installing Babel

I enabled ECMAScript 6 on WebStorm so that I do not get IDE errors when using arrow functions. 我在WebStorm上启用了ECMAScript 6,这样我在使用箭头功能时就不会出现IDE错误。

However, I did not install Babel. 但是,我没有安装Babel。 I was prompted to install Babel after enabling ECMAScript 6. I had problems installing Babel. 在启用ECMAScript 6后,我被提示安装Babel。我在安装Babel时遇到问题。

Is it necessary to use Babel together with ECMAScript 6? 是否有必要将Babel与ECMAScript 6一起使用? What would be the side effect of enabling ECMAScript 6 without installing Babel? 如果不安装Babel,启用ECMAScript 6会产生什么副作用?

I am using node.js on WebStorm. 我在WebStorm上使用node.js.

The purposes of Babel is to convert es6 code into es5 code BECAUSE most browsers do not FULLY support es6 yet, although are getting closer. Babel的目的是将es6代码转换为es5代码,因为大多数浏览器还没有完全支持es6,尽管越来越近了。

https://kangax.github.io/compat-table/es6/ https://kangax.github.io/compat-table/es6/

You will see that IE11 support is poor whilst Firefox and Chrome almost have full support. 你会发现IE11的支持很差,而Firefox和Chrome几乎完全支持。

However, given that the latest Node fully understands ES6 there is now no need for Babel when using Node only unless of course you need to support older versions of Node which only understand ES5. 但是,鉴于最新的Node完全理解ES6,现在只使用Node时不需要Babel,除非您当然需要支持只能理解ES5的旧版Node。

PS: if you enable Babel support in Webstorm it can generate ES5 files on the fly for you as you code in ES6. PS:如果您在Webstorm中启用Babel支持,它可以在您编写ES6代码时随时为您生成ES5文件。 Alternatively, you can use a task runner such as Grunt or Gulp to do this for you. 或者,您可以使用Grunt或Gulp等任务运行程序为您执行此操作。 Depends if you need it! 取决于你是否需要它!

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

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