pmer / local-cdn

Provide a private, local mirror for the world's CDNs
MIT License
0 stars 0 forks source link

Consider transpiling the JS to ES5 instead of using babel-register #1

Open chrisngobanh opened 8 years ago

chrisngobanh commented 8 years ago

It is not recommended to use babel-register if you want to write ES6 JS for Node because it's slow since Node needs to compile the files during runtime.

https://babeljs.io/docs/usage/require/

The require hook will bind itself to node's require and automatically compile files on the fly.

What I recommend doing is: transpile the ES6 code to ES5, then have Node run the ES5 code instead. I use personally Gulp to do this automatically whenever I make a change to the ES6 code

However, the downside to this is that it may make development a bit slower since you have to wait for the files to finish transpiling before you try it out.

pmer commented 8 years ago

That's a good idea and would definitely be more efficient and would reduce the startup time after the initial compile.

I don't think it would slow down development because you'd have to wait for it to finish compiling either way. In fact, it might even speed up development if you told Gulp to only recompile files that have changed. Right now all files are compiled every time you run.

I am leaning towards not doing this though because I like how right now it doesn't require gulp installed to run.

chrisngobanh commented 8 years ago

Since you have to manually restart the Node server every time you make a change anyways (Ctrl-C, Up-Arrow, Enter), an alternative would be to change the npm start script to transpile your files before starting up the app. This way, you won't need Gulp.

However, I'm not sure if this would be any different than what you're currently doing.