Summary - tsconfig in depth
- TypeScript course
- Expert
- Lesson 17/35
- 4 min
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.
Practice 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.
Starter code
// buildMonorepo: build sırasını ve alias sayısını verir
// references'a göre topolojik sıra çıkar
// her projenin paths alanındaki alias'ları say
// "core, app | 2" biçiminde yazdırSample 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);Expected output
core, app | 2
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 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 Correct answer
Explanation: 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.
2 Build command
tsc ____ --build
tsc --build --build
Explanation: The --build flag enables build mode; --watch is watch mode, and --check and --emit are not build mode flags.
3 Monorepo skeleton parts
| Term | Meaning |
|---|---|
composite: true |
enables referenceability |
references |
cross-project dependency |
moduleResolution |
resolution strategy |
paths |
alias mappings |