Overview
Beyond basic setup, Turborepo offers a rich set of features for fine-tuning performance and enhancing developer workflows. This lesson explores advanced configurations within turbo.json, including sophisticated pipeline definitions, input/output control, task filtering, and integration with remote caching providers. Mastering these features allows for maximum optimization and scalability of your monorepo.
Key Points
-
Advanced Pipeline Configuration (
turbo.json): -
dependsOn: More granular control over task dependencies, including^for package dependencies and~for immediate local dependencies. -
outputs: Precisely define cacheable artifacts (e.g.,["dist/**", ".next/**", "coverage/"]). -
inputs: Specify which files should trigger a cache bust. Default includes source files,package.json, andtsconfig.json. You can add custom inputs. -
env: Declare environment variables that affect a task's output and should be included in its cache key. -
persistent: For long-running processes likedevservers, keeps the task running after its dependencies complete. -
cache: Explicitly enable/disable caching for specific tasks. -
Filtering Tasks:
-
Run tasks only on specific projects using the
--filterflag (e.g.,turbo run build --filter=web). -
Filter by changes:
turbo run build --filter=[HEAD^1...HEAD]to only build changed projects. -
Remote Caching Providers:
-
Configure remote caching to share artifacts across your team and CI.
-
Vercel Artifacts: Easiest integration for Vercel users; requires linking to a Vercel team.
-
Other providers can be used via custom cache implementations or cloud storage.
-
Debugging and Monitoring:
-
TURBO_LOG_LEVEL=debugfor verbose output. -
--dryor--dry-runto see which tasks would run without executing them. -
--graphto visualize the task graph (output as.dotfile).
Quick Example
More advanced turbo.json pipeline configuration.
json{ "$schema": "https://turbo.build/schema.json", "pipeline": { "build": { "dependsOn": ["^build"], "outputs": ["dist/**", ".next/**", "build/**"], "inputs": ["src/**/*.ts", "src/**/*.tsx", "package.json", "tsconfig.json"], "env": ["NODE_ENV"] }, "deploy": { "dependsOn": ["build"], "cache": false } } }
Summary
Turborepo provides a powerful and flexible configuration system to finely control caching, dependencies, and execution behavior. By leveraging advanced pipeline definitions, task filtering, and remote caching, developers can significantly optimize monorepo performance, ensuring fast feedback loops and efficient CI/CD processes.