0

My project folder directory is like this

  + build
  + node_modules
  + server
     + config
     + api
     + database
     + ts-model
     - server.ts
  gitignore
  app.js
  package.json
  tsconfig.ts

My tsconfig.ts file is as follows

{
   "compilerOptions": {
   "module": "none",
   "target": "es2016",
   "outDir": "build",
   "noImplicitAny": true,
   "noImplicitReturns": true,
   "noImplicitThis": true
 },
 "include:": [
 "server/**/*.ts"
 ],
 "exclude": [
 "node_modules"
 ]
}

Issue is whenever i do npm run build, my build folder doesn't maintain folder structure. My build folder should contain build>>server>>foldersInsideServer but it is actually build>>foldersInsideServer

  + build
     + config
     + api
     + database
     + ts-model
     - server.ts

I have seen a behavior that whenever I create another folder called "test" and put empty ts file inside, that time build generates like this

+build
   +server
   +test

But as soon as i delete test folder then it again stops generating server folder but shows folders inside server. How can we solve this issue without creating another folder with empty file

1 Answer 1

1

Add "rootDir": "./" to your tsconfig.json.

From the TypeScript wiki:

--outDir specifies the "root" directory of the output. The compiler needs a "root" directory in the source to mirror into the output directory. If --rootDir is not specified, the compiler will compute one; this is based on a common path calculation, which is the longest common prefix of all your input files. Obviously this changes with adding a new file to the compilation that has a shorter path prefix.

To ensure the output does not change with adding new files specify --rootDir on the command-line or in your tsconfig.json

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.