turborepo-monorepo by giuseppe-trisciuoglio/developer-kit
npx skills add https://github.com/giuseppe-trisciuoglio/developer-kit --skill turborepo-monorepo为在 TypeScript/JavaScript 项目中使用 Turborepo monorepo 提供全面的指导。Turborepo 是一个用 Rust 编写的高性能构建系统,它通过智能缓存、并行化和依赖图分析来优化任务执行。本技能涵盖工作区创建、任务配置、框架集成(Next.js、NestJS、Vite)、测试设置、CI/CD 流水线以及性能优化。
在以下情况使用此技能:
turbo.json 任务触发短语: "create Turborepo workspace", "Turborepo monorepo", "turbo.json config", "Turborepo Next.js", "Turborepo NestJS", "Turborepo CI/CD", "Vitest Turborepo"
创建新工作区:
# 使用 pnpm(推荐)
pnpm create turbo@latest my-workspace
# 使用 npm
npm create turbo@latest my-workspace
# 使用 yarn
yarn create turbo my-workspace
在现有项目中初始化:
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
pnpm add -D -w turbo
在根目录创建 turbo.json:
{
"$schema": "https://turborepo.dev/schema.json",
"pipeline": {
"build": {
"dependsOn": ["^build"],
"outputs": ["dist/**", ".next/**"]
},
"lint": {
"outputs": []
},
"test": {
"dependsOn": ["build"],
"outputs": ["coverage/**"]
}
}
}
向根目录 package.json 添加脚本:
{
"scripts": {
"build": "turbo run build",
"dev": "turbo run dev",
"lint": "turbo run lint",
"test": "turbo run test",
"clean": "turbo run clean"
}
}
配置任务依赖关系:
{
"pipeline": {
"build": {
"dependsOn": ["^build"],
"outputs": ["dist/**"]
},
"test": {
"dependsOn": ["build"],
"outputs": ["coverage/**"]
},
"lint": {
"outputs": []
}
}
}
跨包运行任务:
# 为所有包运行任务
turbo run build
# 运行多个任务
turbo run lint test build
# 为特定包运行
turbo run build --filter=web
使用中转节点进行并行类型检查:
{
"pipeline": {
"transit": {
"dependsOn": ["^transit"]
},
"typecheck": {
"dependsOn": ["transit"],
"outputs": []
}
}
}
Next.js 应用配置:
{
"pipeline": {
"build": {
"dependsOn": ["^build"],
"outputs": [".next/**", "!.next/cache/**"],
"env": ["NEXT_PUBLIC_*"]
}
}
}
查看 references/nextjs-config.md 获取完整的 Next.js 设置。
NestJS API 配置:
{
"pipeline": {
"build": {
"dependsOn": ["^build"],
"outputs": ["dist/**"]
},
"start:dev": {
"cache": false,
"persistent": true
}
}
}
查看 references/nestjs-config.md 获取完整的 NestJS 设置。
Vitest 配置:
{
"pipeline": {
"test": {
"outputs": [],
"inputs": ["$TURBO_DEFAULT$", "vitest.config.ts"]
},
"test:watch": {
"cache": false,
"persistent": true
}
}
}
运行受影响的测试:
turbo run test --filter=[HEAD^]
查看 references/testing-config.md 获取完整的测试设置。
创建包特定的 turbo.json:
{
"extends": ["//"],
"tasks": {
"build": {
"outputs": ["$TURBO_EXTENDS$", ".next/**"]
}
}
}
查看 references/package-configs.md 获取详细的包配置模式。
GitHub Actions 基础工作流:
- name: Install dependencies
run: pnpm install
- name: Run tests
run: pnpm run test --filter=[HEAD^]
- name: Build
run: pnpm run build --filter=[HEAD^]
远程缓存设置:
# 登录 Vercel
npx turbo login
# 链接仓库
npx turbo link
查看 references/ci-cd.md 获取完整的 CI/CD 设置示例。
| 属性 | 描述 | 示例 |
|---|---|---|
dependsOn | 必须先完成的任务 | ["^build"] - 依赖项优先 |
outputs | 要缓存的文件/文件夹 | ["dist/**"] |
inputs | 用于缓存哈希的文件 | ["src/**/*.ts"] |
env | 影响哈希的环境变量 | ["DATABASE_URL"] |
cache | 启用/禁用缓存 | true 或 false |
persistent | 长时间运行的任务 | true 用于开发服务器 |
outputLogs | 日志详细程度 | "full", "new-only", "errors-only" |
^task - 先在依赖项中运行任务(拓扑顺序)task - 先在同一个包中运行任务package#task - 运行特定包的任务| 过滤器 | 描述 |
|---|---|
web | 仅 web 包 |
web... | web + 所有依赖项 |
...web | web + 所有依赖于此的包 |
...web... | web + 依赖项 + 依赖于此的包 |
[HEAD^] | 自上次提交以来更改的包 |
./apps/* | apps/ 中的所有包 |
{
"pipeline": {
"build": {
"outputs": ["dist/**"],
"inputs": ["$TURBO_DEFAULT$", "!README.md", "!**/*.md"]
}
}
}
dependsOn:lint、format、spellcheckdependsOn: ["^build"]:build、compiledependsOn: ["build"]:test、e2ecache: false, persistent: true:dev、watchmy-workspace/
├── apps/
│ ├── web/ # Next.js 应用
│ └── api/ # NestJS 后端
├── packages/
│ ├── ui/ # React 组件库
│ └── config/ # 共享配置
├── turbo.json
├── package.json
└── pnpm-workspace.yaml
问题: 任务以错误的顺序执行
解决方案: 检查 dependsOn 配置
{
"build": {
"dependsOn": ["^build"]
}
}
问题: 缓存意外失效
解决方案: 检查 globalDependencies 和 inputs
{
"globalDependencies": ["tsconfig.json"],
"pipeline": {
"build": {
"inputs": ["$TURBO_DEFAULT$", "!*.md"]
}
}
}
问题: 由于缓存未捕获 TypeScript 错误
解决方案: 使用中转节点进行类型检查
{
"transit": { "dependsOn": ["^transit"] },
"typecheck": { "dependsOn": ["transit"] }
}
输入: "Create a Turborepo with Next.js and NestJS"
pnpm create turbo@latest my-workspace
cd my-workspace
# 添加 Next.js 应用
pnpm add next react react-dom -F apps/web
# 添加 NestJS API
pnpm add @nestjs/core @nestjs/common -F apps/api
输入: "Set up Vitest for all packages"
{
"pipeline": {
"test": {
"dependsOn": ["build"],
"outputs": ["coverage/**"],
"inputs": ["$TURBO_DEFAULT$", "vitest.config.ts"]
},
"test:watch": {
"cache": false,
"persistent": true
}
}
}
输入: "Only test changed packages in CI"
pnpm run test --filter=[HEAD^]
输入: "Why is my cache missing?"
# 试运行以查看将执行的内容
turbo run build --dry-run --filter=web
# 显示哈希输入
turbo run build --force --filter=web
package.json 中需要 包管理器字段concurrency 设置有关特定主题的详细指导,请查阅:
| 主题 | 参考文件 |
|---|---|
| turbo.json 模板 | references/turbo.json |
| Next.js 集成 | references/nextjs-config.md |
| NestJS 集成 | references/nestjs-config.md |
| Vitest/Jest/Playwright | references/testing-config.md |
| GitHub/CircleCI/GitLab CI | references/ci-cd.md |
| 包配置 | references/package-configs.md |
每周安装数
224
仓库
GitHub 星标数
173
首次出现
2026年2月20日
安全审计
安装于
codex202
gemini-cli200
github-copilot197
kimi-cli195
cursor195
opencode195
Provides comprehensive guidance for working with Turborepo monorepos in TypeScript/JavaScript projects. Turborepo is a high-performance build system written in Rust that optimizes task execution through intelligent caching, parallelization, and dependency graph analysis. This skill covers workspace creation, task configuration, framework integration (Next.js, NestJS, Vite), testing setup, CI/CD pipelines, and performance optimization.
Use this skill when:
turbo.json tasks with proper dependencies and outputsTrigger phrases: "create Turborepo workspace", "Turborepo monorepo", "turbo.json config", "Turborepo Next.js", "Turborepo NestJS", "Turborepo CI/CD", "Vitest Turborepo"
Create a new workspace:
# Using pnpm (recommended)
pnpm create turbo@latest my-workspace
# Using npm
npm create turbo@latest my-workspace
# Using yarn
yarn create turbo my-workspace
Initialize in an existing project:
pnpm add -D -w turbo
Create turbo.json in root:
{
"$schema": "https://turborepo.dev/schema.json",
"pipeline": {
"build": {
"dependsOn": ["^build"],
"outputs": ["dist/**", ".next/**"]
},
"lint": {
"outputs": []
},
"test": {
"dependsOn": ["build"],
"outputs": ["coverage/**"]
}
}
}
Add scripts to root package.json:
{
"scripts": {
"build": "turbo run build",
"dev": "turbo run dev",
"lint": "turbo run lint",
"test": "turbo run test",
"clean": "turbo run clean"
}
}
Configure task dependencies:
{
"pipeline": {
"build": {
"dependsOn": ["^build"],
"outputs": ["dist/**"]
},
"test": {
"dependsOn": ["build"],
"outputs": ["coverage/**"]
},
"lint": {
"outputs": []
}
}
}
Run tasks across packages:
# Run task for all packages
turbo run build
# Run multiple tasks
turbo run lint test build
# Run for specific package
turbo run build --filter=web
Use transit nodes for parallel type checking:
{
"pipeline": {
"transit": {
"dependsOn": ["^transit"]
},
"typecheck": {
"dependsOn": ["transit"],
"outputs": []
}
}
}
Next.js app configuration:
{
"pipeline": {
"build": {
"dependsOn": ["^build"],
"outputs": [".next/**", "!.next/cache/**"],
"env": ["NEXT_PUBLIC_*"]
}
}
}
See references/nextjs-config.md for complete Next.js setup.
NestJS API configuration:
{
"pipeline": {
"build": {
"dependsOn": ["^build"],
"outputs": ["dist/**"]
},
"start:dev": {
"cache": false,
"persistent": true
}
}
}
See references/nestjs-config.md for complete NestJS setup.
Vitest configuration:
{
"pipeline": {
"test": {
"outputs": [],
"inputs": ["$TURBO_DEFAULT$", "vitest.config.ts"]
},
"test:watch": {
"cache": false,
"persistent": true
}
}
}
Run affected tests:
turbo run test --filter=[HEAD^]
See references/testing-config.md for complete testing setup.
Create package-specific turbo.json:
{
"extends": ["//"],
"tasks": {
"build": {
"outputs": ["$TURBO_EXTENDS$", ".next/**"]
}
}
}
See references/package-configs.md for detailed package configuration patterns.
GitHub Actions basic workflow:
- name: Install dependencies
run: pnpm install
- name: Run tests
run: pnpm run test --filter=[HEAD^]
- name: Build
run: pnpm run build --filter=[HEAD^]
Remote cache setup:
# Login to Vercel
npx turbo login
# Link repository
npx turbo link
See references/ci-cd.md for complete CI/CD setup examples.
| Property | Description | Example |
|---|---|---|
dependsOn | Tasks that must complete first | ["^build"] - dependencies first |
outputs | Files/folders to cache | ["dist/**"] |
inputs | Files for cache hash | ["src/**/*.ts"] |
env |
^task - Run task in dependencies first (topological order)task - Run task in same package firstpackage#task - Run specific package's task| Filter | Description |
|---|---|
web | Only web package |
web... | web + all dependencies |
...web | web + all dependents |
...web... | web + deps + dependents |
[HEAD^] | Packages changed since last commit |
./apps/* | All packages in apps/ |
{
"pipeline": {
"build": {
"outputs": ["dist/**"],
"inputs": ["$TURBO_DEFAULT$", "!README.md", "!**/*.md"]
}
}
}
dependsOn: lint, format, spellcheckdependsOn: ["^build"]: build, compiledependsOn: ["build"]: test, e2ecache: false, persistent: true: dev, watchmy-workspace/
├── apps/
│ ├── web/ # Next.js app
│ └── api/ # NestJS backend
├── packages/
│ ├── ui/ # React component library
│ └── config/ # Shared configs
├── turbo.json
├── package.json
└── pnpm-workspace.yaml
Problem: Tasks execute in wrong order
Solution: Check dependsOn configuration
{
"build": {
"dependsOn": ["^build"]
}
}
Problem: Cache invalidating unexpectedly
Solution: Review globalDependencies and inputs
{
"globalDependencies": ["tsconfig.json"],
"pipeline": {
"build": {
"inputs": ["$TURBO_DEFAULT$", "!*.md"]
}
}
}
Problem: TypeScript errors not caught due to cache
Solution: Use transit nodes for type checking
{
"transit": { "dependsOn": ["^transit"] },
"typecheck": { "dependsOn": ["transit"] }
}
Input: "Create a Turborepo with Next.js and NestJS"
pnpm create turbo@latest my-workspace
cd my-workspace
# Add Next.js app
pnpm add next react react-dom -F apps/web
# Add NestJS API
pnpm add @nestjs/core @nestjs/common -F apps/api
Input: "Set up Vitest for all packages"
{
"pipeline": {
"test": {
"dependsOn": ["build"],
"outputs": ["coverage/**"],
"inputs": ["$TURBO_DEFAULT$", "vitest.config.ts"]
},
"test:watch": {
"cache": false,
"persistent": true
}
}
}
Input: "Only test changed packages in CI"
pnpm run test --filter=[HEAD^]
Input: "Why is my cache missing?"
# Dry run to see what would be executed
turbo run build --dry-run --filter=web
# Show hash inputs
turbo run build --force --filter=web
package.jsonconcurrency settingsFor detailed guidance on specific topics, consult:
| Topic | Reference File |
|---|---|
| turbo.json template | references/turbo.json |
| Next.js integration | references/nextjs-config.md |
| NestJS integration | references/nestjs-config.md |
| Vitest/Jest/Playwright | references/testing-config.md |
| GitHub/CircleCI/GitLab CI | references/ci-cd.md |
| Package configurations | references/package-configs.md |
Weekly Installs
224
Repository
GitHub Stars
173
First Seen
Feb 20, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
codex202
gemini-cli200
github-copilot197
kimi-cli195
cursor195
opencode195
agent-browser 浏览器自动化工具 - Vercel Labs 命令行网页操作与测试
147,400 周安装
| Environment variables affecting hash |
["DATABASE_URL"] |
cache | Enable/disable caching | true or false |
persistent | Long-running task | true for dev servers |
outputLogs | Log verbosity | "full", "new-only", "errors-only" |