Turborepo makes monorepo development fast with intelligent task scheduling and caching.
Setup
npx create-turbo@latest
Project Structure
my-turborepo/
├── apps/
│ ├── web/
│ └── docs/
├── packages/
│ ├── ui/
│ └── config/
├── turbo.json
└── package.json
Configuration
{
"$schema": "https://turbo.build/schema.json",
"pipeline": {
"build": {
"dependsOn": ["^build"],
"outputs": ["dist/**", ".next/**"]
},
"lint": {},
"dev": {
"cache": false,
"persistent": true
}
}
}
Running Tasks
# Run build for all packages
turbo build
# Run dev for specific app
turbo dev --filter=web
# Run lint in parallel
turbo lint
Remote Caching
# Login to Vercel for remote caching
turbo login
# Link to remote cache
turbo link
Shared Packages
// packages/ui/src/Button.tsx
export function Button({ children, onClick }) {
return (
<button onClick={onClick} className="btn">
{children}
</button>
);
}
// apps/web/src/page.tsx
import { Button } from '@repo/ui';
export default function Page() {
return <Button onClick={() => alert('Hi!')}>Click me</Button>;
}
Benefits
- Intelligent caching - Never rebuild unchanged code
- Parallel execution - Run tasks concurrently
- Remote caching - Share cache across team
- Incremental builds - Only rebuild what changed
- Task orchestration - Respects dependencies
Posted ondevopswith tags: