Overview
This lesson deepens your understanding of Turborepo by exploring its fundamental features that enable fast and efficient monorepo builds. We will focus on how Turborepo leverages caching and task pipelines.
Key Points
-
Task Pipelines: Turborepo defines relationships between tasks (e.g.,
build,test,lint) across different workspaces. This allows it to understand which tasks can run in parallel and which depend on others. -
Local Caching: Turborepo caches the output of tasks locally. If a task has been run before with the same inputs, Turborepo can restore the cached output instead of re-running the task, saving significant time.
-
Remote Caching: For teams, Turborepo can integrate with a remote cache (like Vercel's Turborepo Remote Cache) to share cached build artifacts across different machines and CI/CD environments.
-
Workspace Concept: Turborepo operates on the concept of workspaces, which are individual projects (apps or packages) within the monorepo defined in the root
package.json. -
turbo.jsonConfiguration: This file at the root of your monorepo is where you define task pipelines, caching rules, and dependencies, telling Turborepo how to run your project's tasks.
Quick Example
Here's a basic turbo.json configuration demonstrating task pipelines:
json{ "$schema": "https://turbo.build/schema.json", "pipeline": { "build": { "dependsOn": ```json ["^build"]
, "outputs":
json[".next/**", "dist/**"]
},
"lint": {},
"dev": {
"cache": false,
"persistent": true
}
}
}
## Summary
Turborepo's power lies in its intelligent caching and pipeline orchestration. By configuring `turbo.json`, developers can significantly reduce build times and ensure consistency across all projects in the monorepo.