How do i manage monorepo tsconfig.json to create dist folder in every workspaces folder

73 Views Asked by At

I just create a monorepo with this structure

+ packages
  + packages-A
    + src
    - tsconfig.json
    - package.json
  + packages-B
    + src
    - tsconfig.json
    - package.json
- package.json
- tsconfig.json

I've setup tsconfig.json in rootDir like this:

{
  "exclude": [
    "node_modules/*",
    "example/*"
  ],
  "compilerOptions": {
    "allowJs": true,
    "module": "es6",
    "declaration": true,
    "skipLibCheck": true,
    "noImplicitAny": true,
    "esModuleInterop": true,
    "jsx": "react",
    "lib": [
      "esnext"
    ],
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "strict": true,
    "target": "esnext",
  }
}

and I set tsconfig.json in every nested package folder like this:

{
  "extends": "../../tsconfig.json",
  "include": [
    "src/**/*",
  ],
  "compilerOptions": {
    "outDir": "./dist",
  }
}

with this setup, every time I run tsc, .d.ts generated inside package/**/src folder and all my file in package/**/src got formatted.

I expecting whenever I run tsc, I have a dist folder in package/**/ that created .d.ts, so can someone help me what config should I change to make it work as my expectation?

1

There are 1 best solutions below

0
NadavT On

Try adding this to every package tsconfig and also exclude dist

"compilerOptions": {
    "rootDir": "src",
    "outDir": "dist",
    "composite": true
  },
  "exclude": [
    "dist"
  ]