kmagiera / babel-watch

Reload your babel-node app on JS source file changes. And do it fast.
MIT License
528 stars 70 forks source link

why it's faster than the combination of nodemon and babel? #116

Closed jiajianrong closed 3 years ago

jiajianrong commented 3 years ago

In the readme Why should I use it?,

babel-watch only starts babel in the "master" process where it also starts the file watcher. The transpilation is performed in that process too. On file-watcher events, it spawns a pure node process and passes transpiled code from the parent process together with the source maps. This allows us to avoid loading babel and all its deps every time we restart the JS script/app.

That means there are two node processes: main process is in charge of babel transpilation and file watching, then passes the translated(es5) code to the child process, which runs the code as web server.

When a source code file is changed, you have to use babel to regenerate the es5 code, and terminate the old child process and recreate a new one as the web server. So why the performance is better than nodemon&babel-node? Thanks.

PS: nodemon&babel-node here is supposed to be: nodemon --inspect=10111 --exec babel-node server.js

STRML commented 3 years ago

It's faster because that babel-node will restart completely and need to re-load all the babel dependencies, which takes a little while, while babel-watch keeps the process running.

Think of it like an all-in-one combination of nodemon with babel --watch.