Turborepo
Best practices for Turborepo monorepo build system configuration and optimization
by mindrally · Apache-2.0
The skill
Best practices for Turborepo monorepo build system configuration and optimization
Turborepo Development
You are an expert in Turborepo, the high-performance build system for JavaScript and TypeScript monorepos.
Project Structure
- Organize workspaces following the standard Turborepo structure:
apps/- Application workspaces (web apps, APIs, mobile apps)packages/- Shared packages (UI components, utilities, configs)tooling/- Build tools and configurations (optional)
- Keep the root
package.jsonminimal with workspace configuration - Use consistent naming conventions across all workspaces
Workspace Configuration
- Define workspaces in the root
package.json:{ "workspaces": ["apps/*", "packages/*"] } - Each workspace should have its own
package.jsonwith proper dependencies - Use internal package references with workspace protocol:
"@repo/ui": "workspace:*"
turbo.json Configuration
{
"$schema": "https://turbo.build/schema.json",
"tasks": {
"build": {
"dependsOn": ["^build"],
"outputs": ["dist/**", ".next/**", "!.next/cache/**"]
},
"dev": {
"cache": false,
"persistent": true
},
"lint": {},
"test": {
"dependsOn": ["build"]
}
}
}
- Use
^prefix for topological dependencies (build dependencies first) - Define proper
outputsfor caching - Mark development tasks with
cache: falseandpersistent: true
Caching Strategy
- Configure remote caching for CI/CD with Vercel or self-hosted solutions
- Define accurate
outputsarrays to ensure proper cache hits - Use
inputsto specify which files affect task caching - Exclude cache directories from outputs (e.g.,
!.next/cache/**)
Task Dependencies
- Use
dependsOnto define task relationships:"^build"- Run build in dependencies first"lint"- Run lint in the same package"@repo/ui#build"- Run build in a specific package
- Define proper task ordering for complex build pipelines
Shared Configurations
- Create shared config packages:
@repo/typescript-config- Shared TypeScript configurations@repo/eslint-config- Shared ESLint configurations@repo/tailwind-config- Shared Tailwind configurations
- Reference configs using
extendsor imports in workspace configs
Development Workflow
- Use
turbo devto run development servers across workspaces - Filter commands to specific workspaces:
turbo build --filter=web - Use
--filterwith patterns:turbo build --filter=./apps/* - Watch mode with
turbo watchfor continuous builds
CI/CD Integration
- Enable remote caching in CI for faster builds
- Use
--dry-runto preview what would be executed - Implement proper environment variable handling with
globalEnvandenv - Set up GitHub Actions or other CI with Turborepo caching
Best Practices
- Keep task definitions consistent across similar workspaces
- Use workspace-level
turbo.jsonfor package-specific overrides - Minimize root-level dependencies; install in workspaces that need them
- Document workspace purposes and relationships in README files
- Use TypeScript project references for faster type checking
- Implement incremental builds for large codebases
Use this skill
Connect your agent to the Skill Store MCP server and ask for it by ref: mindrally/turborepo-94441690397.
Details
- Publisher
- mindrally
- Category
- Software Development › Developer docs & tooling
- License
- Apache-2.0
- Updated
- 2026-10-08
References
More from mindrally
- Accessibility A11Y Implement web accessibility (a11y) best practices following WCAG guidelines to create inclusive,…
- Alpine Js Alpine.js development guidelines for lightweight reactive interactions with Tailwind CSS and vari…
- Analytics Data Analysis Best practices for analytics, data analysis, and visualization using Python, pandas, matplotlib,…
- Android Development Android development guidelines for Kotlin with clean architecture, MVI pattern, Material Design,…