Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions docs/shared/concepts/myreactapp.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"serve": {
"options": {
"cwd": "apps/myreactapp",
"command": "vite serve"
"command": "vite serve",
"continuous": true
},
"executor": "nx:run-commands",
"configurations": {},
Expand All @@ -51,7 +52,8 @@
"serve-static": {
"executor": "@nx/web:file-server",
"options": {
"buildTarget": "build"
"buildTarget": "build",
"continuous": true
},
"configurations": {}
},
Expand Down
6 changes: 4 additions & 2 deletions docs/shared/migration/adding-to-existing-project.md
Original file line number Diff line number Diff line change
Expand Up @@ -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": {},
Expand All @@ -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",
Expand Down
6 changes: 4 additions & 2 deletions docs/shared/migration/adding-to-monorepo.md
Original file line number Diff line number Diff line change
Expand Up @@ -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": {},
Expand All @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion docs/shared/recipes/running-tasks/convert-to-inferred.md
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
18 changes: 17 additions & 1 deletion docs/shared/recipes/running-tasks/defining-task-pipeline.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
133 changes: 35 additions & 98 deletions docs/shared/reference/project-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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
{
Expand All @@ -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
{
Expand All @@ -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
{
Expand All @@ -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 %}

Expand Down Expand Up @@ -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": {
Expand All @@ -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": {
Expand All @@ -533,94 +494,70 @@ With the expanded syntax, you also have a third option available to configure ho
}
```

{% /tab %}
{% tab label="Version < 16" %}
This also works when defining a relation for the target of the project itself using `"projects": "self"`:

```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" }]
// forward params passed to this target to the project target
"dependsOn": [{ "target": "pre-build", "params": "forward" }]
}
}
}
```

{% /tab %}
{% /tabs %}

This also works when defining a relation for the target of the project itself using `"projects": "self"`:

{% tabs %}
{% tab label="Version 16+" %}
Additionally, when using the expanded object syntax, you can specify individual projects in version 16 or greater.

```json
{
"targets": {
"build": {
// forward params passed to this target to the project target
"dependsOn": [{ "target": "pre-build", "params": "forward" }]
// Run is-even:pre-build and is-odd:pre-build before this target
"dependsOn": [
{ "projects": ["is-even", "is-odd"], "target": "pre-build" }
]
}
}
}
```

{% /tab %}
{% tab label="Version < 16" %}
This configuration is usually not needed. Nx comes with reasonable defaults (imported in `nx.json`) which implement the
configuration above.

```json
### 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": {
"build": {
// forward params passed to this target to the project target
"dependsOn": [
{ "projects": "self", "target": "pre-build", "params": "forward" }
]
"serve": {
"continuous": true
}
}
}
```

{% /tab %}
{% /tabs %}

Additionally, when using the expanded object syntax, you can specify individual projects in version 16 or greater.

{% tabs %}
{% tab label="Version 16+" %}
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
```json {% fileName="apps/myapp-e2e/project.json" %}
{
"targets": {
"build": {
// Run is-even:pre-build and is-odd:pre-build before this target
"e2e": {
"dependsOn": [
{ "projects": ["is-even", "is-odd"], "target": "pre-build" }
{
"projects": "myapp",
"target": "serve"
}
]
}
}
}
```

{% /tab %}
{% /tabs %}

This configuration is usually not needed. Nx comes with reasonable defaults (imported in `nx.json`) which implement the
configuration above.

### 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+.
Expand Down
Loading