Here is another way, use sleep
in your concurrently
command before starting nodemon
.
eg,
"scripts": {
"dev": "concurrently -k \"tsc -p ./src/server -w\" \"tsc -p ./src/client -w\" \"sleep 5 && nodemon ./dist/server/server.js\"",
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node ./dist/server/server.js"
},
In my situation, I generate both client and server typescript projects at the same time, which causes nodemon to actually start 3 times when I execute npm run dev
. But if I sleep 5 seconds before starting the nodemon process, then both tsc processes have already finished, and then continue watching.
You could also use the delay option of nodemon, but I only need it to delay the first time when I execute npm run dev
. After that, every individual recompilation of which ever file in whichever project, correctly restarts nodemon only once.
caveat, If your server is slow, you may need to increase the sleep delay longer than 5.
Also, I did try the accepted answer, but my solution was faster for subsequent recompilations while nodemon and the tsc watch processes continued to run.
1 second for my solution, versus 5 seconds for the accepted. I couldn't get the accepted answer to actually run tsc in watch mode, so that's why it was slower, since both TypeScript projects were getting a full recompile on every change.