Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Configure and optimize Turborepo monorepo build pipelines with correct task structure, caching, and CI setup.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/configuration/RULE.md
1# turbo.json Configuration Overview23Configuration reference for Turborepo. Full docs: https://turborepo.dev/docs/reference/configuration45## File Location67Root `turbo.json` lives at repo root, sibling to root `package.json`:89```10my-monorepo/11├── turbo.json # Root configuration12├── package.json13└── packages/14└── web/15├── turbo.json # Package Configuration (optional)16└── package.json17```1819## Always Prefer Package Tasks Over Root Tasks2021**Always use package tasks. Only use Root Tasks if you cannot succeed with package tasks.**2223Package tasks enable parallelization, individual caching, and filtering. Define scripts in each package's `package.json`:2425```json26// packages/web/package.json27{28"scripts": {29"build": "next build",30"lint": "eslint .",31"test": "vitest",32"typecheck": "tsc --noEmit"33}34}3536// packages/api/package.json37{38"scripts": {39"build": "tsc",40"lint": "eslint .",41"test": "vitest",42"typecheck": "tsc --noEmit"43}44}45```4647```json48// Root package.json - delegates to turbo49{50"scripts": {51"build": "turbo run build",52"lint": "turbo run lint",53"test": "turbo run test",54"typecheck": "turbo run typecheck"55}56}57```5859When you run `turbo run lint`, Turborepo finds all packages with a `lint` script and runs them **in parallel**.6061**Root Tasks are a fallback**, not the default. Only use them for tasks that truly cannot run per-package (e.g., repo-level CI scripts, workspace-wide config generation).6263```json64// AVOID: Task logic in root defeats parallelization65{66"scripts": {67"lint": "eslint apps/web && eslint apps/api && eslint packages/ui"68}69}70```7172## Basic Structure7374```json75{76"$schema": "https://v2-9-12.turborepo.dev/schema.json",77"globalEnv": ["CI"],78"globalDependencies": ["tsconfig.json"],79"tasks": {80"build": {81"dependsOn": ["^build"],82"outputs": ["dist/**"]83},84"dev": {85"cache": false,86"persistent": true87}88}89}90```9192The `$schema` key enables IDE autocompletion and validation.9394### With `futureFlags.globalConfiguration`9596When the `globalConfiguration` future flag is enabled, global options move under a `global` key with cleaner names:9798```json99{100"$schema": "https://v2-9-12.turborepo.dev/schema.json",101"futureFlags": { "globalConfiguration": true },102"global": {103"inputs": ["tsconfig.json"],104"env": ["CI"],105"ui": "tui"106},107"tasks": {108"build": {109"dependsOn": ["^build"],110"outputs": ["dist/**"]111}112}113}114```115116See the [global options reference](./global-options.md) for the full rename mapping and behavior changes.117118## Configuration Sections119120**Global options** - Settings affecting all tasks:121122- Without flag: `globalEnv`, `globalDependencies`, `globalPassThroughEnv`, `cacheDir`, `daemon`, `envMode`, `ui`, `remoteCache`123- With `globalConfiguration` flag: all of the above move under the `global` key (see [global options](./global-options.md))124125**Task definitions** - Per-task settings in `tasks` object:126127- `dependsOn`, `outputs`, `inputs`, `env`128- `cache`, `persistent`, `interactive`, `outputLogs`129130## Package Configurations131132Use `turbo.json` in individual packages to override root settings:133134```json135// packages/web/turbo.json136{137"extends": ["//"],138"tasks": {139"build": {140"outputs": [".next/**", "!.next/cache/**"]141}142}143}144```145146The `"extends": ["//"]` is required - it references the root configuration.147148**When to use Package Configurations:**149150- Framework-specific outputs (Next.js, Vite, etc.)151- Package-specific env vars152- Different caching rules for specific packages153- Keeping framework config close to the framework code154155### Extending from Other Packages156157You can extend from config packages instead of just root:158159```json160// packages/web/turbo.json161{162"extends": ["//", "@repo/turbo-config"]163}164```165166### Adding to Inherited Arrays with `$TURBO_EXTENDS$`167168By default, array fields in Package Configurations **replace** root values. Use `$TURBO_EXTENDS$` to **append** instead:169170```json171// Root turbo.json172{173"tasks": {174"build": {175"outputs": ["dist/**"]176}177}178}179```180181```json182// packages/web/turbo.json183{184"extends": ["//"],185"tasks": {186"build": {187// Inherits "dist/**" from root, adds ".next/**"188"outputs": ["$TURBO_EXTENDS$", ".next/**", "!.next/cache/**"]189}190}191}192```193194Without `$TURBO_EXTENDS$`, outputs would only be `[".next/**", "!.next/cache/**"]`.195196**Works with:**197198- `dependsOn`199- `env`200- `inputs`201- `outputs`202- `passThroughEnv`203- `with`204205### Excluding Tasks from Packages206207Use `extends: false` to exclude a task from a package:208209```json210// packages/ui/turbo.json211{212"extends": ["//"],213"tasks": {214"e2e": {215"extends": false // UI package doesn't have e2e tests216}217}218}219```220221## `turbo.jsonc` for Comments222223Use `turbo.jsonc` extension to add comments with IDE support:224225```jsonc226// turbo.jsonc227{228"tasks": {229"build": {230// Next.js outputs231"outputs": [".next/**", "!.next/cache/**"]232}233}234}235```236