diff --git a/docs/config/run.md b/docs/config/run.md index 73b03cceb1..284e1ae4b0 100644 --- a/docs/config/run.md +++ b/docs/config/run.md @@ -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: { @@ -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). ### `dependsOn` diff --git a/docs/guide/run.md b/docs/guide/run.md index b6458da81e..a39055dd1c 100644 --- a/docs/guide/run.md +++ b/docs/guide/run.md @@ -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 +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: