turborepo
Original:🇺🇸 English
Translated
Best practices for Turborepo monorepo build system configuration and optimization
16installs
Sourcemindrally/skills
Added on
NPX Install
npx skill4agent add mindrally/skills turborepoTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →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:
- - Application workspaces (web apps, APIs, mobile apps)
apps/ - - Shared packages (UI components, utilities, configs)
packages/ - - Build tools and configurations (optional)
tooling/
- Keep the root minimal with workspace configuration
package.json - Use consistent naming conventions across all workspaces
Workspace Configuration
- Define workspaces in the root :
package.jsonjson{ "workspaces": ["apps/*", "packages/*"] } - Each workspace should have its own with proper dependencies
package.json - Use internal package references with workspace protocol:
"@repo/ui": "workspace:*"
turbo.json Configuration
json
{
"$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 for caching
outputs - Mark development tasks with and
cache: falsepersistent: true
Caching Strategy
- Configure remote caching for CI/CD with Vercel or self-hosted solutions
- Define accurate arrays to ensure proper cache hits
outputs - Use to specify which files affect task caching
inputs - Exclude cache directories from outputs (e.g., )
!.next/cache/**
Task Dependencies
- Use to define task relationships:
dependsOn- - Run build in dependencies first
"^build" - - Run lint in the same package
"lint" - - Run build in a specific package
"@repo/ui#build"
- Define proper task ordering for complex build pipelines
Shared Configurations
- Create shared config packages:
- - Shared TypeScript configurations
@repo/typescript-config - - Shared ESLint configurations
@repo/eslint-config - - Shared Tailwind configurations
@repo/tailwind-config
- Reference configs using or imports in workspace configs
extends
Development Workflow
- Use to run development servers across workspaces
turbo dev - Filter commands to specific workspaces:
turbo build --filter=web - Use with patterns:
--filterturbo build --filter=./apps/* - Watch mode with for continuous builds
turbo watch
CI/CD Integration
- Enable remote caching in CI for faster builds
- Use to preview what would be executed
--dry-run - Implement proper environment variable handling with and
globalEnvenv - Set up GitHub Actions or other CI with Turborepo caching
Best Practices
- Keep task definitions consistent across similar workspaces
- Use workspace-level for package-specific overrides
turbo.json - 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