How to watch and reload ts-node when TypeScript files change

后端 未结 11 1546
梦如初夏
梦如初夏 2020-11-30 17:00

I\'m trying to run a dev server with TypeScript and an Angular application without transpiling ts files every time. I found that I can do the running with ts-node

11条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-30 17:27

    Here's an alternative to the HeberLZ's answer, using npm scripts.

    My package.json:

      "scripts": {
        "watch": "nodemon -e ts -w ./src -x npm run watch:serve",
        "watch:serve": "ts-node --inspect src/index.ts"
      },
    
    • -e flag sets the extenstions to look for,
    • -w sets the watched directory,
    • -x executes the script.

    --inspect in the watch:serve script is actually a node.js flag, it just enables debugging protocol.

提交回复
热议问题