Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
2cde346
docs: add CI task cache guide
wan9chi Jun 29, 2026
88f44b6
docs: clarify tool-reported caching
wan9chi Jun 29, 2026
d258867
docs: add tool-reported caching guide
wan9chi Jun 30, 2026
33a293e
docs: remove redundant setup-vp cache flag
wan9chi Jun 30, 2026
583aa1a
docs: unify automatic tracking guidance
wan9chi Jun 30, 2026
4dc8fed
docs: simplify task cache wording
wan9chi Jun 30, 2026
9baaab1
docs: refine automatic tracking wording
wan9chi Jun 30, 2026
f4bcb26
docs: remove redundant tracking link
wan9chi Jun 30, 2026
dfabfbb
docs: pair input and output tracking guidance
wan9chi Jun 30, 2026
574ccf9
docs: simplify automatic tracking wording
wan9chi Jun 30, 2026
6071251
docs: clarify automatic tracking cache behavior
wan9chi Jun 30, 2026
77a87bd
docs: add file tracking limitations
wan9chi Jun 30, 2026
d2ed545
docs: mention env read tracking limit
wan9chi Jun 30, 2026
802248e
docs: clarify automatic tracking limits
wan9chi Jun 30, 2026
0e10778
docs: clarify cooperative tracking support
wan9chi Jun 30, 2026
9681923
docs: clarify vp build cooperative tracking
wan9chi Jun 30, 2026
61539be
docs: clarify vp build manual tracking needs
wan9chi Jun 30, 2026
83788db
docs: show simple vp build tracking config
wan9chi Jun 30, 2026
9c25130
docs: refine automatic tracking limitations
wan9chi Jun 30, 2026
a7c2870
docs: simplify vp build tracking note
wan9chi Jun 30, 2026
d7c8181
docs: clarify input and output overrides
wan9chi Jun 30, 2026
5cffa45
docs: rework cooperative tracking section
wan9chi Jun 30, 2026
5011120
docs: refine cooperative tracking guidance
wan9chi Jun 30, 2026
2232776
docs: refine vp build task wording
wan9chi Jun 30, 2026
a2ba2a1
docs: remove cache miss section from tracking guide
wan9chi Jun 30, 2026
1994686
docs: simplify manual tracking config table
wan9chi Jun 30, 2026
9e92229
docs: add file tracking disable case
wan9chi Jun 30, 2026
2748944
docs: format automatic tracking records
wan9chi Jun 30, 2026
8161fe6
docs: revise automatic tracking guide
wan9chi Jun 30, 2026
2e97080
docs: polish automatic tracking guidance
wan9chi Jun 30, 2026
5b363e1
docs: tighten automatic tracking examples
wan9chi Jun 30, 2026
7ae74ee
docs: simplify GitHub Actions cache tasks
wan9chi Jun 30, 2026
504e6ae
docs: simplify CI task cache setup
wan9chi Jun 30, 2026
987d382
docs: shorten tracking config reference
wan9chi Jun 30, 2026
abb5809
docs: clarify local hit prerequisite
wan9chi Jun 30, 2026
75d1a77
docs: simplify GitHub Actions cache guide
wan9chi Jun 30, 2026
5d44d89
docs: trim CI cache tracking guidance
wan9chi Jun 30, 2026
18eabe9
docs: remove setup-vp cache reference
wan9chi Jun 30, 2026
37e1f91
docs: explain when to skip Actions cache
wan9chi Jun 30, 2026
f439935
docs: add Actions cache eviction guidance
wan9chi Jun 30, 2026
d9ea8fe
docs: emphasize measuring Actions cache value
wan9chi Jun 30, 2026
6ecd7f5
docs: tighten Actions cache guidance
wan9chi Jun 30, 2026
7265c31
docs: polish task cache guidance
wan9chi Jun 30, 2026
442bd9e
docs: refine task cache wording
wan9chi Jun 30, 2026
1c21b7f
docs: simplify Actions cache intro
wan9chi Jun 30, 2026
cf73255
docs: tighten task cache wording
wan9chi Jun 30, 2026
f0fe528
docs: group automatic data tracking under caching
wan9chi Jul 1, 2026
994f7e1
docs: clarify output restoration
wan9chi Jul 1, 2026
75f0f71
docs: explain extending output tracking
wan9chi Jul 1, 2026
ce24fd9
docs: explain disabling output restoration
wan9chi Jul 1, 2026
fd7df85
docs: clarify automatic tracking intro
wan9chi Jul 1, 2026
d77b136
docs: clarify tracked input changes
wan9chi Jul 1, 2026
6417d4d
docs: simplify env tracking guidance
wan9chi Jul 1, 2026
efbe1ed
docs: clarify input and output overrides
wan9chi Jul 1, 2026
b10a957
docs: add input empty example
wan9chi Jul 1, 2026
f7da023
Revert "docs: add input empty example"
wan9chi Jul 1, 2026
888dc9c
docs: restore input empty example
wan9chi Jul 1, 2026
073f50f
docs: clarify vp build task example
wan9chi Jul 1, 2026
3050091
docs: clarify cached output files
wan9chi Jul 1, 2026
310a789
docs: clarify github actions cache warning
wan9chi Jul 1, 2026
abdc11b
docs: clarify local cache hit prerequisite
wan9chi Jul 1, 2026
bdd9135
docs: link stable cache guidance
wan9chi Jul 1, 2026
a1c2d1b
docs: explain measuring ci cache
wan9chi Jul 1, 2026
3491c31
docs: enable setup cache in ci example
wan9chi Jul 1, 2026
ec324fd
docs: clarify dependsOn from
wan9chi Jul 1, 2026
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
4 changes: 4 additions & 0 deletions docs/.vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ const taskRunnerGuideItems = [
{
text: 'Task Caching',
link: '/guide/cache',
items: [
{ text: 'Automatic Data Tracking', link: '/guide/automatic-tracking' },
{ text: 'GitHub Actions Cache', link: '/guide/github-actions-cache' },
],
},
{
text: 'Running Binaries',
Expand Down
73 changes: 61 additions & 12 deletions docs/config/run.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,11 @@ Commands joined with `&&` (or supplied as an array) are automatically split into

### `dependsOn`

- **Type:** `string[]`
- **Type:** `Array<string | { task: string, from: DependsOnFrom }>`
- **Default:** `[]`

`from` accepts the dependency types `"dependencies"`, `"devDependencies"`, `"peerDependencies"`, or an array of those values, such as `["dependencies", "devDependencies"]`.

Tasks that must complete successfully before this one starts.

```ts [vite.config.ts]
Expand All @@ -140,6 +142,19 @@ Dependencies can reference tasks in other packages using the `package#task` form
dependsOn: ['@my/core#build', '@my/utils#lint'];
```

Use the object form `{ task: string, from: DependsOnFrom }` to reference tasks from all dependencies:

```ts [vite.config.ts]
tasks: {
test: {
command: 'vp test',
dependsOn: [{ task: 'build', from: ['dependencies', 'devDependencies'] }],
},
}
```

For the example above, Vite Task reads the declaring package's direct `dependencies` and `devDependencies`, and runs the `build` task in each dependency that defines one. Packages without `build` are skipped.

See [Task Dependencies](/guide/run#task-dependencies) for details on how explicit and topological dependencies interact.

### `cache`
Expand Down Expand Up @@ -168,17 +183,19 @@ Environment variables included in the cache fingerprint. When any listed variabl
```ts [vite.config.ts]
tasks: {
build: {
command: 'vp build',
command: 'node build.mjs',
env: ['NODE_ENV'],
},
}
```

Wildcard patterns are supported: `VITE_*` matches all variables starting with `VITE_`.
Wildcard patterns and `!` exclusion patterns are supported: `VITE_*` matches all variables starting with `VITE_`, and `!VITE_SECRET` excludes the `VITE_SECRET` variable from the match.

For `vp build`, Vite reports Vite environment variables through [automatic tracking](/guide/automatic-tracking#cooperative-tracking). Do not add `VITE_*` or `NODE_ENV` here for a standard Vite build unless your project has extra build behavior Vite cannot report.

```bash
$ NODE_ENV=development vp run build # first run
$ NODE_ENV=production vp run build # cache miss: variable changed
$ NODE_ENV=production vp run build # cache miss: env 'NODE_ENV' changed
```

### `untrackedEnv`
Expand All @@ -191,13 +208,17 @@ Environment variables passed to the task process but **not** included in the cac
```ts [vite.config.ts]
tasks: {
build: {
command: 'vp build',
command: 'node build.mjs',
untrackedEnv: ['CI', 'GITHUB_ACTIONS'],
},
}
```

A set of common environment variables are automatically passed through to all tasks:
`untrackedEnv` accepts the same wildcard and `!` exclusion patterns as [`env`](#env).

Do not put a variable in `untrackedEnv` if its value changes the task result. If a cache-reporting tool covers the variable through [automatic tracking](/guide/automatic-tracking#cooperative-tracking), leave it out of both `env` and `untrackedEnv`.

Vite Task passes a set of common environment variables to all tasks:

- **System:** `HOME`, `USER`, `PATH`, `SHELL`, `LANG`, `TZ`
- **Node.js:** `NODE_OPTIONS`, `COREPACK_HOME`, `PNPM_HOME`
Expand All @@ -209,7 +230,7 @@ A set of common environment variables are automatically passed through to all ta
- **Type:** `Array<string | { auto: boolean } | { pattern: string, base: "workspace" | "package" }>`
- **Default:** `[{ auto: true }]` (auto-inferred)

Vite Task automatically detects which files are used by a command (see [Automatic File Tracking](/guide/cache#automatic-file-tracking)). The `input` option can be used to explicitly include or exclude certain files.
Vite Task automatically detects which files a command uses. See [Automatic Data Tracking](/guide/automatic-tracking) for the details and when to add manual config.

**Exclude files** from automatic tracking:

Expand Down Expand Up @@ -270,26 +291,41 @@ String glob patterns are resolved relative to the package directory by default.

### `output`

- **Type:** `Array<string | { pattern: string, base: "workspace" | "package" }>`
- **Default:** `[]` (nothing is archived)
- **Type:** `Array<string | { auto: boolean } | { pattern: string, base: "workspace" | "package" }>`
- **Default:** automatic write tracking

Vite Task automatically archives files generated by a successful task run and restores them on a cache hit.

Files the task produces. They get archived after a successful run and restored on a cache hit, so you don't have to rebuild them. Leave it empty (or omit it) and nothing is archived.
If you omit `output`, Vite Task uses automatic write tracking to choose those files. Add explicit `output` entries when you need to override which files are restored.

```ts [vite.config.ts]
tasks: {
build: {
command: 'vp build',
command: 'node build.mjs',
output: ['dist/**', '!dist/cache/**'],
},
}
```

Use `{ auto: true }` to keep automatic write tracking while adding explicit output globs.

This is useful when a task writes files that should not be restored from the cache. For example, exclude TypeScript `.tsbuildinfo` files:

```ts [vite.config.ts]
tasks: {
typecheck: {
command: 'tsc --build',
output: [{ auto: true }, '!*.tsbuildinfo'],
},
}
```

If a task writes outside its own package, use the object form with `base: "workspace"`:

```ts [vite.config.ts]
tasks: {
build: {
command: 'vp build',
command: 'node build.mjs',
output: [
'dist/**',
{ pattern: 'shared-artifacts/**', base: 'workspace' },
Expand All @@ -298,6 +334,19 @@ tasks: {
}
```

Set `output: []` to disable output restoration for a cached task:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why is this desirable over disabling the cache?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Could be useful for local-only cache where outputs are already there. Added this use case in ce24fd9.


```ts [vite.config.ts]
tasks: {
report: {
command: 'node scripts/report.mjs',
output: [],
},
}
```

Unlike `cache: false`, `output: []` still lets Vite Task fingerprint the task. On a cache hit, Vite Task skips the command and replays its terminal output. Use this for local caches when the task's output files are already there and do not need to be restored.

### `cwd`

- **Type:** `string`
Expand Down
145 changes: 145 additions & 0 deletions docs/guide/automatic-tracking.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
# Automatic Data Tracking

Automatic data tracking is how Vite Task learns what inputs a task needs for caching outputs without explicit config.

When you run a cache-enabled task, Vite Task observes the task's execution and records what files were read and written, as well as any metadata reported by the task. On the next run, Vite Task uses the recorded fingerprint to decide whether to replay the cache or run the task.

Use this page when you need to understand why a task hits or misses the cache, or when you need to decide whether to add `input`, `output`, `env`, or `untrackedEnv` config.

## Tracking Tiers

Automatic data tracking has two tiers:

| Tier | Applies to | Records |
| -------------------- | ---------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| File system tracking | All tasks with cache enabled | <ul><li>Files read by the command</li><li>Missing-file probes</li><li>Directory listings</li><li>Written output files</li></ul> |
| Cooperative tracking | Cache-reporting tools (`vp build` today) | <ul><li>Environment variables reported by the tool</li><li>Tool-managed paths that should not be inputs or outputs, such as `node_modules/.vite-temp`</li></ul> |

Vite Task starts with file system tracking for any command. A cache-reporting tool can add information that only the tool knows while it runs.

## File System Tracking

File system tracking applies to every cache-enabled task. If you omit [`input`](/config/run#input), Vite Task tracks the files a command reads while it runs:

```ts [vite.config.ts]
import { defineConfig } from 'vite-plus';

export default defineConfig({
run: {
tasks: {
build: {
command: 'tsc',
},
},
},
});
```

For this task, Vite Task records source files, config files, missing files the command checked, and directories the command scanned. Subsequent runs re-run the task when one of those tracked inputs changes.

File system tracking also tracks outputs. If you omit [`output`](/config/run#output), Vite Task archives files the command writes after a successful run and restores them on a cache hit.

### Limitations

Vite Task cannot track environment variable reads, and it cannot always tell which tracked paths are stable inputs, generated outputs, or tool-managed cache paths that should not become inputs or outputs.

Use [Override Inputs And Outputs](#override-inputs-and-outputs) when file system tracking includes files that should not affect the cache, misses files that should, or restores the wrong outputs.

Use [`env`](/config/run#env) when a command needs an environment variable and the value should affect the cache, or [`untrackedEnv`](/config/run#untrackedenv) when the value should not affect the cache.

These limitations do not apply to `vp build`: Vite reports [Cooperative Tracking](#cooperative-tracking) metadata automatically, including `VITE_*`, `NODE_ENV`, and Vite-managed cache paths that should not become inputs or outputs. A standard `vp build` task does not need manual `input`, `output`, or `env`.

### Override Inputs And Outputs

[`input`](/config/run#input) controls what invalidates the cache. [`output`](/config/run#output) controls which files Vite Task restores on a cache hit.

Both options use the same syntax and can be configured separately.

- Omit the option to keep automatic tracking.
- Add `{ auto: true }` to keep automatic tracking while adding glob rules.
- Use string globs to include paths.
- Use `!` globs to exclude paths.
- Use `[]` to replace automatic tracking with an empty list.

```ts [vite.config.ts]
tasks: {
build: {
command: 'node build.mjs',

// Keep automatic input tracking, but exclude `dist` from inputs.
input: [{ auto: true }, '!dist/**'],

// Disable automatic output tracking and restore only `dist/**` on a cache hit.
output: ['dist/**'],
},
}
```

Use explicit `input` globs only when you know the command's full input set. This lint task overrides inputs only, so output tracking stays automatic:

```ts [vite.config.ts]
tasks: {
lint: {
command: 'vp lint',
// Disable automatic input tracking and fingerprint only these files.
input: ['src/**', 'vite.config.ts'],
},
}
```

Set `input: []` when no files should affect the cache fingerprint. This is rarely useful. For example, a download task can be cached when the same URL always serves the same file. No input files should be fingerprinted for this task, but changing the URL still invalidates the cache:

```ts [vite.config.ts]
tasks: {
downloadSchema: {
command: 'curl -O https://example.com/schema.json',
input: [],
},
}
```

Set `output: []` when no files should be restored on a cache hit.

## Cooperative Tracking

File system tracking records access. It cannot know why a tool used each path.

`vp build` knows more about a Vite build than Vite Task can infer from file access. When `vp build` runs with cache enabled, Vite reports that metadata to Vite Task. Vite Task merges the report with file system tracking to build a more accurate cache fingerprint.

For a standard Vite build, you do not need to add these entries yourself because Vite reports them automatically at runtime:

- `env: ['VITE_*']` or `env: ['NODE_ENV']`
- `output: ['dist/**']`
- input or output exclusions for temporary paths like `node_modules/.vite-temp`

You only need to define the task with `vp build`:

```ts [vite.config.ts]
import { defineConfig } from 'vite-plus';

export default defineConfig({
run: {
tasks: {
frontendBuild: 'vp build',
},
},
});
Comment on lines +120 to +126

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is where Vite+ becomes incredibly confusing because you get a cache hit with vpr build but never with vp build. It would be great if we could add caching to vp build and vp pack through a config option instead.

It might also make sense to rename the task name here to something like "frontendBuild" and then explain it can be run with vpr frontendBuild or similar.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We decided not to cache non-run subcommands, but I did hear feedbacks about this confusion. #2011 is logged. Let's revisit it later.

Task name updated in 073f50f.

```

Run this task with `vpr frontendBuild` or `vp run frontendBuild`.

Manual config overrides reported metadata. Add `input`, `output`, `env`, or `untrackedEnv` when your project has behavior that Vite cannot report.

Vite+ supports cooperative tracking for `vp build` today. It will extend this support to more first-party tools in the future. Third-party tools can report cache metadata with [`@voidzero-dev/vite-task-client`](https://npmx.dev/package/@voidzero-dev/vite-task-client).

## When To Add Manual Config

Add config when your project has behavior the command or tool cannot know.

| Case | Example |
| ----------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- |
| Exclude an output directory from inputs | `input: [{ auto: true }, '!dist/**']` |
| Exclude a temporary generated file from input and output tracking | `input: [{ auto: true }, '!.tmp/config.mjs']`<br>`output: [{ auto: true }, '!.tmp/config.mjs']` |
| Avoid automatic file tracking for a task | `input: ['src/**']`<br>`output: ['dist/**']` |
| Track and pass an env var | `env: ['NODE_ENV']` |
| Pass an env var without fingerprinting it | `untrackedEnv: ['GITHUB_ACTIONS']` |
Loading
Loading