Turborepo expert guidance. Use when setting up or optimizing monorepo builds, configuring task caching, remote caching, parallel execution, or the --affected flag for incremental CI.
You are an expert in Turborepo v2.8 — "the build system for agentic coding" — a high-performance build system for JavaScript/TypeScript monorepos, built by Vercel with a Rust-powered core.
--affected flag runs only changed packages + dependentsturbo devtools (2.8+)turbo.json from any package, not just root (2.7+)turbo docsnpx create-turbo@latest
# or add to existing monorepo:
npm install turbo --save-dev
# upgrade existing Turborepo:
npx @turbo/codemod migrate
The turbo.json file defines your task dependency graph. Here are comprehensive examples:
{
"$schema": "https://turborepo.dev/schema.json",
"tasks": {
"build": {
"description": "Compile TypeScript and bundle the application",
"dependsOn": ["^build"],
"outputs": [".next/**", "dist/**"]
},
"test": {
"description": "Run the test suite",
"dependsOn": ["build"]
},
"lint": {
"description": "Lint source files"
},
"dev": {
"cache": false,
"persistent": true
}
}
}
{
"$schema": "https://turborepo.dev/schema.json",
"globalDependencies": [".env"],
"globalEnv": ["CI", "NODE_ENV"],
"tasks": {
"build": {
"dependsOn": ["^build"],
"outputs": [".next/**", "dist/**"],
"env": ["DATABASE_URL", "NEXT_PUBLIC_API_URL"],
"inputs": ["src/**", "package.json", "tsconfig.json"]
},
"test": {
"dependsOn": ["build"],
"outputs": ["coverage/**"],
"env": ["TEST_DATABASE_URL"]
},
"test:unit": {
"dependsOn": [],
"outputs": ["coverage/**"]
},
"lint": {
"inputs": ["src/**", ".eslintrc.*"]
},
"typecheck": {
"dependsOn": ["^build"],
"inputs": ["src/**", "tsconfig.json"]
},
"db:generate": {
"cache": false
},
"dev": {
"cache": false,
"persistent": true
},
"clean": {
"cache": false
}
}
}
dependsOn: ["^build"] — Run build in dependencies first (^ = topological)dependsOn: ["build"] — Run build in the same package first (no ^)outputs — Files to cache (build artifacts)inputs — Files that affect the task hash (default: all non-gitignored files)env — Environment variables that affect the task hashcache: false — Skip caching (for dev servers, codegen)persistent: true — Long-running tasks (dev servers)globalDependencies — Files that invalidate all task caches when changedglobalEnv — Env vars that invalidate all task caches when changedRun tasks in specific packages or subsets of your monorepo:
# Single package
turbo build --filter=web
# Package and its dependencies
turbo build --filter=web...
# Package and its dependents (what depends on it)
turbo build --filter=...ui
# Multiple packages
turbo build --filter=web --filter=api
# By directory
turbo build --filter=./apps/*
# Packages that changed since main
turbo build --filter=[main]
# Combine: changed packages and their dependents
turbo build --filter=...[main]
# Exclude a package
turbo build --filter=!docs
# Packages matching a pattern
turbo build --filter=@myorg/*
| Pattern | Meaning |
|---|---|
web | Only the web package |
web... | web and all its dependencies |
...web | web and all its dependents |
...web... | web, its dependencies, and its dependents |
./apps/* | All packages in the apps/ directory |
[main] | Packages changed since main branch |
{./apps/web}[main] | web only if it changed since main |
!docs | Exclude the docs package |