nodejs从用es6/7/8写项目到发布

本来用传统js写得好好的,然后几个月前开始用ES6陆陆续续写了几个小的东西,其实写的时候也还挺顺的。开发时运行起也是好好的,然后准备发布了。。。

哈哈

晚了,还要带娃,先写个大概,后面来补

要写的东西先整理一下

1

babel-* 那一堆东西

然后 babel-那一堆现在不维护了,要改成 @babel/xxx

2

转代码,es6 转 es5,开发的时候,用babel-node 运行,生产环境,应该先转代码为ES5。
官方说法

Not meant for production use
You should not be using babel-node in production. It is unnecessarily heavy, with high memory usage due to the cache being stored in memory. You will also always experience a startup performance penalty as the entire app needs to be compiled on the fly.

Check out the example Node.js server with Babel for an idea of how to use Babel in a production deployment.

ES6-style module-loading may not function as expected
Due to technical limitations ES6-style module-loading is not fully supported in a babel-node REPL.

3

转代码貌似只转 .js 文件,其它文件要手动copy ? 有没有相关参数

4

踩坑的后续,后面直接上es8/9了,es7就跳过了

5

本来 node 里写es5语法,就能直接支持 async/await 的,用es6后,反而不行了,报错
regeneratorRuntime is not defined ,用 npm install regenerator 貌似能解决
依赖 babel-runtime 貌似也包含了相关的库

相关的链接

https://babeljs.io/docs/en/6.26.3/babel-plugin-transform-runtime

https://babeljs.io/docs/en/babel-node#not-meant-for-production-use

0%