Configure an Nx workspace
Nx is a build system for monorepos that adds computation caching, dependency-graph-aware task ordering, and code generation. The root nx.json controls all of it — which targets are cacheable, how tasks order themselves, and which file changes invalidate cached results. This builder produces a correct, modern nx.json.
How it works
targetDefaults holds shared settings keyed by target name (build, test, lint). For each one you set dependsOn for ordering, inputs to control the cache hash, outputs to tell Nx which files to cache, and cache: true to make the target cacheable. The ^build caret means a project’s dependencies build first, mirroring the project graph.
namedInputs defines reusable globs. The default input covers every project file plus shared globals; the production input extends default but excludes test files, so editing a spec invalidates test but not build. These named sets keep cache invalidation precise.
Parallelism is set with the parallel field, or inside tasksRunnerOptions if you opt into the explicit runner form. Recent Nx versions infer cacheable operations directly from the cache flag, so the simpler top-level form is preferred.
Tips and notes
- Declare
outputsaccurately — a wrong path means cache hits restore nothing. - Use the
productionnamed input forbuildto avoid test files busting the cache. - Keep
parallelnear your CPU core count for best throughput. - The explicit
tasksRunnerOptionsform is only needed for legacy or custom runners.