Run Config
You can configure Vite Task under the run field in vite.config.ts. Check out vp run to learn more about running scripts and tasks with Vite+.
import { defineConfig } from 'vite-plus';
export default defineConfig({
run: {
enablePrePostScripts: true,
cache: {
/* ... */
},
tasks: {
/* ... */
},
},
});run.enablePrePostScripts
- Type:
boolean - Default:
true
Whether to automatically run preX/postX package.json scripts as lifecycle hooks when script X is executed.
When enabled (the default), running a script like test will automatically run pretest before it and posttest after it, if they exist in package.json.
export default defineConfig({
run: {
enablePrePostScripts: false, // Disable pre/post lifecycle hooks
},
});WARNING
This option can only be set in the workspace root's vite.config.ts. Setting it in a package's config will result in an error.
run.cache
- Type:
boolean | { scripts?: boolean, tasks?: boolean } - Default:
{ scripts: false, tasks: true }
Controls whether task results are cached and replayed on subsequent runs.
export default defineConfig({
run: {
cache: {
scripts: true, // Cache package.json scripts (default: false)
tasks: true, // Cache task definitions (default: true)
},
},
});cache: true enables both task and script caching, cache: false disables both.
run.tasks
- Type:
Record<string, TaskConfig>
Defines tasks that can be run with vp run <task>.
command
- Type:
string
Defines the shell command to run for the task.
tasks: {
build: {
command: 'vp build',
},
}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 && are automatically split into independently cached sub-tasks. See Compound Commands.
dependsOn
- Type:
string[] - Default:
[]
Tasks that must complete successfully before this one starts.
tasks: {
deploy: {
command: 'deploy-script --prod',
dependsOn: ['build', 'test'],
},
}Dependencies can reference tasks in other packages using the package#task format:
dependsOn: ['@my/core#build', '@my/utils#lint'];See Task Dependencies for details on how explicit and topological dependencies interact.
cache
- Type:
boolean - Default:
true
Whether to cache this task's output. Set to false for tasks that should never be cached, like dev servers:
tasks: {
dev: {
command: 'vp dev',
cache: false,
},
}env
- Type:
string[] - Default:
[]
Environment variables included in the cache fingerprint. When any listed variable's value changes, the cache is invalidated.
tasks: {
build: {
command: 'vp build',
env: ['NODE_ENV'],
},
}Wildcard patterns are supported: VITE_* matches all variables starting with VITE_.
$ NODE_ENV=development vp run build # first run
$ NODE_ENV=production vp run build # cache miss: variable changeduntrackedEnv
- Type:
string[] - Default: see below
Environment variables passed to the task process but not included in the cache fingerprint. Changing these values won't invalidate the cache.
tasks: {
build: {
command: 'vp build',
untrackedEnv: ['CI', 'GITHUB_ACTIONS'],
},
}A set of common environment variables are automatically passed through to all tasks:
- System:
HOME,USER,PATH,SHELL,LANG,TZ - Node.js:
NODE_OPTIONS,COREPACK_HOME,PNPM_HOME - CI/CD:
CI,VERCEL_*,NEXT_* - Terminal:
TERM,COLORTERM,FORCE_COLOR,NO_COLOR
input
- Type:
Array<string | { auto: boolean }> - Default:
[{ auto: true }](auto-inferred)
Vite Task automatically detects which files are used by a command (see Automatic File Tracking). The input option can be used to explicitly include or exclude certain files.
Exclude files from automatic tracking:
tasks: {
build: {
command: 'vp build',
// Use `{ auto: true }` to use automatic fingerprinting (default).
input: [{ auto: true }, '!**/*.tsbuildinfo', '!dist/**'],
},
}Specify explicit files only without automatic tracking:
tasks: {
build: {
command: 'vp build',
input: ['src/**/*.ts', 'vite.config.ts'],
},
}Disable file tracking entirely and cache only on command/env changes:
tasks: {
greet: {
command: 'node greet.mjs',
input: [],
},
}TIP
Glob patterns are resolved relative to the package directory, not the task's cwd.
cwd
- Type:
string - Default: package root
Working directory for the task, relative to the package root.
tasks: {
'test-e2e': {
command: 'vp test',
cwd: 'tests/e2e',
},
}