Skip to content

Configure a monorepo package

This guide configures one package in a workspace with tsconfig/monorepo, and references another workspace package so tsc --build compiles them in order.

  1. Add the package to the workspace package you are configuring:

    Terminal window
    pnpm add -D typescript @repobuddy/typescript
  2. Create tsconfig.json in the package. Extend the preset and set the folders:

    {
    "extends": "@repobuddy/typescript/tsconfig/monorepo",
    "compilerOptions": {
    "outDir": "esm",
    "rootDir": "src"
    },
    "include": ["src"]
    }

    The preset sets composite, so every source file must be matched by include.

  3. If the package imports another workspace package, add a references entry with the path to that package’s folder (or to its tsconfig file):

    {
    "references": [
    {
    "path": "../other-package"
    }
    ]
    }

    The referenced package must also have composite on. If it extends tsconfig/monorepo, it does.

  4. Build with tsc --build, which builds referenced projects first:

    Terminal window
    pnpm exec tsc --build
  5. Add *.tsbuildinfo and the output folder to .gitignore. composite turns on incremental, which writes a .tsbuildinfo file.

testcases/build-ts/tsconfig.json in this repository:

{
"extends": "@repobuddy/typescript/tsconfig/monorepo",
"compilerOptions": {
"outDir": "esm",
"rootDir": "src"
},
"include": ["src"],
"references": [
{
"path": "../../packages/typescript"
}
]
}
  1. Run pnpm exec tsc --showConfig. The output includes "composite": true and "module": "node16".
  2. Run pnpm exec tsc --build. It exits with code 0 and writes esm/ with .js, .d.ts, and .map files.
  • If a tool that reads your tsconfig cannot follow an extends array, extend tsconfig/legacy/monorepo instead.
  • In a large solution, add projects/large-project to the extends array so the editor does not load every referenced project at startup.