Skip to main content
In a monorepo, you may have dozens or hundreds of projects to manage. Nx provides a task runner that lets you:
  • Run multiple targets for multiple projects in parallel
  • Define task pipelines that execute in dependency order
  • Run tasks only for projects affected by a change
  • Speed up execution with caching

Define tasks

Nx tasks can come from package.json scripts, be inferred from tooling configuration files, or be defined explicitly in project.json. Nx merges all three sources for each project.

Run tasks

Nx uses the syntax nx <target> <project> or the long form nx run <project>:<target>.

Run a single task

Run tasks for multiple projects

Use run-many to run a target across all projects, or a filtered subset:
Nx parallelizes execution and runs tasks in the correct order based on project dependencies and your task pipeline configuration.

Run tasks on projects affected by a PR

See Affected Builds for details on how Nx determines which projects to include.

Define a task pipeline

Many tasks must run in a specific order — for example, building dependencies before the application that uses them. Declare this in nx.json using dependsOn:
The ^build syntax means “run build on all projects this project depends on first”. If you run nx build myreactapp and myreactapp depends on shared-ui and feat-products, Nx will build those two libraries before building the app. You can define dependsOn globally in nx.json or per-project in project.json.

Reduce repetitive configuration

Use targetDefaults in nx.json to set shared configuration that applies to all projects with a matching target name:

Run root-level tasks

For tasks that apply to the whole codebase rather than a single project, define them at the root level:
Invoke the task with: