I am using Typescript in my node project and this my tsconfig -
{
"compilerOptions": {
"module": "commonjs",
"esModuleInterop": true,
"target": "es6",
"noImplicitAny": true,
"moduleResolution": "node",
"sourceMap": true,
"outDir": "dist/application",
"baseUrl": "./src",
"paths": {
"*": [
"node_modules/*",
"src/shared/types/*"
]
}
},
"include": [
"src/**/*"
],
"exclude": [
"node_modules"
],
"typedocOptions": {
"mode": "modules",
"out": "docs"
}
}
This is my application folder structure -
.
├── dist
│ └── application
│ ├── app.js
│ ├── app.js.map
│ ├── modules
│ └── shared
├── environments
│ └── .env.development
├── node_modules
├── nodemon.json
├── package-lock.json
├── package.json
├── security
│ ├── domain.crt
│ └── domain.key
├── src
│ ├── app.ts
│ ├── modules
│ │ ├── chat
│ │ ├── main-controller.ts
│ │ └── sso
│ └── shared
│ ├── constants
│ ├── models
│ ├── types
│ └── utils
├── tsconfig.json
└── typedoc.json
After compilation, Typescript compiler puts everything in .dist/application.
While development, my main file (app.ts) was in ./src/app.ts. In this app.ts file, I was trying to read .env.development file in ./src/app.ts. this is how I was reading this file in app.ts -
config({ path: resolve(Utils.getAppRoot(), "../environments/.env.development") });
but at runtime system is not able to resolve the path for .env file, since TS compiler is putting app.ts code in ./dist/application/app.js, and Node is not able to find the path of .env file with respect to the current root path.
To resolve this issue, I need to copy my all the configuration/static files (here, .env file) into ./dist folder at the time of compilation.
Can someone help me to set-up the ts-config so that these static files get copied to ./dist/folder at the time of compilation?