问题
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 .js
files, but not the original .ts
ones - 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 nodemon
only 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