提示:本网站现在为维护调试状态

Monorepo Toolchain: Turborepo + pnpm workspace

Choyeon
Choyeon
Sep 19, 2026 1 min read 429 Views
331 words 2,179 chars Updated Nov 8, 2026
Monorepo Toolchain: Turborepo + pnpm workspace
Table of contents

As projects split from one package to many, separate repos cause divergent deps, painful code reuse, and fragmented releases. Monorepo solves these with tooling. Turborepo + pnpm delivers the best combination today.

pnpm workspace Dependency Management

Declare apps/* packages/* structure in pnpm-workspace.yaml. Root pnpm install uses hard-links so the same dep is shared across packages with strictly isolated node_modules against phantom dependencies. workspace: protocol references internal packages instantly without publishing.

# pnpm-workspace.yaml
packages:
  - 'apps/*'
  - 'packages/*'
  - 'tooling/*'

# turbo.json
{
  "$schema": "https://turbo.build/schema.json",
  "pipeline": {
    "build": {
      "dependsOn": ["^build"],
      "outputs": [".next/**", "dist/**"],
      "cache": true
    },
    "typecheck": { "dependsOn": ["^build"], "outputs": [] },
    "lint": { "dependsOn": ["^build"], "outputs": [] },
    "test": {
      "dependsOn": ["^build"],
      "outputs": ["coverage/**"],
      "inputs": ["**/*.test.*", "jest.config.*"]
    },
    "dev": { "cache": false, "persistent": true }
  }
}

# root package.json
{
  "name": "my-monorepo",
  "private": true,
  "packageManager": "pnpm@9.0.0",
  "scripts": {
    "build": "turbo build",
    "typecheck": "turbo typecheck",
    "test": "turbo test",
    "dev": "turbo dev",
    "release": "changeset version && changeset publish"
  },
  "devDependencies": {
    "turbo": "^2.0.0",
    "@changesets/cli": "^2.27.0",
    "typescript": "^5.4.0"
  }
}

# packages/ui/package.json
{
  "name": "@company/ui",
  "version": "1.2.0",
  "type": "module",
  "main": "./dist/index.js",
  "types": "./dist/index.d.ts",
  "exports": {
    ".": { "types": "./dist/index.d.ts", "import": "./dist/index.js" },
    "./styles.css": "./dist/styles.css"
  },
  "sideEffects": false
}

Turborepo Incremental Builds and Caching

turbo.json declares task DAG: child build depends on upstream ^build, topologically sorted automatically. Per-task input hash hits local or remote cache to skip entire builds - CI speedup typically 5-20x.

Dimension Manual repos Lerna + yarn pnpm + Turborepo pnpm + Nx
Deduped deps Per-repo copies Medium hoisting Hardlink shared Same as Turborepo
Task orchestration Scripts Weak lerna run DAG smart cache targetDefaults
Remote cache None Paid enterprise Self-host S3/Vercel free Nx Cloud free tier
Phantom dep risk Low High Very Low Very Low

Best Practices

Standardize internal packages on @scope/pkg naming. Use Changesets for versioning/changelogs. Never cross-package relative imports. Wire remote cache to team S3 bucket so every CI run shares cache globally.

X微博Telegram

About the author

Poll

你最希望 Rosetta 优先加入哪项功能?

社区投票(演示数据,可后台删除)

Comments (3)

0 / 3000
云端漫步
云端漫步cloud-notes.cloudSep 24, 2026

补充一个小技巧:用 kubectl 的 kubectx + kubens 插件切换集群和命名空间超级方便,谁用谁知道。

游戏策划阿哲
游戏策划阿哲Sep 24, 2026

按照你的教程搭建完 Prometheus + Grafana 监控后,节点 exporter 的数据采集延迟挺高的,这个正常吗?

机器学习萌新
机器学习萌新Sep 24, 2026

看到你那个 Nginx 配置示例,有个安全问题:server_tokens 建议关掉,不然会暴露 Nginx 版本号给攻击者。

Related posts

CI/CD Pipeline Design: GitHub Actions + Cache + Matrix Build

CI/CD Pipeline Design: GitHub Actions + Cache + Matrix Build

Production GitHub Actions pipeline from scratch: npm/pip cache, multi-version Node/Python matrix builds, Docker layer caching, Lint+Test+Build+Publish stages, conditional execution, env matrix, failure retry, and release gating best practices. Complete workflow YAML included.

1 min read
Advanced Git Workflows

Advanced Git Workflows

Master advanced Git: Interactive Rebase for history cleanup, Cherry-pick selective commit porting, Bisect binary-search bug regression hunting, reflog and reset recovery.

1 min read
Docker Compose Production Deployment Guide

Docker Compose Production Deployment Guide

Deep dive into Docker Compose production best practices: multi-stage builds, health checks, resource limits, logging, network isolation, and secrets management for reliable container deployments.

1 min read
Tailwind CSS v4: Zero-config + CSS-native Variables

Tailwind CSS v4: Zero-config + CSS-native Variables

Tailwind CSS v4 is an architectural upgrade: goodbye tailwind.config.js, declare design tokens in @theme blocks inside native CSS files. Single @import "tailwindcss" entry replaces postcss.config; built-in CSS vars, native container queries, oxc engine 10-40x faster, simplified color functions.

1 min read
PWA Offline App in Practice: Service Worker + IndexedDB + Background Sync

PWA Offline App in Practice: Service Worker + IndexedDB + Background Sync

Build installable, offline-first Progressive Web Apps: Service Worker caching strategies (Cache First, Stale-While-Revalidate), IndexedDB wrapper for structured local data, Background Sync queue that replays offline operations when network returns. Full TypeScript code included.

1 min read
GraphQL vs REST: 7-Dimension Deep Comparison

GraphQL vs REST: 7-Dimension Deep Comparison

End the API style debate: compared across 7 dimensions - network efficiency, DX, evolution cost, caching, type-safety, security risks, ecosystem - with clear decision tree and hybrid architecture patterns.

1 min read