Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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'",
like image 787
SwiftiSwift Avatar asked Sep 18 '19 18:09

SwiftiSwift


People also ask

Does Nodemon working with TypeScript?

As of v1. 19.0, nodemon has inbuilt support for TypeScript files with help from ts-node that requires no manual configuration. By default, nodemon uses the node CLI as an execution program for running JavaScript files; for TypeScript files, nodemon uses ts-node as the execution program instead.

Does TS-node use Tsconfig?

ts-node supports a variety of options which can be specified via tsconfig.


1 Answers

Nodemon will detect and run .ts files with ts-node automatically now. It will actually run .py and .rb files with python and ruby too btw and you can give it a custom --exec for others. Here's a link to the relevant code within nodemon.

So the following should be fine:

"scripts": {
  "dev": "nodemon app.ts"
}
like image 57
kjs3 Avatar answered Sep 21 '22 13:09

kjs3