TypeScript
Summary - tsconfig in depth
Set up a monorepo skeleton with multi-project references.
Summary: monorepo skeleton
To build a monorepo skeleton you combine four parts: enable build mode with composite: true and incremental: true, declare cross-project dependencies with references, pick a resolution strategy with moduleResolution, and define aliases with paths. Together they yield a scalable, fast-compiling setup.
{
"compilerOptions": {
"composite": true,
"incremental": true,
"moduleResolution": "bundler",
"baseUrl": ".",
"paths": { "@/*": ["src/*"] }
},
"references": [{ "path": "../core" }]
}
This skeleton gives consistency and speed to large codebases.
Exercise Configure the monorepo
Write a buildMonorepo function that derives the build order (topological by references) from a project list and counts total aliases. For a config where app → core and each project has one alias, produce the output core, app | 2.
Show example solution
type ProjectConfig = {
name: string;
references: string[];
paths: Record<string, string[]>;
};
function buildMonorepo(projects: ProjectConfig[]): { order: string[]; aliases: number } {
const order: string[] = [];
const visited = new Set<string>();
function visit(name: string) {
if (visited.has(name)) return;
visited.add(name);
const p = projects.find(x => x.name === name);
if (p) {
for (const ref of p.references) visit(ref);
order.push(name);
}
}
for (const p of projects) visit(p.name);
let aliases = 0;
for (const p of projects) {
aliases += Object.keys(p.paths).length;
}
return { order, aliases };
}
const projects = [
{ name: "app", references: ["core"], paths: { "@app/*": ["src/*"] } },
{ name: "core", references: [], paths: { "@core/*": ["src/*"] } }
];
const result = buildMonorepo(projects);
console.log(result.order.join(", ") + " | " + result.aliases);
Test yourself
-
What should be the setup order for a monorepo skeleton?
- First moduleResolution, then paths, then references, last composite
- First references, then paths, then moduleResolution, last composite
- First paths, then references, then composite, last moduleResolution
- First composite and references, then moduleResolution, last paths
Show answer
First composite and references, then moduleResolution, last paths — First composite and references set up the project skeleton, then the resolution strategy is chosen, and aliases are added last; this order establishes the dependency chain first.
-
Build command
tsc ____ --build
Show answer
tsc --build --build
-
Monorepo skeleton parts
- composite: true
- enables referenceability
- references
- cross-project dependency
- moduleResolution
- resolution strategy
- paths
- alias mappings
Next lesson: Emit options