This PR adds information about `continuous` option for tasks. Also removes references to Nx <16 examples on the project configuration page. **Preview:** - https://nx-dev-git-docs-continuous-tasks-nrwl.vercel.app/recipes/running-tasks/defining-task-pipeline#continuous-task-dependencies - Add a section on continuous task and links to the project configuration reference page (below) - https://nx-dev-git-docs-continuous-tasks-nrwl.vercel.app/reference/project-configuration#continuous - Add section on continuous task with example of `e2e -> serve` dependency - Add a callout on `dependsOn` section for continuous/long-running tasks (long-running is mentioned so it appears in the search) - Remove Nx <16 examples **TODO:** - [x] Update PDV that show e2e and serve targets
3.6 KiB
| title | description |
|---|---|
| Defining a Task Pipeline | This recipe shows how to define task dependencies in your Nx workspace |
Defining a Task Pipeline
Running a specific task like build in a monorepo usually involves running multiple commands.
If you want to learn more about the concept of a task pipeline and its importance in a monorepo, have a look at the What is a Task Pipeline page.
{% youtube src="https://youtu.be/_U4hu6SuBaY?si=rSclPBdRh7P_xZ_f" title="Define a task pipeline" /%}
Define Dependencies Between Tasks
You can define dependencies among tasks by using the dependsOn property:
// nx.json
{
...
"targetDefaults": {
"build": {
"dependsOn": ["^build"]
}
}
}
Per Project vs Global
Task dependencies can be defined globally for all projects in nx.json file:
{
...
"targetDefaults": {
"build": {
"dependsOn": ["^build"]
}
}
}
Or they can be defined per-project in the project.json or package.json files. If for example you have a prebuild step for a given project, you can define that relationship as follows:
{% tabs %} {% tab label="package.json" %}
{
"name": "myapp",
"dependencies": {},
"devDependencies": {},
...
"nx": {
"targets": {
"build": {
"dependsOn": [
"prebuild"
]
}
}
}
}
{% /tab %} {% tab label="project.json" %}
{
"name": "myreactapp",
...
"targets": {
"prebuild": {
"command": "echo Prebuild"
},
"build": {
"command": "echo Build",
"dependsOn": ["prebuild"]
}
}
}
{% /tab %} {% /tabs %}
Continuous Task Dependencies
If a task has a dependency that never exits, then the task will never start. To support this scenario, you can mark the dependency as a continuous task. Labeling a task as continuous tells Nx to not wait for the process to exit, and it will be run alongside its dependents.
{
"targets": {
"serve": {
"continuous": true
}
}
}
The continuous option is most useful for running development servers. For example, the e2e task depends on a continuous serve task that starts the server to be tested againts.
Visualize Task Dependencies
You can also visualize the actual task graph (alongside the projects) using Nx graph. This can be useful for debugging purposes.
To view the task graph in your browser, run:
npx nx graph
And then select "Tasks" from the top-left dropdown, choose the target (e.g. build, test,..) and either show all tasks or select a specific project you're interested in. Here's an example of the playwright Nx plugin build target (in the Nx repo).
Alternatively you can use the Nx Console extension in VSCode or IntelliJ, right-click on the project and select:
It'll then visualize within the IDE:


