DEV Community

Alex Spinov
Alex Spinov

Posted on

Turborepo Has a Free API That Makes Monorepo Builds 10x Faster

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"]
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Generators: Scaffold New Packages

# Create a new package from template
turbo gen workspace

# Custom generators
turbo gen custom
Enter fullscreen mode Exit fullscreen mode
// 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/**" },
    ],
  });
}
Enter fullscreen mode Exit fullscreen mode

Cache Analysis

# See what's cached
turbo build --summarize

# Dry run — show task graph
turbo build --dry-run

# Graph visualization
turbo build --graph
Enter fullscreen mode Exit fullscreen mode

CI Optimization

# GitHub Actions
- name: Build
  run: turbo build --filter=...[${{ github.event.pull_request.base.sha }}]
  # Only builds packages affected by PR changes!
Enter fullscreen mode Exit fullscreen mode

Manage scraping tool monorepos? My Apify tools are built in monorepo style.

Custom monorepo setup? Email spinov001@gmail.com

Top comments (0)