Monorepo Management (Nx/Turborepo) Cheat Sheet
Covers workspace structure, task pipelines, remote caching, affected-project detection, and dependency graphs for Nx and Turborepo.
Turborepo `turbo.json` Pipeline
Define task dependencies and cache behavior once; Turborepo topologically orders and caches runs.
{ "$schema": "https://turbo.build/schema.json", "tasks": { "build": { "dependsOn": ["^build"], "outputs": ["dist/**", ".next/**"] }, "test": { "dependsOn": ["build"], "outputs": [] }, "lint": { "outputs": [] }, "dev": { "cache": false, "persistent": true } }}
Turborepo CLI Commands
Run tasks across the whole workspace or scoped to changed packages.
# run build in every package that has a build script, respecting dependsOn orderturbo run build# only packages affected since the given git refturbo run test --filter=...[origin/main]# run for one package and its dependentsturbo run build --filter=@acme/ui...# remote caching (Vercel by default, or self-hosted)turbo loginturbo linkturbo run build --remote-only
Nx `nx.json` & Project Graph
Nx infers a project graph from imports and configures cacheable target defaults centrally.
{ "targetDefaults": { "build": { "dependsOn": ["^build"], "cache": true, "inputs": ["production", "^production"] }, "test": { "cache": true, "inputs": ["default", "^production"] } }, "namedInputs": { "default": ["{projectRoot}/**/*"], "production": ["!{projectRoot}/**/*.spec.ts"] }}
Nx CLI Commands
Nx's `affected` commands use the project graph to run only what changed.
# visualize the dependency graph in the browsernx graph# run a target for one projectnx build my-app# run a target for every project affected by uncommitted/branch changesnx affected -t build test lint --base=main# run with Nx Cloud distributed task execution + remote cachingnx affected -t build --parallel=5
Nx vs Turborepo Quick Comparison
Both solve caching/orchestration; they differ in scope and opinionation.
- Turborepo- lightweight task runner/cache, config in turbo.json, framework-agnostic, minimal opinions
- Nx- full toolkit: generators, plugins, project graph visualization, code-owned migrations
- Remote caching- both support it (Vercel Remote Cache / Nx Cloud or self-hosted alternatives)
- Affected detection- turbo uses --filter=...[ref]; Nx uses `nx affected` with --base/--head
- Task pipeline config- turbo.json `tasks` vs nx.json `targetDefaults`, both express dependsOn graphs
- Best fit- Turborepo for simpler JS/TS monorepos; Nx for large multi-framework orgs wanting generators/enforced boundaries
Always scope CI to affected/changed projects (`turbo run test --filter=...[origin/main]` or `nx affected -t test --base=origin/main`) instead of running every task on every push — this is the single biggest lever for keeping monorepo CI times flat as the repo grows.
Explore Topics
Professional Web Designing Services
- Responsive Websites
- E-commerce Solutions
- SEO Friendly Design
- Fast & Secure
- Support & Maintenance