'Using tsc --build flag with ts-node?
I have a library that has a sub-project which spins up a server utilizing the library for quick development. The project structure looks like this:
--Library root
|-src/
|-example/
|-server/
|-src/
|-tsconfig.json
|-package.json
|-tsconfig.json
|-package.json
The idea is that I can run the sever in the examples directory, and it'll utilize the same code from the parent library project. So when the library code changes, the server will restart to reflect those changes. For this I'm using TypeScript project references: https://www.typescriptlang.org/docs/handbook/project-references.html
I have this in my server's example/server/package.json
"scripts": {
"serve": "nodemon ./src/server.ts",
},
example/server/nodemon.json watches for ts file changes from the parent project directory and exec ts-node
{
"watch": "../../**/*.ts",
"execMap": {
"ts": "ts-node"
}
}
So this will eventually run ts-node ./src/server.ts. This works, however it's not building the parent library when there's changes. Looking into it, it looks like I have to pass in --build to tsc for it to build dependancies. But I don't know how to pump that option into ts-node, or if that's even possible.
Solution 1:[1]
A possible solution is to modify the package.json in the server directory to use something like this:
"scripts": {
"prestart": "tsc --build",
"start": "nodemon ./src/server.ts"
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | MarcosNC |
