简体   繁体   中英

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. Currently we use babel transpiler to convert it into old fashioned 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. 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?

Ofc you can. Node.js 6.x already supports 99% of ES6 features! You can drop babel if you are 100% complaint with Nodejs 6.x features!

Are you using import * as lib from 'myLib' syntax? Currently just the latest version of node supports this sintax.

Try to remove the babel transpilation and run directly your application using node src/index.js :)

to use es6 fetures like import and export without transpiler you must set your files ending with .mjs

run your files with --experimental-modules flag to enable features.

Note

ES Module status is draft now.

DRAFT status does not mean ESM will implemented in Node core. Instead that this is the standard, should Node core decide to implement ESM. At which time this draft would moved to ACCEPTED.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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