I faced a problem :/ I want the shared codebase "shared" to be in both directories. Is this possible with typescript itself or do I need some extra build-tasks? Is there a better solution?
Important: The "shared" folder needs to be generated in srv and app, otherwise our core system would break.
I've got following src directory, where client contains a client.ts, server a server.ts and shared contains a index.ts. Now I want to use shared in client.ts and server.ts.
src
- client
- client.ts
- tsconfig.json
- server
- server.ts
- tsconfig.json
- shared
- index.ts
- tsconfig.json
If I'm compiling my TypeScript, the following output should be generated.
app
- client
- client.js
- shared
- index.ts
srv
- server
- server.js
- shared
- index.ts
Here are my configs for each directory client/tsconfig.json
{
"compileOnSave": true,
"compilerOptions": {
"target": "es2018",
"module": "commonjs",
"noImplicitAny": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"removeComments": true,
"preserveConstEnums": true,
"outDir": "../../app",
"sourceMap": true,
"diagnostics": true,
},
"include": [
"client.ts"
],
"references": [
{ "path": "../shared"}
]
}
server/ts.config.json
{
"compileOnSave": true,
"compilerOptions": {
"target": "es2018",
"module": "commonjs",
"noImplicitAny": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"removeComments": true,
"preserveConstEnums": true,
"outDir": "../../srv",
"sourceMap": true,
"diagnostics": true,
},
"include": [
"server.ts"
],
"references": [
{
"path": "../shared"
}
]
}
shared/tsconfig.json
{
"compilerOptions": {
"declaration": true,
"declarationMap": true,
"composite": true,
},
"include": [
"*.*"
],
"references": []
}
PS: If there is a better solution to solve this issue. Please let me know :)
Kind regards, Sebastian