Nodemon 没有重新加载。这个 nodemon.json 文件有什么问题

Nodemon not reloading. What's wrong with this nodemon.json file

这是我的nodemon.json

{ 
    "watch": ["src/**/*.ts"],
    "exec": "node out/index.js" 
}

我通过执行 运行 nodemon:

nodemon

根nodejs目录下

这是输出:

 % nodemon                                                                                                     
[nodemon] 1.11.0                                                                                
[nodemon] to restart at any time, enter `rs`                                                                                                                       
[nodemon] watching: src/**/*.ts                                                                                                                       
[nodemon] starting node out/index.js
Yay! Started app!

但是当我在 src 中编辑任何 ts 文件时,nodemon 不会重新启动应用程序。

更新

运行 nodemon --watch src/index.ts --exec 'node out/index.js'

在修改 index.ts

时运行并重新加载应用程序

但是,运行 通配符

nodemon --watch 'src/**/*.ts' --exec 'node out/index.js'

nodemon --watch src --exec 'node out/index.js'

不重新加载应用程序。

已解决!

通过 运行 nodemon 在详细模式下我发现 默认情况下它只监视 *.js 文件,不管你正在看什么通配符。因此,在命令中添加 -e ts 可以解决问题:

nodemon --watch src/ --exec 'node out/index.js' -e ts

如果有人使用 nodemon.json 这是我修复后的:

{ 
    "watch": ["src"],
    "exec": "tsc && node out/index.js" ,
    "ext": "js, json, ts, proto"
}

在 package.json 脚本中将 single quotation 用于多值参数,例如 `--exec'。

例如我将 "nodemon --exec npm run build-langs" 更改为 "nodemon --exec 'npm run build-langs'" 并工作。