docs(core): common tasks page (#29376)

Create a common task names concept page.

The main purpose of this page is to have a good search result for people
searching for "build", "test" or "lint" in our docs search. These terms
are regularly in the top 10 most searched terms.
This commit is contained in:
Isaac Mann 2024-12-17 11:06:05 -05:00 committed by GitHub
parent ee4de0b3ac
commit 1963a0cf27
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 327 additions and 0 deletions

View File

@ -606,6 +606,14 @@
"children": [], "children": [],
"disableCollapsible": false "disableCollapsible": false
}, },
{
"name": "Common Tasks",
"path": "/concepts/common-tasks",
"id": "common-tasks",
"isExternal": false,
"children": [],
"disableCollapsible": false
},
{ {
"name": "Nx Daemon", "name": "Nx Daemon",
"path": "/concepts/nx-daemon", "path": "/concepts/nx-daemon",
@ -811,6 +819,14 @@
"children": [], "children": [],
"disableCollapsible": false "disableCollapsible": false
}, },
{
"name": "Common Tasks",
"path": "/concepts/common-tasks",
"id": "common-tasks",
"isExternal": false,
"children": [],
"disableCollapsible": false
},
{ {
"name": "Nx Daemon", "name": "Nx Daemon",
"path": "/concepts/nx-daemon", "path": "/concepts/nx-daemon",

View File

@ -831,6 +831,17 @@
"path": "/concepts/executors-and-configurations", "path": "/concepts/executors-and-configurations",
"tags": ["run-tasks"] "tags": ["run-tasks"]
}, },
{
"id": "common-tasks",
"name": "Common Tasks",
"description": "",
"mediaImage": "",
"file": "shared/concepts/common-tasks",
"itemList": [],
"isExternal": false,
"path": "/concepts/common-tasks",
"tags": ["run-tasks"]
},
{ {
"id": "nx-daemon", "id": "nx-daemon",
"name": "Nx Daemon", "name": "Nx Daemon",
@ -1113,6 +1124,17 @@
"path": "/concepts/executors-and-configurations", "path": "/concepts/executors-and-configurations",
"tags": ["run-tasks"] "tags": ["run-tasks"]
}, },
"/concepts/common-tasks": {
"id": "common-tasks",
"name": "Common Tasks",
"description": "",
"mediaImage": "",
"file": "shared/concepts/common-tasks",
"itemList": [],
"isExternal": false,
"path": "/concepts/common-tasks",
"tags": ["run-tasks"]
},
"/concepts/nx-daemon": { "/concepts/nx-daemon": {
"id": "nx-daemon", "id": "nx-daemon",
"name": "Nx Daemon", "name": "Nx Daemon",

View File

@ -58,6 +58,13 @@
"name": "Executors and Configurations", "name": "Executors and Configurations",
"path": "/concepts/executors-and-configurations" "path": "/concepts/executors-and-configurations"
}, },
{
"description": "",
"file": "shared/concepts/common-tasks",
"id": "common-tasks",
"name": "Common Tasks",
"path": "/concepts/common-tasks"
},
{ {
"description": "", "description": "",
"file": "shared/recipes/running-tasks/configure-inputs", "file": "shared/recipes/running-tasks/configure-inputs",

View File

@ -236,6 +236,12 @@
"tags": ["run-tasks"], "tags": ["run-tasks"],
"file": "shared/concepts/executors-and-configurations" "file": "shared/concepts/executors-and-configurations"
}, },
{
"name": "Common Tasks",
"id": "common-tasks",
"tags": ["run-tasks"],
"file": "shared/concepts/common-tasks"
},
{ {
"name": "Nx Daemon", "name": "Nx Daemon",
"id": "nx-daemon", "id": "nx-daemon",

View File

@ -0,0 +1,275 @@
# Common Tasks
The tasks that are [inferred by plugins](/concepts/inferred-tasks) or that you define in your [project configuration](/reference/project-configuration) can have any name that you want, but it is helpful for developers if you keep your task naming convention consistent across the projects in your repository. This way, if a developer moves from one project to another, they already know how to launch tasks for the new project. Here are some common task names that you can define for your projects.
## `build`
This task should produce the compiled output of this project. Typically, you'll want to have `build` tasks depend on the `build` tasks of project dependencies across the whole repository. You can set this default in the `nx.json` file like this:
```json {% fileName="nx.json" %}
{
"targetDefaults": {
"build": {
"dependsOn": ["^build"]
}
}
}
```
The task might use the [@nx/vite](/nx-api/vite), [@nx/webpack](/nx-api/webpack) or [@nx/rspack](/nx-api/rspack) plugins. Or you could have the task launch your own custom script.
{% tabs %}
{% tab label="Vite" %}
Set up an [inferred](/concepts/inferred-tasks) `build` task for every project that has a Vite configuration file with this configuration in `nx.json`:
```json {% fileName="nx.json" %}
{
"plugins": [
{
"plugin": "@nx/vite/plugin",
"options": {
"buildTargetName": "build"
}
}
]
}
```
You can also [override the inferred task configuration](/concepts/inferred-tasks#overriding-inferred-task-configuration) as needed.
{% /tab %}
{% tab label="Webpack" %}
Set up an [inferred](/concepts/inferred-tasks) `build` task for every project that has a Webpack configuration file with this configuration in `nx.json`:
```json {% fileName="nx.json" %}
{
"plugins": [
{
"plugin": "@nx/webpack/plugin",
"options": {
"buildTargetName": "build"
}
}
]
}
```
You can also [override the inferred task configuration](/concepts/inferred-tasks#overriding-inferred-task-configuration) as needed.
{% /tab %}
{% tab label="rspack" %}
Set up an [inferred](/concepts/inferred-tasks) `build` task for every project that has an rspack configuration file with this configuration in `nx.json`:
```json {% fileName="nx.json" %}
{
"plugins": [
{
"plugin": "@nx/rspack/plugin",
"options": {
"buildTargetName": "build"
}
}
]
}
```
You can also [override the inferred task configuration](/concepts/inferred-tasks#overriding-inferred-task-configuration) as needed.
{% /tab %}
{% tab label="Custom Script" %}
You can define your own `build` task in your project configuration. Here is an example that uses `ts-node` to run a node script.
```json {% fileName="packages/my-project/package.json" %}
{
"scripts": {
"build": "ts-node build-script.ts"
}
}
```
{% /tab %}
{% /tabs %}
## `serve`
This task should run your project in a developer preview mode. The task might use the [@nx/vite](/nx-api/vite), [@nx/webpack](/nx-api/webpack) or [@nx/rspack](/nx-api/rspack) plugins. Or you could have the task launch your own custom script.
{% tabs %}
{% tab label="Vite" %}
Set up an [inferred](/concepts/inferred-tasks) `serve` task for every project that has a Vite configuration file with this configuration in `nx.json`:
```json {% fileName="nx.json" %}
{
"plugins": [
{
"plugin": "@nx/vite/plugin",
"options": {
"serveTargetName": "serve"
}
}
]
}
```
You can also [override the inferred task configuration](/concepts/inferred-tasks#overriding-inferred-task-configuration) as needed.
{% /tab %}
{% tab label="Webpack" %}
Set up an [inferred](/concepts/inferred-tasks) `serve` task for every project that has a Webpack configuration file with this configuration in `nx.json`:
```json {% fileName="nx.json" %}
{
"plugins": [
{
"plugin": "@nx/webpack/plugin",
"options": {
"serveTargetName": "serve"
}
}
]
}
```
You can also [override the inferred task configuration](/concepts/inferred-tasks#overriding-inferred-task-configuration) as needed.
{% /tab %}
{% tab label="rspack" %}
Set up an [inferred](/concepts/inferred-tasks) `serve` task for every project that has an rspack configuration file with this configuration in `nx.json`:
```json {% fileName="nx.json" %}
{
"plugins": [
{
"plugin": "@nx/rspack/plugin",
"options": {
"serveTargetName": "serve"
}
}
]
}
```
You can also [override the inferred task configuration](/concepts/inferred-tasks#overriding-inferred-task-configuration) as needed.
{% /tab %}
{% tab label="Custom Script" %}
You can define your own `serve` task in your project configuration. Here is an example that uses `ts-node` to run the entry point of your project.
```json {% fileName="packages/my-project/package.json" %}
{
"scripts": {
"serve": "ts-node main.ts"
}
}
```
{% /tab %}
{% /tabs %}
## `test`
This task typically runs unit tests for a project. The task might use the [@nx/vite](/nx-api/vite) or [@nx/jest](/nx-api/jest) plugins. Or you could have the task launch your own custom script.
{% tabs %}
{% tab label="Vitest" %}
Set up an [inferred](/concepts/inferred-tasks) `test` task for every project that has a Vitest configuration file with this configuration in `nx.json`:
```json {% fileName="nx.json" %}
{
"plugins": [
{
"plugin": "@nx/vite/plugin",
"options": {
"testTargetName": "test"
}
}
]
}
```
You can also [override the inferred task configuration](/concepts/inferred-tasks#overriding-inferred-task-configuration) as needed.
{% /tab %}
{% tab label="Jest" %}
Set up an [inferred](/concepts/inferred-tasks) `test` task for every project that has a Jest configuration file with this configuration in `nx.json`:
```json {% fileName="nx.json" %}
{
"plugins": [
{
"plugin": "@nx/jest/plugin",
"options": {
"targetName": "test"
}
}
]
}
```
You can also [override the inferred task configuration](/concepts/inferred-tasks#overriding-inferred-task-configuration) as needed.
{% /tab %}
{% tab label="Custom Script" %}
You can define your own `test` task in your project configuration. Here is an example that runs the `ava` test tool.
```json {% fileName="packages/my-project/package.json" %}
{
"scripts": {
"test": "ava"
}
}
```
{% /tab %}
{% /tabs %}
## `lint`
This task should run lint rules for a project. The task might use the [@nx/eslint](/nx-api/eslint) plugin or run your own custom script.
{% tabs %}
{% tab label="ESLint" %}
Set up an [inferred](/concepts/inferred-tasks) `lint` task for every project that has an ESLint configuration file with this configuration in `nx.json`:
```json {% fileName="nx.json" %}
{
"plugins": [
{
"plugin": "@nx/eslint/plugin",
"options": {
"targetName": "lint"
}
}
]
}
```
You can also [override the inferred task configuration](/concepts/inferred-tasks#overriding-inferred-task-configuration) as needed.
{% /tab %}
{% tab label="Custom Script" %}
You can define your own `lint` task in your project configuration. Here is an example that runs the `sonarts` lint tool.
```json {% fileName="packages/my-project/package.json" %}
{
"scripts": {
"lint": "sonarts"
}
}
```
{% /tab %}
{% /tabs %}

View File

@ -30,6 +30,7 @@
- [Inferred Tasks](/concepts/inferred-tasks) - [Inferred Tasks](/concepts/inferred-tasks)
- [Types of Configuration](/concepts/types-of-configuration) - [Types of Configuration](/concepts/types-of-configuration)
- [Executors and Configurations](/concepts/executors-and-configurations) - [Executors and Configurations](/concepts/executors-and-configurations)
- [Common Tasks](/concepts/common-tasks)
- [Nx Daemon](/concepts/nx-daemon) - [Nx Daemon](/concepts/nx-daemon)
- [Sync Generators](/concepts/sync-generators) - [Sync Generators](/concepts/sync-generators)
- [Nx and Turborepo](/concepts/turbo-and-nx) - [Nx and Turborepo](/concepts/turbo-and-nx)