docs(core): add continuous task to task pipeline and project config pages (#30919)

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
This commit is contained in:
Jack Hsu 2025-04-29 15:44:05 -04:00 committed by GitHub
parent 5fc641012d
commit 13f57d6c04
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 73 additions and 113 deletions

View File

@ -29,7 +29,8 @@
"serve": {
"options": {
"cwd": "apps/myreactapp",
"command": "vite serve"
"command": "vite serve",
"continuous": true
},
"executor": "nx:run-commands",
"configurations": {},
@ -51,7 +52,8 @@
"serve-static": {
"executor": "@nx/web:file-server",
"options": {
"buildTarget": "build"
"buildTarget": "build",
"continuous": true
},
"configurations": {}
},

View File

@ -169,7 +169,8 @@ nx show project my-workspace --web
"dev": {
"options": {
"cwd": ".",
"command": "next dev"
"command": "next dev",
"continuous": true
},
"executor": "nx:run-commands",
"configurations": {},
@ -180,7 +181,8 @@ nx show project my-workspace --web
"start": {
"options": {
"cwd": ".",
"command": "next start"
"command": "next start",
"continuous": true
},
"dependsOn": ["build"],
"executor": "nx:run-commands",

View File

@ -165,7 +165,8 @@ nx show project my-workspace --web
"dev": {
"options": {
"cwd": ".",
"command": "next dev"
"command": "next dev",
"continuous": true
},
"executor": "nx:run-commands",
"configurations": {},
@ -176,7 +177,8 @@ nx show project my-workspace --web
"start": {
"options": {
"cwd": ".",
"command": "next start"
"command": "next start",
"continuous": true
},
"dependsOn": ["build"],
"executor": "nx:run-commands",

View File

@ -84,7 +84,8 @@ For example, if we migrated the `@nx/vite` plugin for a single app (i.e. `nx g @
"serve": {
"executor": "nx:run-commands",
"options": {
"command": "vite dev"
"command": "vite dev",
"continuous": true
}
},
"build": {

View File

@ -87,7 +87,23 @@ Or they can be [defined per-project](/reference/project-configuration#dependson)
{% /tab %}
{% /tabs %}
## Visualize task dependencies
## 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](/reference/project-configuration#continuous). Labeling a task as continuous tells Nx to not wait for the process to exit, and it will be run alongside its dependents.
```json {% fileName="apps/myapp/project.json" %}
{
"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](/features/explore-graph). This can be useful for debugging purposes.

View File

@ -30,7 +30,8 @@ nx show project myproject --web
"dev": {
"executor": "nx:run-commands",
"options": {
"command": "vite dev"
"command": "vite dev",
"continuous": true
},
"metadata": {
"technologies": ["vite"]
@ -365,10 +366,14 @@ instance, `"dependsOn": ["build"]` of
the `test` target tells Nx that before it can test `mylib` it needs to make sure that `mylib` is built, which will
result in `mylib`'s dependencies being built as well.
{% callout type="note" title="Dependencies that do not exit" %}
If you specify a task in `dependsOn` that never exits, then the dependent task will never start. Label such dependencies as [continuous](#continuous) tasks, which tells Nx to not wait for the process to end before starting the dependent task.
{% /callout %}
You can also express task dependencies with an object syntax:
{% tabs %}
{% tab label="Version 16+ (self)" %}
{% tab label="Dependencies on self" %}
```json
{
@ -386,7 +391,7 @@ You can also express task dependencies with an object syntax:
```
{% /tab %}
{% tab label="Version 16+ (dependencies)" %}
{% tab label="Dependencies on other projects" %}
```json
{
@ -405,7 +410,7 @@ You can also express task dependencies with an object syntax:
```
{% /tab %}
{% tab label="Version 16+ (specific projects)" %}
{% tab label="Dependencies on specific projects" %}
```json
{
@ -423,25 +428,6 @@ You can also express task dependencies with an object syntax:
}
```
{% /tab %}
{% tab label="Version < 16" %}
```json
{
"targets": {
"build": {
"dependsOn": [
{
"projects": "dependencies", // "dependencies" or "self"
"target": "build", // target name
"params": "ignore" // "forward" or "ignore", defaults to "ignore"
}
]
}
}
}
```
{% /tab %}
{% /tabs %}
@ -470,9 +456,6 @@ Starting from v19.5.0, wildcards can be used to define dependencies in the `depe
You can write the shorthand configuration above in the object syntax like this:
{% tabs %}
{% tab label="Version 16+" %}
```json
{
"targets": {
@ -486,30 +469,8 @@ You can write the shorthand configuration above in the object syntax like this:
}
```
{% /tab %}
{% tab label="Version < 16" %}
```json
{
"targets": {
"build": {
"dependsOn": [{ "projects": "dependencies", "target": "build" }]
},
"test": {
"dependsOn": [{ "projects": "self", "target": "build" }]
}
}
}
```
{% /tab %}
{% /tabs %}
With the expanded syntax, you also have a third option available to configure how to handle the params passed to the target. You can either forward them or you can ignore them (default).
{% tabs %}
{% tab label="Version 16+" %}
```json
{
"targets": {
@ -533,40 +494,8 @@ With the expanded syntax, you also have a third option available to configure ho
}
```
{% /tab %}
{% tab label="Version < 16" %}
```json
{
"targets": {
"build": {
// forward params passed to this target to the dependency targets
"dependsOn": [
{ "projects": "dependencies", "target": "build", "params": "forward" }
]
},
"test": {
// ignore params passed to this target, won't be forwarded to the dependency targets
"dependsOn": [
{ "projects": "dependencies", "target": "build", "params": "ignore" }
]
},
"lint": {
// ignore params passed to this target, won't be forwarded to the dependency targets
"dependsOn": [{ "projects": "dependencies", "target": "build" }]
}
}
}
```
{% /tab %}
{% /tabs %}
This also works when defining a relation for the target of the project itself using `"projects": "self"`:
{% tabs %}
{% tab label="Version 16+" %}
```json
{
"targets": {
@ -578,30 +507,8 @@ This also works when defining a relation for the target of the project itself us
}
```
{% /tab %}
{% tab label="Version < 16" %}
```json
{
"targets": {
"build": {
// forward params passed to this target to the project target
"dependsOn": [
{ "projects": "self", "target": "pre-build", "params": "forward" }
]
}
}
}
```
{% /tab %}
{% /tabs %}
Additionally, when using the expanded object syntax, you can specify individual projects in version 16 or greater.
{% tabs %}
{% tab label="Version 16+" %}
```json
{
"targets": {
@ -615,12 +522,42 @@ Additionally, when using the expanded object syntax, you can specify individual
}
```
{% /tab %}
{% /tabs %}
This configuration is usually not needed. Nx comes with reasonable defaults (imported in `nx.json`) which implement the
configuration above.
### Continuous
In Nx 21+, tasks that never exit (sometimes called long-running processes) can be configured with `"continuous": true` to prevent their dependent tasks from waiting for task completion. For example, the `e2e` task depends on a continuous `serve` task to ensure that the development server is running.
In this example, application's configuration labels the `serve` task as continuous.
```json {% fileName="apps/myapp/project.json" %}
{
"targets": {
"serve": {
"continuous": true
}
}
}
```
And the E2E project's `e2e` task has a dependency on the `serve` task, which ensures that the server is running when we run the `e2e` task.
```json {% fileName="apps/myapp-e2e/project.json" %}
{
"targets": {
"e2e": {
"dependsOn": [
{
"projects": "myapp",
"target": "serve"
}
]
}
}
}
```
### Sync Generators
In the same way that `dependsOn` tells Nx to run another task before running this task, the `syncGenerator` property tells Nx to run a generator to ensure that your files are in the correct state before this task is run. [Sync generators](/concepts/sync-generators) are especially useful for keeping configuration files up to date with the project graph. Sync generators are available in Nx 19.8+.