"scripts": {
"start": "npm run prod",
"build": "npm-run-all clean transpile",
"server": "node ./dist/bin/www",
"dev": "npm run lint && NODE_ENV=development nodemon --inspect=notifications:9236 --exec babel-node bin/www",
"prod": "NODE_ENV=production npm-run-all build server",
"transpile": "babel ./ --out-dir dist",
"lint": "eslint '*.js' ",
"lint:watch": "watch 'npm run lint' ",
"precommit": "npm run lint",
"prepush": "npm run lint",
"clean": "rimraf dist",
"test": "jest"
}
我在 docker 上有多个微服务,每个微服务的 package.json 中都包含类似的脚本。 每当我进行更改并保存文件时,nodemon 都不会检测到更改并重新启动服务器。
Nodemon 在微服务启动时启动,输出以下内容:
[nodemon] 2.0.15
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): **/* public/**/*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `babel-node --inspect=notifications:9236 bin/www`
我必须提到,这是一个基于 Mac OS 构建的项目,如果有相关的话,我目前正在 Windows 上运行它。
最佳答案
这与 Windows 相关,因为运行 unix 的容器中的文件系统存在差异 Duplicate question
如果您设置 nodemon.json
来轮询更改,它应该更新,但内存非常昂贵
{
"verbose": true,
"watch": ["src/**/*.ts"],
"exec": "ts-node ./src/index.ts",
"pollingInterval": 100,
"legacyWatch": true
}
关于node.js - Nodemon 在文件更改时未重新启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70802513/