Search code examples
javascriptnode.jstypescriptvisual-studio-codenodemon

Run Nodemon with Typescript compiling?


I want my typescript files to be compiled on every file saving with the command tsc.

How do I combine the tsc command with the command that nodemon runs in the build:live script

"scripts": {
    "start": "npm run build:live",
    "build:live": "nodemon --watch '*.ts' --exec 'ts-node' app.ts",
 }

this script causes nodemon to call itself twice or three times:

"build:live": "nodemon --watch '*.ts' --exec 'ts-node app.ts & tsc'",

Solution

  • This looks like it will achieve what you're looking for:

    "start": "tsc-watch --project . --outDir ./dist --onSuccess \"nodemon ./dist/bin/www.js\""
    

    Source: https://github.com/Microsoft/TypeScript/issues/12996#issuecomment-349277673