使用 grunt 或 gulp "compile" 节点项目有意义吗?

Does it make sense to "compile" node project with grunt or gulp?

我花了很多时间构建一个带有 g运行t 文件的 Web 模板(前端)到 "compile" 整个项目,并且在生产中有一个高效的代码。

现在我正在从事后端项目(使用 node/express),我想知道 "compile" 节点项目是否有意义?

我在 Babel 中使用 ES6 语法,所以我想每次我启动项目(node index.js 或 nodemon index.js)时,Babel 都会在 ES5 中转译它,然后 运行 .

我不管是不是在项目开始的时候就做了,一旦启动了就没有影响了。但我不确定。

node 是否读取整个程序并将其 "save" 写入 ram?如果是这样,我想它对 concat/compile javascript 文件没有用,就像我们习惯于使用前端一样。

是的,至少这不是个坏主意。

但是:

  • nodemon 不适用于生产
  • 当您 运行 babel 作为 运行 时,您将其引入为可能失败的附加层,在您的代码之上。
  • 仅从转译的 js 读取对于较旧的 node 平台可能更容易,或者当您将其作为模块提供时效率更高。

更好:

  • 使用而不是NODE_ENV=生产
  • 是的,它确实将其保存到 RAM 中。解析会更快,但只是略有增加。
  • 确实,当您缩小代码时,您的 js 的编译时间会更好。但副作用(例如更差的可调试性)是权衡。
  • OH:对于不超过特定 char 计数的函数,可以对 V8 进行性能优化。但效果可能真的很低,因为只有真正热门的功能才能从中受益。
  • 编译和丑化将有助于混淆,如果你需要发送你的代码。 npm shrinkwrap 也是一个很好的工具。

Concluding: Don't do it, since it rather feels like premature optimization, which is generally a bad idea. You will meet heavy problems of node debugability, which will be a problem at dev-time.

Rather follow general Node.js performance guide, and if you don't target other platforms than your production environment, choose the newest Node.js version with all the ES6 features you need.