Keep the global hash narrow
Global inputs bust every task. Scope files and vars to their task.
From turborepo, configuration/gotchas.md #3.
One app's file, every task
Change something only web reads, then build and test.
GlobalBad
0 of 10 re-ranCPU –
"globalDependencies": ["**/.env.*local"], "globalEnv": ["API_URL"]Scoped to webGood
0 of 10 re-ranCPU –
apps/web/turbo.json: "inputs", "env"// turbo.json: only what truly affects everything
{
"globalEnv": ["CI", "NODE_ENV"],
"tasks": {
"build": { "dependsOn": ["^build"], "outputs": ["dist/**"] },
"test": { "dependsOn": ["build"] }
}
}
// apps/web/turbo.json: web's own files and vars
{
"extends": ["//"],
"tasks": {
"build": {
"inputs": ["$TURBO_DEFAULT$", ".env*"],
"env": ["API_URL"]
}
}
}
Why it matters, pros and cons
Why it matters
globalDependencies and globalEnv go into the global hash, which is part of every task's key. No task can opt out.
Pros
- An app's env edit rebuilds that app only.
- Package
turbo.jsonkeeps config next to the code. - Per-package
.envfiles show who reads what.
Cons
- Truly shared vars like
CIbelong inglobalEnv. - The lockfile and root
turbo.jsonstay global anyway. - More files to read when auditing the hash.