Is it ok to use Babel npm package for node.js serv

2019-01-28 07:38发布

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?

1条回答
做自己的国王
2楼-- · 2019-01-28 08:33

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:

查看更多
登录 后发表回答