Skip to content
Open
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
8 changes: 6 additions & 2 deletions docs/config/run.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,11 @@ Use the object form when a task needs other fields like `cache`, `dependsOn`, or

- **Type:** `string | string[]`

Defines the shell command to run for the task. The string is interpreted by a shell, so spaces, quoting, `&&`, pipes, and redirects all work as written on the command line.
Defines the command to run for the task.

::: info
Vite Task parses simple commands and `&&` chains itself instead of passing them to a shell, so they behave the same on every platform. Other shell syntax, such as pipes or redirects, may behave differently across platforms.
:::

```ts [vite.config.ts]
tasks: {
Expand All @@ -117,7 +121,7 @@ tasks: {

Each task defined in `vite.config.ts` must include its own `command`. You cannot define a task in both `vite.config.ts` and `package.json` with the same task name.

Commands joined with `&&` (or supplied as an array) are automatically split into independently cached sub-tasks. See [Compound Commands](/guide/run#compound-commands).
Array entries, and `&&` chains without other shell syntax, are automatically split into independently cached sub-tasks. See [Compound Commands](/guide/run#compound-commands).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent hyperlink with what guide/run.md uses this. What is the correct one?

[`&&` chains](#compound-commands)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kept the existing See [Compound Commands] link and removed the inline one.


### `dependsOn`

Expand Down
24 changes: 23 additions & 1 deletion docs/guide/run.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
`vpr` is available as a standalone shorthand for `vp run`. All examples below work with both `vp run` and `vpr`.
:::

::: info

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not make it identical to config/run.md? So similar yet different in few words.

Also, can't we use the same block syntax in that file as well? Seems much cleaner.

Defines the command to run for the task.

::: info
...

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Vite Task parses simple commands and `&&` chains itself instead of passing them to a shell, so they behave the same on every platform. Other shell syntax, such as pipes or redirects, may behave differently across platforms.
:::

## Overview

Use `vp run` with existing `package.json` scripts:
Expand Down Expand Up @@ -232,7 +236,7 @@ vp run -w build

## Compound Commands

Commands joined with `&&` are split into independent sub-tasks. Each sub-task is cached separately when [caching is enabled](/guide/cache#when-is-caching-enabled). This works for both `vite.config.ts` tasks and `package.json` scripts:
Commands joined with `&&` are split into independent sub-tasks, unless they also use other shell syntax. Each sub-task is cached separately when [caching is enabled](/guide/cache#when-is-caching-enabled). This works for both `vite.config.ts` tasks and `package.json` scripts:

```json [package.json]
{
Expand Down Expand Up @@ -266,6 +270,24 @@ $ vp build ○ cache miss: 'index.html' modified, executing
vp run: 1/2 cache hit (50%), 2/2 successful, 120ms saved.
```

### Environment Variable Prefixes

Environment variable prefixes such as `FOO=bar command` work on every platform, without extra tools like `cross-env`:

```json [package.json]
{
"scripts": {
"build": "NODE_ENV=production node build.js"
}
}
```

A prefix applies only to the command it directly precedes. In `FOO=1 a && b`, `FOO` is set for `a` but not for `b`.

::: warning
Prefixes may not work on every platform when the command also uses other shell syntax.
:::

### Nested `vp run`

When a command contains `vp run`, Vite Task inlines it as separate tasks instead of spawning a nested process. Each sub-task is cached independently and output stays flat:
Expand Down