Turborepo
Overview
Turborepo is a high-performance build system for JavaScript/TypeScript monorepos that intelligently caches task outputs, parallelizes execution across CPU cores, and ensures teams only rebuild what has changed. It integrates with npm, yarn, and pnpm workspaces.
Instructions
- When setting up a monorepo, define tasks in
turbo.json with dependsOn for ordering, use ^ prefix for topological dependencies (e.g., "dependsOn": ["^build"]), and specify outputs for cacheable artifacts.
- When configuring caching, define
outputs arrays for each task (["dist/**", ".next/**"]), list all build-affecting environment variables in env or globalEnv, and set up Remote Cache for cross-developer sharing.
- When filtering workspaces, use
--filter=@app/web to target specific packages, --filter=...[HEAD~1] for changed packages, and turbo run build --graph to visualize the dependency graph.
- When optimizing Docker builds, use
turbo prune --scope=@app/web to generate a minimal Docker context containing only the targeted package and its dependencies.
- When setting up CI/CD, enable Remote Cache for cross-PR cache sharing, use
--dry-run=json for pipeline analysis, and leverage incremental builds that only rebuild packages affected by PR changes.
- When organizing shared packages, create focused internal packages (
@repo/ui, @repo/db, @repo/auth) with shared tsconfig and ESLint configs.
Examples
Example 1: Set up a new Turborepo monorepo
User request: "Initialize a monorepo with a Next.js app and shared UI library"
Actions:
- Set up pnpm workspace with
apps/web and packages/ui directories
- Configure
turbo.json with build, dev, lint, and typecheck tasks
- Define task dependencies and cache outputs for each task
- Create shared
tsconfig base in packages/tsconfig
Output: A monorepo with parallel builds, intelligent caching, and shared configuration.
Example 2: Optimize Docker builds for deployment
User request: "Create a Dockerfile for deploying one service from our Turborepo monorepo"
Actions:
- Run
turbo prune --scope=@app/api to generate minimal context
- Create multi-stage Dockerfile using the pruned output
- Install dependencies and build only the targeted package
- Configure cache mounts for faster rebuilds
Output: A lean Docker image containing only the service and its dependencies, not the full monorepo.
Guidelines
- Always define
outputs for cacheable tasks; use empty outputs: [] for side-effect-only tasks like lint.
- List all environment variables in
env or globalEnv that affect build output.
- Use
^ prefix in dependsOn for tasks that consume dependency outputs (build, typecheck).
- Keep internal packages small and focused:
@repo/ui, @repo/db, @repo/auth.
- Use
turbo prune for Docker builds; never copy the entire monorepo into a container.
- Set up Remote Cache in CI for cross-developer and cross-PR cache sharing.
1---2name: turborepo3description: >-4 Assists with managing JavaScript/TypeScript monorepos using Turborepo. Use when configuring5 build pipelines, setting up caching, pruning workspaces for Docker, or optimizing CI/CD6 for monorepo projects. Trigger words: turborepo, turbo, monorepo, pipeline, workspace,7 remote cache, turbo.json.8license: Apache-2.09compatibility: "Requires Node.js 16+ with npm, yarn, or pnpm"10metadata:11 source: https://skillmd.com/skills/eliferjunior/turborepo12 author: terminal-skills13 version: "1.0.0"14 category: development15 tags: ["turborepo", "monorepo", "build-system", "caching", "ci-cd"]16---1718# Turborepo1920## Overview2122Turborepo is a high-performance build system for JavaScript/TypeScript monorepos that intelligently caches task outputs, parallelizes execution across CPU cores, and ensures teams only rebuild what has changed. It integrates with npm, yarn, and pnpm workspaces.2324## Instructions2526- When setting up a monorepo, define tasks in `turbo.json` with `dependsOn` for ordering, use `^` prefix for topological dependencies (e.g., `"dependsOn": ["^build"]`), and specify `outputs` for cacheable artifacts.27- When configuring caching, define `outputs` arrays for each task (`["dist/**", ".next/**"]`), list all build-affecting environment variables in `env` or `globalEnv`, and set up Remote Cache for cross-developer sharing.28- When filtering workspaces, use `--filter=@app/web` to target specific packages, `--filter=...[HEAD~1]` for changed packages, and `turbo run build --graph` to visualize the dependency graph.29- When optimizing Docker builds, use `turbo prune --scope=@app/web` to generate a minimal Docker context containing only the targeted package and its dependencies.30- When setting up CI/CD, enable Remote Cache for cross-PR cache sharing, use `--dry-run=json` for pipeline analysis, and leverage incremental builds that only rebuild packages affected by PR changes.31- When organizing shared packages, create focused internal packages (`@repo/ui`, `@repo/db`, `@repo/auth`) with shared `tsconfig` and ESLint configs.3233## Examples3435### Example 1: Set up a new Turborepo monorepo3637**User request:** "Initialize a monorepo with a Next.js app and shared UI library"3839**Actions:**401. Set up pnpm workspace with `apps/web` and `packages/ui` directories412. Configure `turbo.json` with `build`, `dev`, `lint`, and `typecheck` tasks423. Define task dependencies and cache outputs for each task434. Create shared `tsconfig` base in `packages/tsconfig`4445**Output:** A monorepo with parallel builds, intelligent caching, and shared configuration.4647### Example 2: Optimize Docker builds for deployment4849**User request:** "Create a Dockerfile for deploying one service from our Turborepo monorepo"5051**Actions:**521. Run `turbo prune --scope=@app/api` to generate minimal context532. Create multi-stage Dockerfile using the pruned output543. Install dependencies and build only the targeted package554. Configure cache mounts for faster rebuilds5657**Output:** A lean Docker image containing only the service and its dependencies, not the full monorepo.5859## Guidelines6061- Always define `outputs` for cacheable tasks; use empty `outputs: []` for side-effect-only tasks like `lint`.62- List all environment variables in `env` or `globalEnv` that affect build output.63- Use `^` prefix in `dependsOn` for tasks that consume dependency outputs (build, typecheck).64- Keep internal packages small and focused: `@repo/ui`, `@repo/db`, `@repo/auth`.65- Use `turbo prune` for Docker builds; never copy the entire monorepo into a container.66- Set up Remote Cache in CI for cross-developer and cross-PR cache sharing.