我尝试同时使用nodemon
+ts-node
以及ts-node-dev
在开发时自动重新加载。
但是,两者都遇到了相同的问题,即某些文件没有被正确监视并且不使用保存的更改,除非我npm run build
先手动运行。
这是我的package.json
:
{
"scripts": {
"start": "ts-node-dev src/server/index.ts",
"build": "rimraf ./build && tsc",
"format": "prettier --write \"**/*.ts\""
},
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.19.0",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"knex": "^0.21.14",
"module-alias": "^2.2.2",
"morgan": "^1.10.0",
"passport": "^0.4.1",
"passport-google-oauth2": "^0.2.0",
"pg": "^8.5.1"
},
"devDependencies": {
"@types/body-parser": "^1.19.0",
"@types/express": "^4.17.8",
"@types/knex": "^0.16.1",
"@types/morgan": "^1.9.2",
"@types/node": "^14.14.6",
"@types/passport": "^1.0.4",
"@types/passport-google-oauth2": "^0.1.3",
"prettier": "^2.2.1",
"rimraf": "^3.0.2",
"ts-node-dev": "^1.1.1",
"typescript": "^4.0.5"
},
"_moduleAliases": {
"@db": "build/server/db"
}
}
这是我的tsconfig.json
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"rootDir": "./src",
"outDir": "./build",
"esModuleInterop": true,
"strict": true,
"baseUrl": "./src",
"paths": {
"@db/*": ["server/db/*"]
}
},
"include": [
"src"
]
}
它正确地重新加载大多数文件的已保存更改,但不是src/server/db/models/voter.ts
. 我怀疑这可能与该文件有关,module-alias
因为该文件被导入为import Voter from '@db/models/voter'
. 我不确定解决方案是什么,因为我没有遇到任何编译或运行时错误,并且在手动运行npm run build
.