GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||
GeezerVison is showing viteplus.dev — Vite+ Are you an LLM? You can read better optimized documentation at /guide/cache.md for this page in Markdown format Task Caching Vite Task can automatically track dependencies and cache tasks run through Overview When a task runs successfully (exit code 0), its terminal output (stdout/stderr) and all written files (output files) are saved. On the next run, Vite Task checks if anything changed:
When all checks match, Vite Task replays the cached terminal output, restores saved output files, and skips the command. When a cache miss occurs, Vite Task tells you exactly why: When Is Caching Enabled? A command run by There are three types of controls for task caching, in order: 1. Per-task |
| Setting | Default | Effect |
|---|---|---|
cache.tasks | true | Cache tasks defined in vite.config.ts |
cache.scripts | false | Cache package.json scripts |
Vite Task uses automatic data tracking to learn what each task needs for caching so you don't have to configure it manually. Automatic data tracking has two tiers:
vp build and vp test both support cooperative tracking.Use cache.input or cache.output when a task needs manual tracking rules. input controls what invalidates the cache. output controls which files Vite Task restores on a cache hit.
tasks: {
build: {
command: 'node build.mjs',
cache: {
input: [{ auto: true }, '!dist/**'],
output: ['dist/**'],
},
},
}By default, tasks run in a clean environment. Only a small set of common variables, such as PATH, HOME, and CI, are passed through. Other environment variables are neither visible to the task nor included in the cache fingerprint.
To add an environment variable to the cache key, add it to cache.env. Changing its value then invalidates the cache:
tasks: {
build: {
command: 'webpack --mode production',
cache: {
env: ['NODE_ENV'],
},
},
}To pass a variable to the task without affecting cache behavior, use cache.untrackedEnv. This is useful for variables like CI or GITHUB_ACTIONS that should be available in the task, but do not affect caching behavior.
See Run Config for details on wildcard patterns and the full list of automatically passed-through variables.
Vite Task's cache is content-based. If two tasks run the same command with the same inputs, they share the cache entry. This happens naturally when multiple tasks include a common step, either as standalone tasks or as parts of compound commands:
{
"scripts": {
"check": "vp lint && vp build",
"release": "vp lint && deploy-script"
}
}With caching enabled, for example through --cache or run.cache.scripts: true, running check first means the vp lint step in release is an instant cache hit, since both run the same command against the same files.
Use vp cache clean when you need to clear cached task results:
vp cache cleanThe task cache is stored in node_modules/.vite/task-cache at the project root. vp cache clean deletes that cache directory.