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

Monorepo ツールチェーン:Turborepo + pnpm workspace

Choyeon
Choyeon
2026年9月19日 1 分で読了 432 閲覧
331 字 2,179 文字 更新日 2026年11月8日
Monorepo ツールチェーン:Turborepo + pnpm workspace
目次

Monorepo Toolchain: Turborepo + pnpm workspace

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

筆者について

投票

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

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

コメント (3)

0 / 3000
云端漫步
云端漫步cloud-notes.cloud2026年9月24日

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

游戏策划阿哲
游戏策划阿哲2026年9月24日

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

机器学习萌新
机器学习萌新2026年9月24日

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

関連記事

CI/CD パイプライン設計:GitHub Actions + Cache + Matrix Build

CI/CD パイプライン設計:GitHub Actions + Cache + Matrix Build

本番級GitHub Actionsパイプライン設計:npm/pipキャッシュ、マルチバージョンNode/Python Matrix並列ビルド、Dockerレイヤーキャッシュ、Lint/Test/Build/Publish段階化、条件実行、環境マトリクス、失敗リトライとリリースゲートベストプラクティス。完全ワークフロー付き。

1 分で読了
Git 高度なワークフロー

Git 高度なワークフロー

Git上級操作:Interactive Rebase、Cherry-pick、Bisectによるバグ特定、reflogとresetによる誤操作からの復旧。

1 分で読了
Docker Compose 本番デプロイ実践

Docker Compose 本番デプロイ実践

Docker Composeの本番環境ベストプラクティス:マルチステージビルド、ヘルスチェック、リソース制限、ログ設定、ネットワーク分離、シークレット管理を解説。

1 分で読了
Tailwind CSS v4 新機能:Zero-config + CSS ネイティブ変数

Tailwind CSS v4 新機能:Zero-config + CSS ネイティブ変数

Tailwind CSS v4はアーキテクチャ級アップデート:tailwind.config.js を廃止し、ネイティブCSS内の@themeブロックでデザイントークン宣言。@import "tailwindcss" 単一エントリでpostcss設定不要。CSS変数内蔵、Container Queriesネイティブ対応、oxcエンジンで10-40倍高速化、カラー関数簡略化。

1 分で読了
PWA オフラインアプリ実践:Service Worker + IndexedDB + Background Sync

PWA オフラインアプリ実践:Service Worker + IndexedDB + Background Sync

インストール可能・オフラインファーストなPWAを段階的構築:Service Worker キャッシュ戦略(Cache First / Stale-While-Revalidate)、構造化ローカルデータ用IndexedDBラッパー、ネットワーク復旧時にオフライン操作を自動リプレイするBackground Syncキュー。完全TypeScriptコード付き。

1 分で読了
GraphQL vs REST:7つの視点から深く比較

GraphQL vs REST:7つの視点から深く比較

APIスタイル選択迷宮を終わらせる:ネットワーク効率・DX・進化コスト・キャッシュ・型安全性・セキュリティ・エコシステムの7次元で比較。明確なデシジョンツリーとハイブリッド構成を提示。

1 分で読了