Skip to content

Instantly share code, notes, and snippets.

@jrson83
Forked from khalidx/typescript-monorepo.md
Created December 14, 2022 20:28
Show Gist options
  • Save jrson83/c41b3d40418d7d320a90ff9a8e5700a7 to your computer and use it in GitHub Desktop.
Save jrson83/c41b3d40418d7d320a90ff9a8e5700a7 to your computer and use it in GitHub Desktop.
A simple setup for a TypeScript monorepo.

There are countless guides online for setting up a TypeScript monorepo.

Most rely on external tools like Lerna, Yarn, Turborepo, Yalc, or something else.

Here's a simple, zero-opinion way to get a monorepo going.

First, make a structure like this:

root/
  package-1/
    package.json
    tsconfig.json
  package-2/
    package.json
    tsconfig.json
  package.json

The root/package.json can be empty, with only the following set:

{
  "private": true,
  "workspaces": [
    "package-1",
    "package-2"
  ]
}

Now, assuming package-1 depends on package-2, add this to the tsconfig.json for package-1:

{
  ...
  "references": [
    { "path": "../parser/" }
  ]
}

And add this to the tsconfig.json for package-2:

{
  "compilerOptions": {
     ...
    "composite": true
  }
}

Now, go into into package-1 and run npm install.

Now, you can install package-2 as a dependency, even though it is not publishe to npm! npm install --save package-2

Everything is set up now! Notice, if you change TypeScript in package-2, you don't have to rebuild it or reinstall it. Stuff just works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment