Skip to content

docs: clarify environment variable prefixes in task commands - #3161

Open
Tarte12 wants to merge 3 commits into
voidzero-dev:mainfrom
Tarte12:khs_docs-env-prefix
Open

Tarte12 wants to merge 3 commits into
voidzero-dev:mainfrom
Tarte12:khs_docs-env-prefix

Conversation

@Tarte12

@Tarte12 Tarte12 commented Oct 21, 2026 •

Copy link
Copy Markdown

Closes #3140

  • Note that Vite Task parses simple commands and && chains itself, so they behave the same on every platform.
  • Document that FOO=bar command works on Windows without cross-env.
  • Clarify that a prefix applies only to the command it directly precedes.
  • Note that && chains are split into cached sub-tasks only when they don't use other shell syntax.
  • Fix the command reference, which implied every command runs through a shell.

Shell fallback details are intentionally left out, per the discussion above.

Verified on Windows 11 with vite-plus 1.4.0: prefixes work in simple commands and && chains and apply only to the next command. With a pipe, the prefix fails under cmd.exe and the && chain is not split into sub-tasks.

@Tarte12 Tarte12 changed the title docs: document env prefixes in task commands docs: clarify environment variable prefixes in task commands Oct 21, 2026
@hyunbinseo

hyunbinseo commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

After reviewing, I think Vite Task should document how it parses commands first, so these docs can link to it instead of describing internals. This goes beyond env prefixes: it decides cross-platform behavior and whether && chains become cached sub-tasks.

I'll open a vite-task issue to spec it alongside task-cache.md.

@jong-kyung

Copy link
Copy Markdown
Collaborator

cc @wan9chi

Comment thread docs/guide/run.md Outdated

### Environment Variable Prefixes

Vite Task parses simple commands and `&&` chains itself, including environment variable prefixes such as `FOO=bar command`. These work on every platform, including Windows, without `cross-env`:

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.

Shouldn't the Vite Task parsing be placed on the top of vpr docs (e.g. as a note block)?

I don't think this explanation applies to "Environment Variable Prefixes" only.

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.

Moved to an info block at the top of the page.

Comment thread docs/guide/run.md Outdated
```json [package.json]
{
"scripts": {
"build": "NODE_ENV=production vp build"

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 use a vanilla non-vp command inside the build script?

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.

Switched to node build.js.

Comment thread docs/guide/run.md Outdated
Comment on lines +281 to +283
A prefix applies only to the command it precedes. In `FOO=1 a && b`, `FOO` is set for `a` but not for `b`.

If any part of a command uses other shell syntax, such as pipes, redirects, or variable expansion, the whole command runs in the system shell instead: `/bin/sh -c` on macOS and Linux, and `cmd.exe /d /s /c` on Windows. In that case, `FOO=bar command` does not work on Windows, so use `cross-env` there.

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.

These seem to be implementation details. It would be nice if Vite Task had documentation of these that can be linked to? Or at least it should be converted to a warning block, etc.

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.

Dropped the shell details and the Vite Task link per the discussion, and replaced them with a short warning that points to cross-env.

Comment thread docs/config/run.md Outdated
- **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. Quoting, `&&`, pipes, and redirects all work as written on the command line. Vite Task runs simple commands and `&&` chains directly, and falls back to the system shell for other shell syntax. See [Environment Variable Prefixes](/guide/run#environment-variable-prefixes) for details.

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.

"Work as written" isn't true on Windows when it falls back to cmd.exe (e.g. single quotes, $VAR). Same as the guide, it'd be nice to link to Vite Task docs for the parsing rules. Until then, how about:

Suggested change
Defines the command to run for the task. Quoting, `&&`, pipes, and redirects all work as written on the command line. Vite Task runs simple commands and `&&` chains directly, and falls back to the system shell for other shell syntax. See [Environment Variable Prefixes](/guide/run#environment-variable-prefixes) for details.
Defines the command to run for the task. Vite Task parses simple commands and `&&` chains itself, so they behave the same on every platform. Other shell syntax, such as pipes and redirects, runs in the system shell: `/bin/sh` on macOS and Linux, and `cmd.exe` on Windows. See [Environment Variable Prefixes](/guide/run#environment-variable-prefixes) for details.

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.

Applied your suggestion without the /bin/sh / cmd.exe part to keep internals out. Verified on Windows; see the updated PR description.

Comment thread docs/config/run.md Outdated
- **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. Quoting, `&&`, pipes, and redirects all work as written on the command line. Vite Task runs simple commands and `&&` chains directly, and falls back to the system shell for other shell syntax. See [Environment Variable Prefixes](/guide/run#environment-variable-prefixes) for details.

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.

Line 120 is now inconsistent: && is only split into cached sub-tasks when parsed, not on shell fallback. Array entries are always split. Maybe update it too?

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.

Updated line 120, and the matching sentence in Compound Commands in the guide.

@hyunbinseo

Copy link
Copy Markdown
Contributor

@jong-kyung How should we proceed? I would love to out-link Vite Task behaviors as mentioned above. The PR can be polished for review once it is decided.

@jong-kyung

Copy link
Copy Markdown
Collaborator

Personally, I think it would be better not to link to the Vite Task docs

@hyunbinseo

Copy link
Copy Markdown
Contributor

Thanks for the quick reply. We'll drop the detailed Vite Task behavior and keep the PR focused on:

  1. Simple commands are parsed by Vite+ (Vite Task) directly.
  2. One benefit: FOO=bar command works on Windows without cross-env.
  3. A prefix applies only to the command it directly precedes. The docs will also note that other behaviors (e.g. shell fallback) exist and should be verified at runtime.

- Move the note that Vite Task parses simple commands to the top of the run guide
- Use a non-`vp` command in the env prefix example
- Replace shell fallback internals with a short warning that points to `cross-env`
- Reword the `command` reference and the `&&` sub-task notes to match

@hyunbinseo hyunbinseo left a comment

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.

  • Consistency. Reuse a single well phrased Vite Task explanation. (e.g. in a blockquote form)
  • Generalization. The vanilla Vite docs does mention dotenv-expand but it's purely because its codes are used. Here, Vite Task handles it by itself. cross-env and Windows can be mentioned as an example but it can be shortened and generalized.

Comment thread docs/config/run.md Outdated
- **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. Vite Task parses simple commands and `&&` chains itself, so they behave the same on every platform. Other shell syntax, such as pipes and redirects, may behave differently across platforms. See [Environment Variable Prefixes](/guide/run#environment-variable-prefixes) for details.

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 drop [Environment Variable Prefixes] hyperlink? It only illustrates a single example.

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.

Dropped.

Comment thread docs/config/run.md
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.

Comment thread docs/guide/run.md
`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.

Comment thread docs/guide/run.md Outdated

### Environment Variable Prefixes

Because Vite Task parses simple commands itself, environment variable prefixes such as `FOO=bar command` work on every platform, including Windows, without `cross-env`:

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.

cross-env is a third party package. Can we emphasize that it's an example?

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.

Changed to "extra tools like cross-env".

Comment thread docs/guide/run.md Outdated
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
If a command also uses other shell syntax, such as pipes or redirects, environment variable prefixes may not work on Windows. Verify such commands at runtime, and use `cross-env` if needed.

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 tighten and make it more general.

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.

Shortened to one line.

@Tarte12

Tarte12 commented Oct 25, 2026

Copy link
Copy Markdown
Author

Thanks! Moved the explanation into a shared info block and generalized the prefix section.

@Tarte12
Tarte12 marked this pull request as ready for review October 25, 2026 05:04
@liangmiQwQ
liangmiQwQ requested a review from wan9chi October 25, 2026 10:38

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Document cross-platform FOO=bar cmd in task commands and scripts

3 participants