Turborepo 2.x: Fast Monorepo Builds With Remote Caching
Turborepo's task graph and remote cache cut monorepo build times dramatically - here is how to set it up with pnpm workspaces, Docker, and self-hosted caching.
Running pnpm build in a monorepo with 20 packages rebuilds everything every time. Turborepo understands your task dependency graph, caches outputs by input hash, and skips tasks whose inputs have not changed - locally and in CI.
Initial Setup
pnpm add -D turbo -w # -w installs to workspace root
# Or scaffold a new monorepo
npx create-turbo@latest
# Use in CI
TURBO_API=http://your-cache-server:3000 TURBO_TOKEN=your-token TURBO_TEAM=your-team turbo build
Pruning for Docker Layers
turbo prune creates a minimal subset of your monorepo containing only the packages needed for a specific app - ideal for Docker:
FROM node:22-alpine AS pruner
WORKDIR /app
RUN pnpm add -g turbo
COPY . .
RUN turbo prune web --docker
FROM node:22-alpine AS installer
WORKDIR /app
COPY --from=pruner /app/out/json/ .
COPY --from=pruner /app/out/pnpm-lock.yaml ./pnpm-lock.yaml
RUN pnpm install --frozen-lockfile
FROM node:22-alpine AS builder
WORKDIR /app
COPY --from=installer /app .
COPY --from=pruner /app/out/full/ .
RUN turbo build --filter=web
FROM node:22-alpine AS runner
COPY --from=builder /app/apps/web/.next/standalone ./
CMD ["node", "server.js"]
Filtering for Affected Packages
Only build packages affected by changes on the current branch:
# Build only changed packages and their dependents
turbo build --filter="...[origin/main]"
# Build a specific app and all its dependencies
turbo build --filter=web...
Turborepo vs Nx
Feature
Turborepo
Nx
Config complexity
Simple JSON
More complex
Plugin ecosystem
Smaller
Larger
Code generation
No
Yes
Affected detection
Git-based
Git + dep graph
Remote cache
Vercel or self-hosted
Nx Cloud or self-hosted
Turborepo is better for teams that want minimal config and are already on pnpm workspaces. Nx is better for large enterprise monorepos that need code generation and extensive scaffolding.
Practical deep-dives on LLMs, developer tools, and AI engineering. No filler. Unsubscribe any time.
// written byFIG. AUTH-01
530
Mahmudul Haque Qudrati
CEO & ML Engineer
CEO and ML Engineer at Pristren. Builds AI-powered software for teams and writes about machine learning, LLMs, developer tools, and practical AI applications.
Open Code Review – An AI-powered code review CLI tool: A Practical Overview
Open Code Review is an open-source CLI tool from Alibaba that uses AI to review code changes. It runs locally, supports multiple LLMs, and costs about $0.01 per review. Here's a practical breakdown.