Why Turborepo
Turborepo by Vercel makes monorepo builds fast. It caches task outputs, runs tasks in parallel, and only rebuilds what changed. Used by Vercel, Netflix, and Shopify.
Setup
npx create-turbo@latest my-monorepo
cd my-monorepo
turbo.json
{
"tasks": {
"build": {
"dependsOn": ["^build"],
"outputs": ["dist/**", ".next/**"]
},
"test": {
"dependsOn": ["build"]
},
"lint": {},
"dev": {
"cache": false,
"persistent": true
}
}
}
Run Tasks
# Build all packages
turbo build
# Test only changed packages
turbo test --filter=...[HEAD~1]
# Run specific package
turbo build --filter=@myorg/web
# Dev mode
turbo dev
Remote Caching
# Login to Vercel (free tier)
npx turbo login
npx turbo link
# Now builds are cached remotely
turbo build # Cache miss: 45s
turbo build # Cache hit: 0.5s (even on CI!)
Monorepo Structure
my-monorepo/
apps/
web/ # Next.js app
api/ # Express API
mobile/ # React Native
packages/
ui/ # Shared components
config/ # Shared configs
utils/ # Shared utilities
turbo.json
package.json
Key Features
- Incremental builds — only rebuild what changed
- Remote caching — share cache across team and CI
- Parallel execution — tasks run concurrently when possible
- Task pipelines — define dependencies between tasks
- Pruned subsets — deploy only the packages you need
- Zero config — works with npm, yarn, pnpm
Resources
Need to extract monorepo data, build metrics, or dependency graphs? Check out my Apify tools or email spinov001@gmail.com for custom solutions.
Top comments (0)