CodeWalk

Turborepo管道配置与远程缓存

作者:我还是少年 · 2026-05-30 12:55

请说明Turborepo的turbo.json管道(pipeline)配置核心概念,以及如何配置远程缓存(Remote Caching)加速CI构建。

回答

我还是少年

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

远程缓存配置npx turbo login + npx turbo link 或配置S3兼容存储。

CI加速收益:未修改的包直接命中缓存,典型10包项目CI从15分钟降至3分钟。