Configure TypeScript project references
Improvements:
- The common/ project is automatically built by dependent projects
- Building common/ in in the "prepare" script is thus no longer necessary
- Vite and server hot-reloading now work if files in common/ change
- Recompiling common after every change is done automatically
- Using "go to definition" now jumps to the .ts file rather than the .d.ts
Changes:
- Use TypeScript project references to refer to common/ from client/ and server/
- Set "composite" and "declarationMap" options in common/tsconfig.json
- See https://www.typescriptlang.org/docs/handbook/project-references.html
- Use tsc --build in order to build references automatically
- Replace nodemon and ts-node with ts-watch in server in order to use the new tsc --build mode
- See https://github.com/TypeStrong/ts-node/issues/897#issuecomment-647035509
- Remove now unneeded SIGUSR2 signal handler which was for nodemon
- Use tsc-watch before Vite in client in order for hot-reloading to work if common/ changes
- Update TypeScript version
- Add vite.config.node.json to be consistent with expected Vite project defaults
GitLab: #151
Change-Id: Id2f84fe45e44c4d8b4e6d3b324e1aee322c52df6
diff --git a/server/package.json b/server/package.json
index 5ad16ee..471079d 100644
--- a/server/package.json
+++ b/server/package.json
@@ -3,10 +3,10 @@
"version": "1.0.0",
"type": "module",
"scripts": {
- "start": "nodemon --watch src src/index.ts",
+ "start": "tsc-watch --build --onSuccess \"node dist/index.js\"",
"start:prod": "env NODE_ENV=production node dist/index.js",
- "build": "tsc",
- "clean": "rm -rf dist tsconfig.tsbuildinfo",
+ "build": "tsc --build",
+ "clean": "rm -rf dist *.tsbuildinfo",
"lint": "eslint src",
"lint:fix": "eslint --fix src",
"format": "prettier --write src",
@@ -36,8 +36,7 @@
"@types/whatwg-url": "^11.0.0",
"@types/ws": "^8.5.3",
"dotenv-cli": "^6.0.0",
- "nodemon": "^2.0.20",
- "ts-node": "^10.9.1",
- "typescript": "^4.8.4"
+ "tsc-watch": "^5.0.3",
+ "typescript": "~4.8.4"
}
}