nodemon 只监视 JavaScript 文件而不是 TypeScript [英] nodemon watches onjy JavaScript files not TypeScript

查看:88
本文介绍了nodemon 只监视 JavaScript 文件而不是 TypeScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

nodemon 应该在 Visual Studio Code 中开始调试并观察 TypeScript.对于任何 TypeScript 更改,它应该使用 ts-node 重新编译它们.我在这里遇到了很多问题.目前最重要的是 nodemon 只监视生成的 .js 文件,而不是原始的 .ts 文件 - 尽管我明确让它们看打字稿.

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
}

当我开始调试时,打印hello123".保存 index.ts 后什么也没有发生.如果生成的 dist/index.js 脚本是手动保存的,它也会显示hello123".

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.

当然,这只是为了隔离问题.实际上,我想运行一个 npm 脚本来重新编译打字稿,如下所示:

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"
}

但主要问题是:为什么nodemon只查看生成的js文件而不是它们的打字稿?似乎这是由 outFiles 属性引起的.没有它就不能工作,它会显示一个错误,找不到相应的 js 文件.

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.

推荐答案

您可以将 nodemon 配置为查看 typescript 文件,因为它默认不查看 .ts

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

在root中添加nodemon.json文件,内容如下,然后运行nodemon:

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"
}

或以

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

我希望这会奏效.

这篇关于nodemon 只监视 JavaScript 文件而不是 TypeScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆