[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill-d97f493c-2739-4547-8c16-c9849f6d078c":3,"$f6l-Z3fBb_AUCk80ItRwa6bt19Sj8CY3iezSPOb_mweQ":43},{"id":4,"title":5,"description":6,"categoryId":7,"moduleId":8,"tags":9,"prompt":10,"icon":11,"source":12,"sourceUrl":13,"authorId":14,"authorName":15,"isPublic":16,"stars":17,"runs":18,"createdAt":19,"updatedAt":19,"module":20,"category":27,"packages":34},"d97f493c-2739-4547-8c16-c9849f6d078c","turborepo-caching","配置Turborepo以实现高效的monorepo构建，并使用本地和远程缓存。在设置Turborepo、优化构建管道或实施分布式缓存时使用。","cat_prod_data","mod_productivity","sickn33,productivity","---\nname: turborepo-caching\ndescription: \"Configure Turborepo for efficient monorepo builds with local and remote caching. Use when setting up Turborepo, optimizing build pipelines, or implementing distributed caching.\"\nrisk: critical\nsource: community\ndate_added: \"2026-02-27\"\n---\n\n# Turborepo Caching\n\nProduction patterns for Turborepo build optimization.\n\n## Do not use this skill when\n\n- The task is unrelated to turborepo caching\n- You need a different domain or tool outside this scope\n\n## Instructions\n\n- Clarify goals, constraints, and required inputs.\n- Apply relevant best practices and validate outcomes.\n- Provide actionable steps and verification.\n- If detailed examples are required, open `resources\u002Fimplementation-playbook.md`.\n\n## Use this skill when\n\n- Setting up new Turborepo projects\n- Configuring build pipelines\n- Implementing remote caching\n- Optimizing CI\u002FCD performance\n- Migrating from other monorepo tools\n- Debugging cache misses\n\n## Core Concepts\n\n### 1. Turborepo Architecture\n\n```\nWorkspace Root\u002F\n├── apps\u002F\n│   ├── web\u002F\n│   │   └── package.json\n│   └── docs\u002F\n│       └── package.json\n├── packages\u002F\n│   ├── ui\u002F\n│   │   └── package.json\n│   └── config\u002F\n│       └── package.json\n├── turbo.json\n└── package.json\n```\n\n### 2. Pipeline Concepts\n\n| Concept | Description |\n|---------|-------------|\n| **dependsOn** | Tasks that must complete first |\n| **cache** | Whether to cache outputs |\n| **outputs** | Files to cache |\n| **inputs** | Files that affect cache key |\n| **persistent** | Long-running tasks (dev servers) |\n\n## Templates\n\n### Template 1: turbo.json Configuration\n\n```json\n{\n  \"$schema\": \"https:\u002F\u002Fturbo.build\u002Fschema.json\",\n  \"globalDependencies\": [\n    \".env\",\n    \".env.local\"\n  ],\n  \"globalEnv\": [\n    \"NODE_ENV\",\n    \"VERCEL_URL\"\n  ],\n  \"pipeline\": {\n    \"build\": {\n      \"dependsOn\": [\"^build\"],\n      \"outputs\": [\n        \"dist\u002F**\",\n        \".next\u002F**\",\n        \"!.next\u002Fcache\u002F**\"\n      ],\n      \"env\": [\n        \"API_URL\",\n        \"NEXT_PUBLIC_*\"\n      ]\n    },\n    \"test\": {\n      \"dependsOn\": [\"build\"],\n      \"outputs\": [\"coverage\u002F**\"],\n      \"inputs\": [\n        \"src\u002F**\u002F*.tsx\",\n        \"src\u002F**\u002F*.ts\",\n        \"test\u002F**\u002F*.ts\"\n      ]\n    },\n    \"lint\": {\n      \"outputs\": [],\n      \"cache\": true\n    },\n    \"typecheck\": {\n      \"dependsOn\": [\"^build\"],\n      \"outputs\": []\n    },\n    \"dev\": {\n      \"cache\": false,\n      \"persistent\": true\n    },\n    \"clean\": {\n      \"cache\": false\n    }\n  }\n}\n```\n\n### Template 2: Package-Specific Pipeline\n\n```json\n\u002F\u002F apps\u002Fweb\u002Fturbo.json\n{\n  \"$schema\": \"https:\u002F\u002Fturbo.build\u002Fschema.json\",\n  \"extends\": [\"\u002F\u002F\"],\n  \"pipeline\": {\n    \"build\": {\n      \"outputs\": [\".next\u002F**\", \"!.next\u002Fcache\u002F**\"],\n      \"env\": [\n        \"NEXT_PUBLIC_API_URL\",\n        \"NEXT_PUBLIC_ANALYTICS_ID\"\n      ]\n    },\n    \"test\": {\n      \"outputs\": [\"coverage\u002F**\"],\n      \"inputs\": [\n        \"src\u002F**\",\n        \"tests\u002F**\",\n        \"jest.config.js\"\n      ]\n    }\n  }\n}\n```\n\n### Template 3: Remote Caching with Vercel\n\n```bash\n# Login to Vercel\nnpx turbo login\n\n# Link to Vercel project\nnpx turbo link\n\n# Run with remote cache\nturbo build --remote-only\n\n# CI environment variables\nTURBO_TOKEN=your-token\nTURBO_TEAM=your-team\n```\n\n```yaml\n# .github\u002Fworkflows\u002Fci.yml\nname: CI\n\non:\n  push:\n    branches: [main]\n  pull_request:\n\nenv:\n  TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}\n  TURBO_TEAM: ${{ vars.TURBO_TEAM }}\n\njobs:\n  build:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions\u002Fcheckout@v4\n\n      - uses: actions\u002Fsetup-node@v4\n        with:\n          node-version: 20\n          cache: 'npm'\n\n      - name: Install dependencies\n        run: npm ci\n\n      - name: Build\n        run: npx turbo build --filter='...[origin\u002Fmain]'\n\n      - name: Test\n        run: npx turbo test --filter='...[origin\u002Fmain]'\n```\n\n### Template 4: Self-Hosted Remote Cache\n\n```typescript\n\u002F\u002F Custom remote cache server (Express)\nimport express from 'express';\nimport { createReadStream, createWriteStream } from 'fs';\nimport { mkdir } from 'fs\u002Fpromises';\nimport { join } from 'path';\n\nconst app = express();\nconst CACHE_DIR = '.\u002Fcache';\n\n\u002F\u002F Get artifact\napp.get('\u002Fv8\u002Fartifacts\u002F:hash', async (req, res) => {\n  const { hash } = req.params;\n  const team = req.query.teamId || 'default';\n  const filePath = join(CACHE_DIR, team, hash);\n\n  try {\n    const stream = createReadStream(filePath);\n    stream.pipe(res);\n  } catch {\n    res.status(404).send('Not found');\n  }\n});\n\n\u002F\u002F Put artifact\napp.put('\u002Fv8\u002Fartifacts\u002F:hash', async (req, res) => {\n  const { hash } = req.params;\n  const team = req.query.teamId || 'default';\n  const dir = join(CACHE_DIR, team);\n  const filePath = join(dir, hash);\n\n  await mkdir(dir, { recursive: true });\n\n  const stream = createWriteStream(filePath);\n  req.pipe(stream);\n\n  stream.on('finish', () => {\n    res.json({ urls: [`${req.protocol}:\u002F\u002F${req.get('host')}\u002Fv8\u002Fartifacts\u002F${hash}`] });\n  });\n});\n\n\u002F\u002F Check artifact exists\napp.head('\u002Fv8\u002Fartifacts\u002F:hash', async (req, res) => {\n  const { hash } = req.params;\n  const team = req.query.teamId || 'default';\n  const filePath = join(CACHE_DIR, team, hash);\n\n  try {\n    await fs.access(filePath);\n    res.status(200).end();\n  } catch {\n    res.status(404).end();\n  }\n});\n\napp.listen(3000);\n```\n\n```json\n\u002F\u002F turbo.json for self-hosted cache\n{\n  \"remoteCache\": {\n    \"signature\": false\n  }\n}\n```\n\n```bash\n# Use self-hosted cache\nturbo build --api=\"http:\u002F\u002Flocalhost:3000\" --token=\"my-token\" --team=\"my-team\"\n```\n\n### Template 5: Filtering and Scoping\n\n```bash\n# Build specific package\nturbo build --filter=@myorg\u002Fweb\n\n# Build package and its dependencies\nturbo build --filter=@myorg\u002Fweb...\n\n# Build package and its dependents\nturbo build --filter=...@myorg\u002Fui\n\n# Build changed packages since main\nturbo build --filter='...[origin\u002Fmain]'\n\n# Build packages in directory\nturbo build --filter='.\u002Fapps\u002F*'\n\n# Combine filters\nturbo build --filter=@myorg\u002Fweb --filter=@myorg\u002Fdocs\n\n# Exclude package\nturbo build --filter='!@myorg\u002Fdocs'\n\n# Include dependencies of changed\nturbo build --filter='...[HEAD^1]...'\n```\n\n### Template 6: Advanced Pipeline Configuration\n\n```json\n{\n  \"$schema\": \"https:\u002F\u002Fturbo.build\u002Fschema.json\",\n  \"pipeline\": {\n    \"build\": {\n      \"dependsOn\": [\"^build\"],\n      \"outputs\": [\"dist\u002F**\"],\n      \"inputs\": [\n        \"$TURBO_DEFAULT$\",\n        \"!**\u002F*.md\",\n        \"!**\u002F*.test.*\"\n      ]\n    },\n    \"test\": {\n      \"dependsOn\": [\"^build\"],\n      \"outputs\": [\"coverage\u002F**\"],\n      \"inputs\": [\n        \"src\u002F**\",\n        \"tests\u002F**\",\n        \"*.config.*\"\n      ],\n      \"env\": [\"CI\", \"NODE_ENV\"]\n    },\n    \"test:e2e\": {\n      \"dependsOn\": [\"build\"],\n      \"outputs\": [],\n      \"cache\": false\n    },\n    \"deploy\": {\n      \"dependsOn\": [\"build\", \"test\", \"lint\"],\n      \"outputs\": [],\n      \"cache\": false\n    },\n    \"db:generate\": {\n      \"cache\": false\n    },\n    \"db:push\": {\n      \"cache\": false,\n      \"dependsOn\": [\"db:generate\"]\n    },\n    \"@myorg\u002Fweb#build\": {\n      \"dependsOn\": [\"^build\", \"@myorg\u002Fdb#db:generate\"],\n      \"outputs\": [\".next\u002F**\"],\n      \"env\": [\"NEXT_PUBLIC_*\"]\n    }\n  }\n}\n```\n\n### Template 7: Root package.json Setup\n\n```json\n{\n  \"name\": \"my-turborepo\",\n  \"private\": true,\n  \"workspaces\": [\n    \"apps\u002F*\",\n    \"packages\u002F*\"\n  ],\n  \"scripts\": {\n    \"build\": \"turbo build\",\n    \"dev\": \"turbo dev\",\n    \"lint\": \"turbo lint\",\n    \"test\": \"turbo test\",\n    \"clean\": \"turbo clean && rm -rf node_modules\",\n    \"format\": \"prettier --write \\\"**\u002F*.{ts,tsx,md}\\\"\",\n    \"changeset\": \"changeset\",\n    \"version-packages\": \"changeset version\",\n    \"release\": \"turbo build --filter=.\u002Fpackages\u002F* && changeset publish\"\n  },\n  \"devDependencies\": {\n    \"turbo\": \"^1.10.0\",\n    \"prettier\": \"^3.0.0\",\n    \"@changesets\u002Fcli\": \"^2.26.0\"\n  },\n  \"packageManager\": \"npm@10.0.0\"\n}\n```\n\n## Debugging Cache\n\n```bash\n# Dry run to see what would run\nturbo build --dry-run\n\n# Verbose output with hashes\nturbo build --verbosity=2\n\n# Show task graph\nturbo build --graph\n\n# Force no cache\nturbo build --force\n\n# Show cache status\nturbo build --summarize\n\n# Debug specific task\nTURBO_LOG_VERBOSITY=debug turbo build --filter=@myorg\u002Fweb\n```\n\n## Best Practices\n\n### Do's\n- **Define explicit inputs** - Avoid cache invalidation\n- **Use workspace protocol** - `\"@myorg\u002Fui\": \"workspace:*\"`\n- **Enable remote caching** - Share across CI and local\n- **Filter in CI** - Build only affected packages\n- **Cache build outputs** - Not source files\n\n### Don'ts\n- **Don't cache dev servers** - Use `persistent: true`\n- **Don't include secrets in env** - Use runtime env vars\n- **Don't ignore dependsOn** - Causes race conditions\n- **Don't over-filter** - May miss dependencies\n\n## Resources\n\n- [Turborepo Documentation](https:\u002F\u002Fturbo.build\u002Frepo\u002Fdocs)\n- [Caching Guide](https:\u002F\u002Fturbo.build\u002Frepo\u002Fdocs\u002Fcore-concepts\u002Fcaching)\n- [Remote Caching](https:\u002F\u002Fturbo.build\u002Frepo\u002Fdocs\u002Fcore-concepts\u002Fremote-caching)\n\n## Limitations\n- Use this skill only when the task clearly matches the scope described above.\n- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.\n- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.\n","","imported","https:\u002F\u002Fgithub.com\u002Fsickn33\u002Fantigravity-awesome-skills","user_system_seed","SkillOPIC",true,232,236,"2026-05-16 13:44:53",{"id":8,"name":21,"slug":22,"icon":23,"description":24,"sort":25,"createdAt":26},"效率工具","productivity","mdi-lightning-bolt-outline","文档处理、数据分析、自动化工作流",4,"2026-05-16 12:53:40",{"id":7,"name":28,"slug":29,"icon":30,"description":31,"moduleId":8,"sort":32,"skillCount":33,"createdAt":26},"数据分析","data-analysis","mdi-chart-bar","数据可视化、统计分析",2,30,[35],{"id":36,"skillId":4,"version":37,"fileName":38,"fileSize":39,"filePath":40,"fileHash":41,"manifest":42,"createdAt":19},"aa7ae4c7-68ec-422d-9d92-375ecd349a04","1.0.0","turborepo-caching.zip",3368,"uploads\u002Fskills\u002Fd97f493c-2739-4547-8c16-c9849f6d078c\u002Fturborepo-caching.zip","ba9d28187026bf5cb3c6a5419ecaf4c95007d9e39802332d62f2e8bc619152b0","[{\"path\":\"SKILL.md\",\"isDirectory\":false,\"size\":9186}]",{"code":44,"message":45,"data":46},200,"success",{"items":47,"stats":48,"page":51},[],{"averageRating":49,"totalRatings":49,"ratingCounts":50},0,[49,49,49,49,49],{"limit":52,"offset":49,"hasMore":53,"nextOffset":52,"ratedOnly":16},15,false]