gpt4 book ai didi

babeljs - 为什么不应该在生产中使用 babel-node?

转载 作者:行者123 更新时间:2023-12-04 01:12:27 27 4
gpt4 key购买 nike

babel-node docs发出严厉警告:

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.



让我们分解一下:
  • 内存使用——嗯?无论如何,所有模块都在应用程序的生命周期内“缓存”在内存中。他们来这里做什么?
  • 启动惩罚——这是一个性能问题吗?部署 Web 应用程序已经需要几秒钟(如果您在 CI 中进行测试,则需要几分钟)。为启动增加半秒没有任何意义。事实上,如果启动时间在任何地方都很重要,那么它在开发中比在生产中更重要。如果您频繁地重新启动 Web 服务器,以至于启动时间成为问题,那么您将遇到更大的问题。

  • 此外,没有关于使用 Babel 的 require hook 的警告。 ( require('babel-register') ) 在生产中,尽管这可能与 babel-node 几乎完全相同。例如,你可以做 node -r babel-register server.js并获得与 babel-node server.js 相同的行为. (我的公司在数百个微服务中做到了这一点,没有任何问题。)

    Babel 的警告只是 FUD,还是我遗漏了什么?如果警告是有效的,为什么它不适用于 Babel 的 require 钩子(Hook)?

    相关 : Is it okay to use babel-node in production
    – 但该问题只是询问是否建议生产使用,答案只是引用官方建议,即“否”。相比之下,我质疑官方建议背后的推理。

    最佳答案

    通天塔节点
    添加生产警告以解决 this issue :

    Without the kexec module, you can get into a really ugly situation where the child_process dies but its death or error never bubbles up. For more info see https://github.com/babel/babel/issues/2137.

    It would be great if the docs on babel-node explained that it is not aimed for production and that without kexec installed that it has bad behaviour.


    (强调我的)
    原问题 #2137 的链接已失效,但您可以找到它 here .
    所以这里似乎有两个问题:
  • “大型应用程序的内存使用率非常高”
  • “没有安装 kexec,它有不良行为”

  • 这些问题导致生产警告。
    通天塔注册

    Also, there is no such warning about using Babel's require hook (require('babel-register')) in production


    可能没有警告,但也不建议这样做。见 this issue :

    babel-register is primarily recommended for simple cases. If you're running into issues with it, it seems like changing your workflow to one built around a file watcher would be ideal. Note that we also never recommend babel-register for production cases.

    关于babeljs - 为什么不应该在生产中使用 babel-node?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38264828/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com