简体   繁体   English

我可以在 ES6 中使用服务器端节点 js 并且仍然不使用 bable

[英]Can I use server-side node js with ES6 and still without using bable

We are using nodejs 6.4.0 on server-side code only with ES6 style of code.我们在服务器端代码上使用 nodejs 6.4.0,仅使用 ES6 风格的代码。 Currently we use babel transpiler to convert it into old fashioned javascript.目前我们使用 babel transpiler 将其转换为老式的 javascript。 My question is, since out code going to be executed on server side only can we use ES6 style code as is with node 6.4.0 version, can we get rid of babel altogether.我的问题是,由于输出代码只能在服务器端执行,我们可以像 node 6.4.0 版本一样使用 ES6 风格的代码,我们可以完全摆脱 babel 吗? I checked ES6 compatibility for node 6.4.0, and confirmed that we are using only the supported features (ref http://node.green/ ) Has anyone having any guideline for this?我检查了节点 6.4.0 的 ES6 兼容性,并确认我们仅使用受支持的功能(参考http://node.green/ ) 有没有人对此有任何指导?

Ofc you can.你可以。 Node.js 6.x already supports 99% of ES6 features! Node.js 6.x 已经支持 99% 的 ES6 特性! You can drop babel if you are 100% complaint with Nodejs 6.x features!如果你对 Nodejs 6.x 特性 100% 抱怨,你可以放弃 babel!

Are you using import * as lib from 'myLib' syntax?您是否使用import * as lib from 'myLib'语法? Currently just the latest version of node supports this sintax.目前只有最新版本的 node 支持这个 sintax。

Try to remove the babel transpilation and run directly your application using node src/index.js :)尝试删除 babel 转译并使用node src/index.js直接运行您的应用程序:)

to use es6 fetures like import and export without transpiler you must set your files ending with .mjs要在没有转译器的情况下使用 es6 fetures,例如导入导出,您必须设置以 .mjs 结尾的文件

run your files with --experimental-modules flag to enable features.使用--experimental-modules标志运行您的文件以启用功能。

Note笔记

ES Module status is draft now. ES 模块状态现在是草案。

DRAFT status does not mean ESM will implemented in Node core. DRAFT 状态并不意味着 ESM 将在 Node 核心中实现。 Instead that this is the standard, should Node core decide to implement ESM.相反,这是标准,如果 Node 核心决定实施 ESM。 At which time this draft would moved to ACCEPTED.届时,该草案将移至 ACCEPTED。

look at this https://nodejs.org/api/esm.html看看这个https://nodejs.org/api/esm.html

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

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