Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

babel-node vs babel-register in development

Is there any difference between using babel-register or babel-node when running my code in development? The two options are:

  1. require('babel-register')({ "presets": ["es2015"] }); at entry-point.js and npm start script node entry-point.js

  2. simply have npm start script babel-node entry-point.js --preset=es2015

Do they do the exact same thing? And is one way recommended over the other?

like image 317
shayac Avatar asked Feb 20 '17 03:02

shayac


1 Answers

I asked around at work and got an answer. I'm going to post it here in case anyone else is interested.

babel-node basically calls babel-register internally. see source. The differences are

  1. when using babel-node the entry-point itself will also run through babel vs. babel-register only files required after babel-register is required will be run through babel.

  2. if you need babel-polyfill (for eg. generators) babel-node will pull it in automatically, vs. babel-register you'd need to do that yourself. This is something to keep in mind when building for production. If you need babel-polyfill and you are using babel-node in development, you'd need to make sure you are building w/ babel-polyfill when building for production.

One way doesn't seem to be recommended over the other. However, babel-node is a little cleaner b/c it'll keep the require ('babel-register') out of the codebase. It also seems to be a bit more intuitive to someone new to all this stuff.

like image 77
shayac Avatar answered Sep 28 '22 14:09

shayac