Repository navigation
docs: clarify environment variable prefixes in task commands #3161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not make it identical to 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
...
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: | ||
|
|
@@ -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] | ||
| { | ||
|
|
@@ -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: | ||
|
|
||
There was a problem hiding this comment.
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.mduses this. What is the correct one?There was a problem hiding this comment.
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.