ESbuild is excellent for using with TypeScript and Node.js. We were previously using Nodemon to restart the server on changes. ESbuild is fast enough that rather than having to change our workflow and run a tsc --watch process in addition to Nodemon (which would be rather a pain given that we have 5-6 microservices), we simply use ESbuild to recompile the entire service before restarting the code (it takes about 0.1 seconds to compile everything, so it effectively doesn't impact our workflow at all).
We don't use esbuild's "bundle" (--bundle) option, which means that our files get processed one-by-one and end up as separate files in the `dist` directory that we output to and that dependencies aren't processed at all and are just `required` like normal by our transpiled code.
Our build command (in a bash script file to avoid string escaping issues) is:
Thanks for sharing, I’ve just given it a go with one of my larger projects and WOW!! Typescript incremental compilation was taking around 2 seconds on every save, then Nodemon would restart etc.
I’ve plugged in Esbuild, I have used bundle mode though to see what it’s like, it works fine if I external all of my node modules, it builds in 0.23 seconds (approx 350 source files in my project).
Nodemon now watches for TS file changes and exec’s the esbuild on every start.
Thank you for the pointer to this as this will be a much needed productivity boost!
I’ll try bundling some node modules when I have some time but it will take more work as I use Yarn PnP (I’ve found a plug-in so will definitely try that)
Yes, but tsc is super-slow if you don't use watch mode (and to be honest even if you do). The advantage of using esbuild is that it doesn't slow down the edit-test workflow.