我可以在ES6的生产中使用Babel Require Hook吗?

时间:2021-05-27 00:05:54

I have a node app that uses ES6. I'm using Babel for transpiling. As far as i understand use a build system like Gulp for example or use the require hook . The Require Hook approach seems appealing to me since i will be able to keep my source files in ES6 but still execute them using node server.js without the use of some build system.

我有一个使用ES6的节点应用程序。我正在使用Babel进行转换。据我所知,使用像Gulp这样的构建系统或使用require钩子。 Require Hook方法似乎对我很有吸引力,因为我能够将我的源文件保存在ES6中,但仍然使用节点server.js执行它们而不使用某些构建系统。

This seems extremely useful for develop at least, my main concerns is about the use of this approach in production.

这对于至少开发来说似乎非常有用,我主要担心的是这种方法在生产中的使用。

  • Does it have any penalty hit every time that a user makes a request ?
  • 每次用户提出请求时是否会受到任何惩罚?

  • How this works exactly ?
  • 这是如何工作的?

For context i'm using it with an Express app.

对于上下文我正在使用Express应用程序。

1 个解决方案

#1


7  

Does it have any penalty hit every time that a user makes a request ?

每次用户提出请求时是否会受到任何惩罚?

No, not in the sense that it would have to re-transpile the code on every request.

不,不是因为它必须在每个请求上重新转换代码。

How this works exactly ?

这是如何工作的?

The require hook basically hi-jacks all subsequent calls to require(), and performs the ES6->ES5 transpiling prior to that module being executed.

require hook基本上是hi-jacks所有后续调用require(),并在执行该模块之前执行ES6-> ES5转换。

I've been using the babel require hook in production for awhile now (with moderate traffic levels -- peak traffic in the mid-hundreds req/sec range), and it's never been an issue.

我一直在使用babel需要挂钩生产一段时间(中等流量水平 - 中等数百里亚/秒范围内的峰值流量),这从来都不是问题。

#1


7  

Does it have any penalty hit every time that a user makes a request ?

每次用户提出请求时是否会受到任何惩罚?

No, not in the sense that it would have to re-transpile the code on every request.

不,不是因为它必须在每个请求上重新转换代码。

How this works exactly ?

这是如何工作的?

The require hook basically hi-jacks all subsequent calls to require(), and performs the ES6->ES5 transpiling prior to that module being executed.

require hook基本上是hi-jacks所有后续调用require(),并在执行该模块之前执行ES6-> ES5转换。

I've been using the babel require hook in production for awhile now (with moderate traffic levels -- peak traffic in the mid-hundreds req/sec range), and it's never been an issue.

我一直在使用babel需要挂钩生产一段时间(中等流量水平 - 中等数百里亚/秒范围内的峰值流量),这从来都不是问题。