Skip to content

Commit

Permalink
docs(core): explain root level tasks in project.json (nrwl#27151)
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacplmann authored Jul 26, 2024
1 parent 5e4f05c commit 719c6a5
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions docs/shared/features/run-tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,10 @@ Learn all the details:

## Run Root-Level Tasks

Sometimes you have tasks that apply to the entire codebase rather than to a single project. But you still want those tasks to go through the "Nx pipeline" in order to benefit from caching. You can define these in the root-level `package.json` as follows:
Sometimes you have tasks that apply to the entire codebase rather than to a single project. But you still want those tasks to go through the "Nx pipeline" in order to benefit from caching. You can define these in the root-level `package.json` or `project.json` as follows:

{% tabs %}
{% tab label="package.json" %}

```json {% fileName="package.json" %}
{
Expand All @@ -149,12 +152,6 @@ Sometimes you have tasks that apply to the entire codebase rather than to a sing

> Note the `nx: {}` property on the `package.json`. This is necessary to inform Nx about this root-level project. The property can also be expanded to specify cache inputs and outputs.
To invoke it, use:

```shell
npx nx docs
```

If you want Nx to cache the task, but prefer to use npm (or pnpm/yarn) to run the script (i.e. `npm run docs`) you can use the [nx exec](/nx-api/nx/documents/exec) command:

```json {% fileName="package.json" %}
Expand All @@ -167,4 +164,28 @@ If you want Nx to cache the task, but prefer to use npm (or pnpm/yarn) to run th
}
```

{% /tab %}
{% tab label="project.json" %}

```json {% fileName="project.json"%}
{
"name": "myorg",
...
"targets": {
"docs": {
"command": "node ./generateDocsSite.js"
}
}
}
```

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

To invoke the task, use:

```shell
npx nx docs
```

Learn more about root-level tasks [in our dedicated recipe page](/recipes/running-tasks/root-level-scripts).

0 comments on commit 719c6a5

Please sign in to comment.