Can I use Babel Require Hook to produce ES6?

I have a node application that uses ES6. I use Babel for forwarding. As far as I understand, for example, use a build system like Gulp, or use require hook . The Require Hook approach seems attractive to me, since I can save the source files in ES6, but I still execute them using node server.js without using any build system.

It seems extremely useful to develop, at least my main concern is to use this approach in production.

  • Is there any penalty every time a user makes a request?
  • How it works?

For context, I use it using the Express application.

+6
source share
1 answer

Is there any penalty every time a user makes a request?

No, not in the sense that he will have to re-broadcast the code for each request.

How it works?

The hook request basically welcomes all subsequent calls to require() and runs ES6-> ES5, which translates before this module executes.

I use babel to demand a capture in production for some time (with moderate traffic levels — peak traffic in the range from mid-hundreds of req / sec), and this has never been a problem.

+7
source

All Articles