• Discover
  • Collections
  • Board
  • Create
  • Profile
  • Settings
Paths

Advanced Turborepo Features and Optimizations

Advanced Turborepo Features and Optimizations

2 min read

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, and tsconfig.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 like dev servers, 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 --filter flag (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=debug for verbose output.

  • --dry or --dry-run to see which tasks would run without executing them.

  • --graph to visualize the task graph (output as .dot file).

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.

End of lesson
👏Well done!
Previous Lesson
Setting Up a New Turborepo Project
Next Lesson
Quiz: Implementing and Optimizing with Turborepo

Course Content

0% Complete0/9 Lessons

What is a Monorepo?

Monorepo Best Practices & Tooling Overview

Quiz

Setting Up a New Turborepo Project

Advanced Turborepo Features and Optimizations

Quiz

Course Content

0% Complete0/9 Lessons

What is a Monorepo?

Monorepo Best Practices & Tooling Overview

Quiz

Setting Up a New Turborepo Project

Advanced Turborepo Features and Optimizations

Quiz