In my current project setup, I have a library with a sub-project that launches a server using the same code from the parent library for rapid development. The structure of the project is as follows:
--Library root
|-src/
|-example/
|-server/
|-src/
|-tsconfig.json
|-package.json
|-tsconfig.json
|-package.json
The main concept is to run the server in the examples directory, leveraging the code from the parent library. This means that any changes made to the library code will trigger a restart of the server to reflect those updates. To achieve this, TypeScript project references are utilized: https://www.typescriptlang.org/docs/handbook/project-references.html
Inside the server's example/server/package.json
, I have added the following script:
"scripts": {
"serve": "nodemon ./src/server.ts",
},
The file example/server/nodemon.json
monitors changes in the ts files from the parent project directory and executes ts-node accordingly:
{
"watch": "../../**/*.ts",
"execMap": {
"ts": "ts-node"
}
}
As a result, the command ts-node ./src/server.ts
is executed. While this method works fine, it does not rebuild the parent library upon changes. After investigation, I found out that passing --build
to tsc
triggers the building of dependencies. However, I am unsure of how to incorporate this option into ts-node
, or if it is even feasible.