Turborepo is the monorepo build system from Vercel. Its caching and task pipeline API eliminates redundant work across packages.
turbo.json: Define Your Pipeline
{
"$schema": "https://turbo.build/schema.json",
"globalDependencies": [".env"],
"tasks": {
"build": {
"dependsOn": ["^build"],
"outputs": ["dist/**", ".next/**"],
"env": ["NODE_ENV", "API_URL"]
},
"test": {
"dependsOn": ["build"],
"inputs": ["src/**/*.ts", "tests/**/*.ts"]
},
"lint": {},
"dev": {
"cache": false,
"persistent": true
},
"typecheck": {
"dependsOn": ["^build"]
}
}
}
Task Graph: Parallel Execution
# Build all packages in dependency order
turbo build
# Run tests across all packages
turbo test
# Lint and typecheck in parallel
turbo lint typecheck
# Filter to specific packages
turbo build --filter=@myapp/web
turbo build --filter=@myapp/web...
turbo test --filter=...@myapp/shared
Remote Caching: Share Build Artifacts
# Enable remote caching (Vercel)
turbo login
turbo link
# Now builds are cached across your team and CI
# Developer A builds → cache uploaded → Developer B gets instant build
Monorepo Structure
my-monorepo/
turbo.json
package.json
apps/
web/ # Next.js app
package.json
api/ # Express API
package.json
mobile/ # React Native
package.json
packages/
ui/ # Shared React components
package.json
shared/ # Shared utilities
package.json
db/ # Prisma schema + client
package.json
config-eslint/ # Shared ESLint config
package.json
config-ts/ # Shared tsconfig
package.json
Generators: Scaffold New Packages
# Create a new package from template
turbo gen workspace
# Custom generators
turbo gen custom
// turbo/generators/config.ts
import { PlopTypes } from "@turbo/gen";
export default function generator(plop: PlopTypes.NodePlopAPI) {
plop.setGenerator("package", {
description: "Create a new shared package",
prompts: [{ type: "input", name: "name", message: "Package name?" }],
actions: [
{ type: "addMany", destination: "packages/{{name}}", base: "templates/package", templateFiles: "templates/package/**" },
],
});
}
Cache Analysis
# See what's cached
turbo build --summarize
# Dry run — show task graph
turbo build --dry-run
# Graph visualization
turbo build --graph
CI Optimization
# GitHub Actions
- name: Build
run: turbo build --filter=...[${{ github.event.pull_request.base.sha }}]
# Only builds packages affected by PR changes!
Manage scraping tool monorepos? My Apify tools are built in monorepo style.
Custom monorepo setup? Email spinov001@gmail.com
Top comments (0)