turborepo について
turborepo は、Turborepo を使う JavaScript と TypeScript のモノレポ向けガイダンススキルです。タスク設定、キャッシュ、環境変数、フィルタリング、CI のルールと参照先を示します。
主な機能
- 01Turborepo タスクの設定
- 02キャッシュと出力設定の指針
- 03環境変数設定への対応
- 04影響を受けるパッケージの抽出
- 05モノレポと CI の計画
活用シーン
- 01パッケージ間のビルド依存関係の設定
- 02ビルドキャッシュミスの調査
- 03CI で影響対象のタスクを実行
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ shipshitdev/ skills --skill turborepoインストール後、Claude Code で/turborepoを入力して読み込まれたか確認します。
同梱ファイル
SKILL.md と一緒にインストールされる参考資料やスクリプト。
plugin.jsoncommand/turborepo.mdreferences/best-practices/dependencies.mdpackages.mdRULE.mdstructure.mdreferences/boundaries/RULE.mdreferences/caching/gotchas.mdremote-cache.mdRULE.mdreferences/ci/github-actions.mdpatterns.mdRULE.mdvercel.mdreferences/cli/commands.mdRULE.mdreferences/configuration/global-options.mdgotchas.mdRULE.mdtasks.mdreferences/environment/gotchas.mdmodes.mdRULE.mdreferences/filtering/patterns.mdRULE.mdreferences/watch/RULE.md詳細
Turborepo スキル
Turborepo を使用した JavaScript および TypeScript のモノレポ向けビルドシステムのガイダンスです。
コアとなるルール
- ルートタスクではなく、パッケージタスクを作成します。
- タスクの動作は
turbo.jsonに登録します。 - ルートの
package.jsonからturbo run <task>を呼び出します。 turbo <task>は対話型の単発ターミナルコマンドにのみ使用し、コミットするコードでは使用しません。dependsOn: ["^build"]で実際のパッケージ間の依存関係を解決できるよう、ワークスペースの依存関係をpackage.jsonに宣言します。
基本パターン
// apps/web/package.json
{
"scripts": {
"build": "next build",
"lint": "eslint .",
"test": "vitest"
}
}
// turbo.json
{
"tasks": {
"build": {
"dependsOn": ["^build"],
"outputs": ["dist/**", ".next/**", "!.next/cache/**"]
},
"lint": {},
"test": {
"dependsOn": ["build"]
}
}
}
// root package.json
{
"scripts": {
"build": "turbo run build",
"lint": "turbo run lint",
"test": "turbo run test"
}
}
クイックルーティング
タスクに必要なリファレンスファイルのみを読みます。
| 必要な項目 | 読むファイル |
|---|---|
タスク定義、dependsOn、outputs、persistent、パッケージのオーバーライド | references/configuration/RULE.md、references/configuration/tasks.md |
| グローバルオプション、デーモン、cacheDir、環境モード | references/configuration/global-options.md |
| キャッシュミスまたはリモートキャッシュ | references/caching/RULE.md、references/caching/gotchas.md、references/caching/remote-cache.md |
環境変数、.env、strict モードと loose モード | references/environment/RULE.md、references/environment/modes.md、references/environment/gotchas.md |
--affected、--filter、パッケージの選択 | references/filtering/RULE.md、references/filtering/patterns.md |
CI、GitHub Actions、Vercel、turbo-ignore | references/ci/RULE.md、references/ci/github-actions.md、references/ci/vercel.md、references/ci/patterns.md、references/cli/commands.md |
| リポジトリ構造、パッケージの作成、依存関係の管理 | references/best-practices/RULE.md、references/best-practices/structure.md、references/best-practices/packages.md、references/best-practices/dependencies.md |
| ウォッチモードと長時間実行する開発タスク | references/watch/RULE.md、references/configuration/tasks.md |
| パッケージ境界と分離 | references/boundaries/RULE.md |
判断ツリー
タスクを設定する
Configure a task?
├─ Define dependencies or outputs → configuration/tasks.md
├─ Handle environment variables → environment/RULE.md
├─ Set package-specific overrides → configuration/RULE.md#package-configurations
├─ Add persistent/watch behavior → configuration/tasks.md + watch/RULE.md
└─ Tune global options → configuration/global-options.md
キャッシュをデバッグする
Cache issue?
├─ Outputs not restored → add or fix `outputs`
├─ Unexpected misses → caching/gotchas.md
├─ Remote cache issue → caching/remote-cache.md
└─ Env or .env drift → environment/gotchas.md
変更された項目のみを実行する
Need changed packages only?
├─ Default path → `turbo run <task> --affected`
├─ Custom comparison base → add `--affected-base=...`
└─ Custom package selection → filtering/RULE.md + filtering/patterns.md
CI を設定する
CI setup?
├─ GitHub Actions → ci/github-actions.md
├─ Vercel deployment → ci/vercel.md
├─ Remote cache in CI → caching/remote-cache.md
└─ Skip unchanged work → ci/patterns.md + cli/commands.md
モノレポを構成する
Repo/package structure?
├─ apps/ vs packages/ layout → best-practices/RULE.md
├─ Create internal package → best-practices/packages.md
├─ Workspace dependency management → best-practices/dependencies.md
└─ Enforce package boundaries → boundaries/RULE.md
重大なアンチパターン
- Turborepo を完全に迂回するルートスクリプト。ルートスクリプトでは、アプリ固有のタスクロジックを埋め込むのではなく、
turbo runを呼び出します。 package.json、CI、スクリプトにコミットされたturbo buildまたはturbo lintコマンド。コミットするコードではturbo run ...を使用します。- ワークスペースの依存関係を宣言して
^buildを使用する代わりに、兄弟パッケージをコンパイルする手動のprebuildチェーン。 - ファイルを書き出すタスクに
outputsがないこと。タスクをキャッシュ可能と判断する前に、実際のスクリプトを確認します。 envから環境変数が漏れている、またはinputsから.envファイルが漏れているために、古いキャッシュがヒットすること。- モノレポのルートレベルに
.envファイルを置くこと。パッケージ間に見えにくい結合を生みます。 - パッケージ API を通じてインポートせず、相対インポートやファイルの階層をたどってパッケージ境界を越えること。
- パッケージごとのオーバーライドでルートの
turbo.jsonを煩雑にすること。代わりにパッケージごとのturbo.jsonファイルを使用します。
詳しい例については、以下を参照してください。
references/configuration/gotchas.mdreferences/caching/gotchas.mdreferences/environment/gotchas.mdreferences/best-practices/structure.mdreferences/best-practices/packages.md
よくある設定
標準的なビルドと開発
{
"tasks": {
"build": {
"dependsOn": ["^build"],
"outputs": ["dist/**", ".next/**", "!.next/cache/**"]
},
"dev": {
"cache": false,
"persistent": true
}
}
}
キャッシュを正しく無効化しながら並列タスクを実行するための中継ノード
{
"tasks": {
"transit": {
"dependsOn": ["^transit"]
},
"lint": {
"dependsOn": ["transit"]
}
}
}
タスクを並列実行できる一方で、依存関係にあるソースの変更をキャッシュ無効化に反映する必要がある場合に使用します。
ウォッチモードのパターン
ファイル変更の監視ループには turbo watch を使用し、スクリプト内で即席に作成した turbo run ... --watch パターンは使用しません。persistent、interruptible、または with を設定する前に、references/watch/RULE.md を読んでください。
検証チェックリスト
- コードまたは CI でコミットされているすべてのコマンドは、
turbo run ...を使用しています。 - タスクはパッケージのスクリプトに記述し、ルートのスクリプトは委譲のみを行います。
dependsOnは実際の依存関係に一致しています。上流のパッケージには^task、同じパッケージ内の前提タスクにはtaskを使用します。- キャッシュ可能なファイル生成タスクでは、
outputsを宣言しています。 - 関連する環境変数は
envまたはglobalEnvに記述しています。 - 関連する
.envファイルはinputsに含めています。 - ワークスペースのパッケージ間のインポートには、相対ソースパスではなくパッケージ名を使用しています。
- CI では、デフォルトですべてを再ビルドするのではなく、適切な場合に
--affectedまたはフィルターを使用しています。
参照ドキュメント
Turborepo の公式ドキュメント(ライブラリ v2.9.7-canary.12)に基づいています:apps/docs/content/docs/ — https://turborepo.dev/docs
コメント
Markdown 対応