While debugging an express server my 'build & run' process consists of 3 steps:
tsc
dist/
server.js
fileEach of these steps can be automated using a watch mode, but I'm struggling to combine the three together. I managed to get it working by using tsc-watch to watch the TypeScript sources, cpx to copy the static files and finally nodemon to restart the server. This approach works but there are a couple of issues:
cpx
only watches files that existed at the time it started (I think tsc-watch
does this too sometimes, it's a little weird)cpx
& tsc-watch
do not handle Ctrl+C
exit correctly, causing all sorts of issuesI found some other questions that relate to this subject, but none of them fix the aforementioned issues (although they did tell me about cpx & tsc-watch).
I don't want to use concurrently because it can cause timing issues and it mixes console output from the different processes (most notably tsc-watch
and the actual server).
Using tsc-watch
'es --onSuccess
to copy the static files is not sufficient, since changes in the template files won't be picked up on. This can be worked around by changing a comment in a source file, but this triggers a complete recompile (restarting the server).
Using webpack's watch mode wouldn't be sufficient either since it doesn't pick up on new files and contaminates the console output even more.
Are there any solutions to this that I may have missed? Should I just write a script that automatically opens the 3 required terminals?
I ended up going for webpack with the copy-webpack-plugin.
Although the watch mode is unfortunately broken at the time of writing, it seems like it fits my needs almost perfectly:
Ctrl+C
exits gracefully