Skip to content

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+.

vite.config.ts
ts
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.

vite.config.ts
ts
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, remote?: { url?: string, headers?: Record<string, string | undefined> } }
  • Default: { scripts: false, tasks: true }

Controls whether task results are cached and replayed on subsequent runs.

vite.config.ts
ts
export default defineConfig({
  run: {
    cache: {
      scripts: true, // Cache package.json scripts (default: false)
      tasks: true, // Cache task definitions (default: true)
      remote: {
        url: 'https://cache.example.com/projects/my-app',
      },
    },
  },
});

cache: true enables both task and script caching, cache: false disables both.

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.remote ​

  • Type: { url?: string, headers?: Record<string, string | undefined> }

Experimental

Remote caching is experimental and currently intended for sharing task outputs across CI runs (sharing with developer machines is not supported yet). Configuration options, runtime behavior, and HTTP APIs are subject to change.

Configures remote caching so vp run can share cached task outputs across CI runs.

When a remote endpoint is configured (via run.cache.remote.url or VP_REMOTE_CACHE_URL), vp run defaults to read mode (downloads cache hits without uploading). Enable uploads in trusted CI with VP_REMOTE_CACHE=read-write or --remote-cache read-write, or disable remote caching with off. Remote cache errors are non-fatal; inspect details with vp run --last-details.

vite.config.ts
ts
export default defineConfig({
  run: {
    cache: {
      remote: {
        url: 'https://cache.example.com/projects/my-app',
        headers: {
          'CF-Access-Client-Id': process.env.CF_ACCESS_CLIENT_ID,
          'CF-Access-Client-Secret': process.env.CF_ACCESS_CLIENT_SECRET,
        },
      },
    },
  },
});

run.cache.remote.url ​

  • Type: string

HTTP or HTTPS namespace endpoint for the remote cache (for example, https://cache.example.com/projects/my-app).

Optional if VP_REMOTE_CACHE_URL is set in the environment. When both are set, VP_REMOTE_CACHE_URL overrides run.cache.remote.url.

run.cache.remote.headers ​

  • Type: Record<string, string | undefined>

Extra HTTP headers sent on all remote cache requests (both reads and writes). Entries with undefined values are omitted, while empty strings ('') are preserved.

Never hardcode secrets in vite.config.ts. For credentials, either pass VP_REMOTE_CACHE_HEADER_<NAME> environment variables directly, or read process.env in vite.config.ts (unset variables evaluate to undefined and are automatically omitted):

vite.config.ts
ts
headers: {
  'CF-Access-Client-Id': process.env.CF_ACCESS_CLIENT_ID,
  'CF-Access-Client-Secret': process.env.CF_ACCESS_CLIENT_SECRET,
  Authorization: process.env.REMOTE_CACHE_TOKEN
    ? `Bearer ${process.env.REMOTE_CACHE_TOKEN}`
    : undefined,
}

Headers can also be set or overridden via VP_REMOTE_CACHE_HEADER_<NAME> environment variables, where underscores map to hyphens (for example, VP_REMOTE_CACHE_HEADER_CF_ACCESS_CLIENT_ID sends CF-Access-Client-Id). Environment headers override matching entries in run.cache.remote.headers.

Setting an Authorization header disables automatic GitHub Actions OIDC authentication. Setting HTTP transport or framing headers (such as Host, Content-Type, Content-Length, or Transfer-Encoding) fails with a configuration error because they are managed by the HTTP client.

run.tasks ​

  • Type: Record<string, Task | string | string[]>

Defines tasks that can be run with vp run <task>.

As a shorthand, a task value can be a command string or an array of command strings directly:

vite.config.ts
ts
tasks: {
  build: 'vp build',
  check: ['vp lint', 'vp build'],
}

These are equivalent to setting only command on a task config:

vite.config.ts
ts
tasks: {
  build: { command: 'vp build' },
  check: { command: ['vp lint', 'vp build'] },
}

Use the object form when a task needs other fields like cache, dependsOn, or cwd.

command ​

  • Type: string | string[]

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.

vite.config.ts
ts
tasks: {
  build: {
    command: 'vp build',
  },
}

An array runs each entry as its own command, sequentially, equivalent to joining them with &&. It is not a way to split one command into argv tokens — ['vp', 'build'] would try to run a command called vp with no arguments, then a command called build, instead of vp build.

vite.config.ts
ts
tasks: {
  check: {
    // Two commands, run in order
    command: ['vp lint', 'vp build'],
  },
  bad: {
    // Wrong: this is NOT `vp build`; it is `vp` followed by `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.

Array entries, and && chains without other shell syntax, are automatically split into independently cached sub-tasks. See Compound Commands.

dependsOn ​

  • 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.

vite.config.ts
ts
tasks: {
  deploy: {
    command: 'deploy-script --prod',
    dependsOn: ['build', 'test'],
  },
}

Dependencies can reference tasks in other packages using the package#task format:

vite.config.ts
ts
dependsOn: ['@my/core#build', '@my/utils#lint'];

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

vite.config.ts
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 for details on how explicit and topological dependencies interact.

cache ​

  • Type: boolean | { env?: string[], untrackedEnv?: string[], input?: Array<...>, output?: Array<...>, remote?: boolean }
  • Default: true

Whether and how to cache this task. Caching is enabled with default settings when cache is omitted, true, or {}.

Use an object to configure how the task is cached with cache.env, cache.untrackedEnv, cache.input, cache.output, and cache.remote:

vite.config.ts
ts
tasks: {
  build: {
    command: 'node build.mjs',
    cache: {
      env: ['NODE_ENV'],
      input: [{ auto: true }, '!dist/**'],
    },
  },
}

Set cache to false for tasks that should never be cached, like dev servers:

vite.config.ts
ts
tasks: {
  dev: {
    command: 'vp dev',
    cache: false,
  },
}

cache.env ​

  • Type: string[]
  • Default: []

Environment variables included in the cache fingerprint. When any listed variable's value changes, the cache is invalidated.

vite.config.ts
ts
tasks: {
  build: {
    command: 'node build.mjs',
    cache: {
      env: ['NODE_ENV'],
    },
  },
}

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. 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: env 'NODE_ENV' changed

cache.untrackedEnv ​

  • 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.

vite.config.ts
ts
tasks: {
  build: {
    command: 'node build.mjs',
    cache: {
      untrackedEnv: ['CI', 'GITHUB_ACTIONS'],
    },
  },
}

untrackedEnv accepts the same wildcard and ! exclusion patterns as 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, leave it out of both env and untrackedEnv.

Common system, tool, and VP_* environment variables are passed through untracked by default. See DEFAULT_UNTRACKED_ENV and vp_untracked_env_vars for the full list.

The defaults do not include platform, container, or credential variables such as GITHUB_*, VERCEL_*, NEXT_*, DOCKER_*, or *_TOKEN. Add each one that a task reads to env if its value changes the task result, or to untrackedEnv if it does not.

Color variables such as FORCE_COLOR, NO_COLOR, COLORTERM, TERM, and TERM_PROGRAM require an explicit env or untrackedEnv entry. If FORCE_COLOR isn't listed, Vite Task sets FORCE_COLOR=1 to keep cached logs colored. Colors are stripped on display when the terminal can't render them.

cache.input ​

  • Type: Array<string | { auto: boolean } | { pattern: string, base: "workspace" | "package" }>
  • Default: [{ auto: true }] (auto-inferred)

Vite Task automatically detects which files a command uses. See Automatic Data Tracking for the details and when to add manual config.

Exclude files from automatic tracking:

vite.config.ts
ts
tasks: {
  lint: {
    command: 'vp lint',
    cache: {
      // Use `{ auto: true }` to use automatic fingerprinting (default).
      // Keep the build task's `dist` folder from affecting this task.
      input: [{ auto: true }, '!dist/**'],
    },
  },
}

Specify explicit files only without automatic tracking:

vite.config.ts
ts
tasks: {
  build: {
    command: 'vp build',
    cache: {
      input: ['src/**/*.ts', 'vite.config.ts'],
    },
  },
}

Resolve patterns relative to the workspace root using the object form:

vite.config.ts
ts
tasks: {
  build: {
    command: 'vp build',
    cache: {
      input: [
        { auto: true },
        { pattern: 'shared-config/**', base: 'workspace' },
      ],
    },
  },
}

The base field is required and controls how the glob pattern is resolved:

  • "package": relative to the package directory
  • "workspace": relative to the workspace root

Disable file tracking entirely and cache only on command/env changes:

vite.config.ts
ts
tasks: {
  greet: {
    command: 'node greet.mjs',
    cache: {
      input: [],
    },
  },
}

TIP

String glob patterns are resolved relative to the package directory by default. Use the object form with base: "workspace" to resolve relative to the workspace root.

cache.output ​

  • 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.

If you omit output, Vite Task uses automatic write tracking to choose those files. An output glob such as dist/** captures matching files that exist when the task finishes. Use a glob for generators that skip unchanged files.

vite.config.ts
ts
tasks: {
  build: {
    command: 'node build.mjs',
    cache: {
      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, such as a debug log:

vite.config.ts
ts
tasks: {
  build: {
    command: 'node build.mjs',
    cache: {
      output: [{ auto: true }, '!build.log'],
    },
  },
}

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

vite.config.ts
ts
tasks: {
  build: {
    command: 'node build.mjs',
    cache: {
      output: [
        'dist/**',
        { pattern: 'shared-artifacts/**', base: 'workspace' },
      ],
    },
  },
}

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

vite.config.ts
ts
tasks: {
  report: {
    command: 'node scripts/report.mjs',
    cache: {
      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.

cache.remote ​

  • Type: boolean
  • Default: true

Whether this task participates in experimental remote caching when a remote cache is configured.

Set remote: false to keep a task cached locally without reading from or writing to the remote cache:

vite.config.ts
ts
tasks: {
  'local-setup': {
    command: 'node scripts/local-setup.mjs',
    cache: {
      remote: false,
    },
  },
}

cwd ​

  • Type: string
  • Default: package root

Working directory for the task, relative to the package root.

vite.config.ts
ts
tasks: {
  'test-e2e': {
    command: 'vp test',
    cwd: 'tests/e2e',
  },
}