nodemon watches onjy JavaScript files not TypeScript

流过昼夜 提交于 2020-05-17 06:03:30

问题


nodemon should be started on debugging in Visual Studio Code and watch TypeScript. On any TypeScript changes, it should re-compile them using ts-node. I'm struggling with many issues here. The currently most important one is that nodemon watches only the generated .jsfiles, but not the original .tsones - although I explicit let them watch typescript.

launch.json

{
    "type": "node",
    "request": "launch",
    "name": "nodemon",
    "runtimeExecutable": "nodemon",
    "program": "${workspaceFolder}/index.ts",
    "outFiles": [
        "${workspaceRoot}/dist/*.js"
    ],
    "restart": true,
    "console": "integratedTerminal",
    "internalConsoleOptions": "neverOpen",
    "args": [
        "--inspect-brk",
        "-x 'echo hello123'"
    ],
    "timeout": 30000
}

When I start debugging, "hello123" is printed. After saving index.ts nothing happens. If the generated dist/index.js script is saved by hand, it shows "hello123" too.

Of course, this is only to isolate the issue. In fact, I want to run a npm script to re-compile typescript like this:

"scripts": {
    "ts-node": "ts-node --inspect-brk index.ts"
}

But the main problem is: Why does nodemononly watches the generated js-files instead of their typescript ones? Seems like this is caused by outFiles attribute. Without it's not working, it shows an error that corresponding js files cant' be found.


回答1:


You can configure nodemon to watch typescript files as it does not watch .ts by default

Add nodemon.json file in root with the following content, and then just run nodemon:

{
  "watch": ["src"],
  "ext": "ts",
  "ignore": ["**/*.test.ts", "**/*.spec.ts", ".git", "node_modules"],
  "exec": "ts-node ./index.ts"
}

or run nodemon as

nodemon --watch 'workspace/*.ts' --exec 'ts-node' index.ts

I hope this will work.



来源:https://stackoverflow.com/questions/48565505/nodemon-watches-onjy-javascript-files-not-typescript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!