Skip to content

Commit

Permalink
docs(core): improve outputs documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenPandaz committed Jul 14, 2022
1 parent 59fb331 commit 0074e37
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 8 deletions.
47 changes: 42 additions & 5 deletions docs/shared/configuration/packagejson.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,49 @@ sources (non-test sources) of its dependencies. In other words, it treats test s
### outputs
`"outputs": ["dist/libs/mylib"]` tells Nx where the `build` target is going to create file artifacts. The provided value
is actually the default, so we can omit it in this case. `"outputs": []` tells Nx that the `test` target doesn't create
any artifacts on disk.
Targets may define outputs to tell Nx where the target is going to create file artifacts that Nx should cache. `"outputs": ["dist/libs/mylib"]` tells Nx where the `build` target is going to create file artifacts.
This configuration is usually not needed. Nx comes with reasonable defaults (imported in `nx.json`) which implement the
configuration above.
This configuration is usually not needed. Nx comes with reasonable defaults (imported in `nx.json`) which implement the configuration above.
#### Basic Example
Usually, a target writes to a specific directory or a file. The following instructs Nx to cache `dist/libs/mylib` and `build/libs/mylib/main.js`:
```json
{
"build": {
"outputs": ["dist/libs/mylib", "build/libs/mylib/main.js"]
}
}
```
#### Specifying Globs
Sometimes, multiple targets might write to the same directory. When possible it is recommended to direct these targets into separate directories.
```json
{
"build-js": {
"outputs": ["dist/libs/mylib/js"]
},
"build-css": {
"outputs": ["dist/libs/mylib/css"]
}
}
```
But if the above is not possible, globs can be specified as outputs to only cache a set of files rather than the whole directory.
```json
{
"build-js": {
"outputs": ["dist/libs/mylib/**/*.js"]
},
"build-css": {
"outputs": ["dist/libs/mylib/**/*.css"]
}
}
```
### dependsOn
Expand Down
82 changes: 79 additions & 3 deletions docs/shared/configuration/projectjson.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,85 @@ sources (non-test sources) of its dependencies. In other words, it treats test s

### Outputs

`"outputs": ["dist/libs/mylib"]` tells Nx where the `build` target is going to create file artifacts. The provided value
is actually the default, so we can omit it in this case. `"outputs": []` tells Nx that the `test` target doesn't create
any artifacts on disk.
Targets may define outputs to tell Nx where the target is going to create file artifacts that Nx should cache. `"outputs": ["dist/libs/mylib"]` tells Nx where the `build` target is going to create file artifacts.

#### Basic Example

Usually, a target writes to a specific directory or a file. The following instructs Nx to cache `dist/libs/mylib` and `build/libs/mylib/main.js`:

```json
{
"build": {
...,
"outputs": ["dist/libs/mylib", "build/libs/mylib/main.js"],
"options": {
...
},
}
}
```

#### Referencing Options

Most commonly, targets have an option for an output file or directory. Rather than duplicating the information as seen above, options can be referenced using the below syntax:

> When the `outputPath` option is changed, Nx will start caching the new path as well.
```json
{
"build": {
...,
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/libs/mylib"
}
}
}
```

#### Specifying Globs

Sometimes, multiple targets might write to the same directory. When possible it is recommended to direct these targets into separate directories.

```json
{
"build-js": {
...,
"outputs": ["dist/libs/mylib/js"],
"options": {
"outputPath": "dist/libs/mylib/js"
}
},
"build-css": {
...,
"outputs": ["dist/libs/mylib/css"],
"options": {
"outputPath": "dist/libs/mylib/css"
}
}
}
```

But if the above is not possible, globs can be specified as outputs to only cache a set of files rather than the whole directory.

```json
{
"build-js": {
...,
"outputs": ["dist/libs/mylib/**/*.js"],
"options": {
"outputPath": "dist/libs/mylib"
}
},
"build-css": {
...,
"outputs": ["dist/libs/mylib/**/*.css"],
"options": {
"outputPath": "dist/libs/mylib"
}
}
}
```

### dependsOn

Expand Down

0 comments on commit 0074e37

Please sign in to comment.