When Nx computes the hash for a task, it considers the task’sDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/nrwl/nx/llms.txt
Use this file to discover all available pages before exploring further.
inputs. If any input changes, the cache is invalidated and the task re-runs. Inputs are defined on individual targets or in namedInputs for reuse across the workspace.
Input types
Nx supports the following input types. Each can appear as an element in aninputs array.
Fileset
File path globs that determine which files contribute to the cache hash. Patterns must be prefixed with{projectRoot} or {workspaceRoot}.
fileset property:
A glob pattern prefixed with
{projectRoot} or {workspaceRoot} that
selects files to include in the hash.When
true, the fileset is applied to each of the project’s dependencies
rather than the project itself.{projectRoot}/**/*— matches only files assigned to the specific project. Files in nested projects are excluded.{workspaceRoot}/path/**/*— matches all files in the workspace including nested projects.- Prefix with
!to exclude matching files from the hash. - Prefix with
^to apply the pattern to dependency projects (e.g."^{projectRoot}/**/*.ts").
Environment variable
Include the value of an environment variable in the cache hash. If the variable’s value changes, the task re-runs.The name of the environment variable whose value is included in the hash.
Runtime command
Run a shell command and include its output in the cache hash. Use this to capture tool versions or other dynamic values.A shell command whose stdout output is included in the hash. Avoid
platform-specific scripts (
.sh, .bat) — use cross-platform commands
instead.External dependencies
Include the resolved version of one or more npm packages in the cache hash. When a listed package is updated, the task re-runs.Package names to include in the hash. If this property is omitted from a
target’s inputs entirely, Nx hashes all external dependencies in the
workspace (conservative default). Specifying at least one
externalDependencies entry restricts hashing to only the listed packages.Nx plugins maintained by the Nx team automatically configure the correct
externalDependencies for their executors. You only need to configure this
manually for nx:run-commands targets and community plugins.Outputs of dependent tasks
Consider files produced by dependency tasks as inputs to this task. Useful when a build task consumes type definitions generated upstream.A glob pattern matched against output file paths (resolved from workspace
root) of dependent tasks.
When
true, also includes outputs from transitive dependencies (all tasks in
the dependency chain), not only direct dependencies.Working directory
Include the current working directory in the hash. Use this when task behavior depends on which directory the command is invoked from."relative" hashes the path from workspace root to the current directory.
"absolute" hashes the full filesystem path, which invalidates cache entries
when the repository is cloned to a different location.Named inputs
Named inputs are reusable sets of inputs defined innamedInputs. They act as variables you can reference by name in target inputs arrays instead of repeating the same definition everywhere.
Defining named inputs
Workspace level — available to all projects:nx.json
- project.json
- package.json
project.json
Referencing named inputs
Named inputs are referenced by string in anyinputs array:
project.json
| Reference | Meaning |
|---|---|
"default" | Apply the default named input for the current project |
"^production" | Apply the production named input for each dependency project |
{ "input": "production", "projects": "mylib" } | Apply the production named input defined in a specific project |
The
^ prefix behaves differently depending on what follows it:"^production"— resolves theproductionnamed input per dependency"^{projectRoot}/**/*.ts"— applies the fileset to each dependency project’s root
Built-in named input conventions
Nx workspaces are generated with these named inputs by default:nx.json
default
default
All files in the project root plus shared global inputs. Using
default for
a target means any file change in the project invalidates the cache — the
safest choice.sharedGlobals
sharedGlobals
production
production
A subset of
default that excludes developer-only files (test files, lint
configs, etc.) that don’t affect production output. Define production
inputs on each project so that test tasks on downstream projects are not
invalidated when test files change.Configuring inputs for build vs. test
A common pattern is to useproduction inputs for builds and default inputs for tests, so that changes to test files don’t invalidate downstream build caches:
nx.json
- Changing a
*.spec.tsfile invalidatestest(becausedefaultincludes all files) but notbuild(becauseproductionexcludes spec files). - Changing a source file in a library invalidates both the library’s
buildand any application’sbuildthat depends on it, because^productionpropagates the library’s production inputs upstream.
nx.json reference
Define
namedInputs at the workspace level.Project configuration reference
Override
namedInputs and set inputs per target.