I have a project written in TypeScript and running on Node. I'm really struggling to write the script with npm to get it running for development. What I trying to do is:
- clean the
/distfolder - if a
.tschange, compile it into/distand restart node
Here is my 1st attempt, from the scripts section of my package.json:
"clean": "rimraf dist/**/*",
"build": "tsc",
"watch:start": "npm run clean && nodemon -e ts --exec \"npm run start\"",
"start": "npm run build && node dist/index.js"
If I start my project with npm run watch:start, it got stuck in a loop:
npm run watch:start
> nodemon -e ts --exec "npm run start"
[nodemon] 1.11.0
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `npm run start`
[nodemon] restarting due to changes...
[nodemon] restarting due to changes...
[nodemon] starting `npm run start`
[nodemon] restarting due to changes...
[nodemon] restarting due to changes...
Here is my 2nd attempt, using npm-run-all to run several task in parallel:
"clean": "rimraf dist/**/*",
"build": "tsc",
"watch:start": "npm-run-all clean build --parallel --race watch:build watch:serve --print-label",
"watch:build": "tsc -w",
"watch:serve": "nodemon dist/index.js"
This one works better but it still restart node several time at startup.
Suggestions and improvements welcome !