Skip to content

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

Draft
Tarte12 wants to merge 1 commit into
voidzero-dev:mainfrom
Tarte12:khs_docs-env-prefix
Draft

Tarte12 wants to merge 1 commit into
voidzero-dev:mainfrom
Tarte12:khs_docs-env-prefix

Conversation

@Tarte12

@Tarte12 Tarte12 commented Oct 21, 2026

Copy link
Copy Markdown

Closes #3140

  • Document that FOO=bar command works on Windows without cross-env for commands Vite Task parses directly.
  • Clarify that a prefix applies only to the command it precedes in && chains.
  • Document shell fallback (/bin/sh -c / cmd.exe /d /s /c) and that it applies to the whole command.
  • Fix the command reference, which implied every command runs through a shell.

Behavior is based on the vite-task source (9ba4cc9, linked in the issue). Not tested on Windows.

@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

### 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.

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

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

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

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

@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.

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