I have the following structure:
apps
|-api
|-src
|-_migrations
|-_seeds
|-dev
|-test
|-app
|-assets
|-environments
|-main.ts
|-tsconfig.app.json
|-tsconfig.json
I am using ng serve api
to compile and serve api
which is a NestJS backend. This belongs to a monorepo with an Angular frontend.
The migrations and seeders inside _migrations
and _seeds
are in TypeScript. To run them when serving the backend, I need to compile them to JavaScript and locate the compiled files into dist/apps/api
.
I know I could compile the files with tsc
before serving, or specify a webpack configuration file in angular.json
, but I would like to keep it as simple as possible, and just try to use some configuration with ng
.
I tried adding the paths in the tsconfig.app.json
which is used in the angular.json
.
// angular.json
"api": {
"root": "apps/api",
"sourceRoot": "apps/api/src",
"projectType": "application",
"prefix": "api",
"schematics": {},
"architect": {
"build": {
"builder": "@nrwl/node:build",
"options": {
"outputPath": "dist/apps/api",
"main": "apps/api/src/main.ts",
"tsConfig": "apps/api/tsconfig.app.json",
"assets": ["apps/api/src/assets"]
},
"configurations": {
"production": {
"optimization": true,
"extractLicenses": true,
"inspect": false,
"fileReplacements": [
{
"replace": "apps/api/src/environments/environment.ts",
"with": "apps/api/src/environments/environment.prod.ts"
}
]
}
}
},
"serve": {
"builder": "@nrwl/node:execute",
"options": {
"buildTarget": "api:build"
}
}
}
}
// tsconfig.app.json
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"types": ["node"]
},
"exclude": ["**/*.spec.ts"],
"include": ["**/*.ts"], // or ["**/*.ts", "src/_migrations/*.ts", "src/_seeds/**/*.ts"] without "files"
"files": ["src/_migrations/*.ts", "src/_seeds/**/*.ts"]
}
Is there a way to compile all the files in _migrations
and _seeds
when running ng serve api
and ng build api
just switching some configuration or similar?
If not, which would be the simplest webpack configuration to achieve this?