是否可以将Babel npm软件包用于node.js服务器应用程序 [英] Is it ok to use Babel npm package for node.js server application

查看:95
本文介绍了是否可以将Babel npm软件包用于node.js服务器应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于Node V6已经支持约95%的ES6,为什么人们在服务器端使用Babel?在服务器端使用Babel的利弊是什么?

As Node V6 already supports ~95% of ES6, why are people using Babel on the server side? What are the pros and cons of using Babel on the server side?

推荐答案

有一个主要原因:import/export

请参阅:

  • https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import
  • https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export

甚至还为节点设置了特殊的Babel预设:

There is even a special Babel preset for Node:

不会转换Node本身已经支持的任何内容.

that doesn't transpile anything that Node already supports natively.

您还可以使用babel-preset-env,这是"Babel预设,可以根据支持的环境自动确定所需的Babel插件和polyfill"-感谢 loganfsmyth 在评论.参见:

You can also use babel-preset-env which is "A Babel preset that can automatically determine the Babel plugins and polyfills you need based on your supported environments" - thanks to loganfsmyth for pinting it out in the comments. See:

并且Node不支持ES6模块-有关原因的详细信息,请参见以下答案:

And Node doesn't support ES6 modules - see this answer for details on why:

这篇关于是否可以将Babel npm软件包用于node.js服务器应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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