Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
379 views
in Technique[技术] by (71.8m points)

javascript - Is it ok to use Babel npm package for node.js server application

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

There is one main reason: import / export

See:

There is even a special Babel preset for Node:

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

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:

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...