Commit Hooks & Staged Checks
Set up Git commit hooks with vp config and run checks on staged files with vp staged — no Husky or lint-staged needed. Your staged-file rules live in the same vite.config.ts as everything else.
What it is#
Vite+ has built-in commit hooks. vp config installs the Git hooks and hook directory; vp staged runs checks against the files currently staged for commit, using a staged block in vite.config.ts. No Husky, no lint-staged.
Why you'd care#
Fast, staged-only checks at commit time catch problems before they land, and keeping the rules in vite.config.ts means your hook config lives beside your lint, format, test, and task config — one file, one source of truth.
Before#
Husky writing shell scripts under .husky/, plus a separate .lintstagedrc and a lint-staged dependency to keep updated.
After#
Hooks managed by vp, staged rules in vite.config.ts.
Do it yourself#
1. Install hooks#
vp config
By default hooks are written to .vite-hooks. Useful flags:
vp config --hooks-dir .vite-hooks
vp config --no-hooks # leave existing Git hooks alone
vp config --no-agent # skip coding-agent instruction files
(If you used vp create or vp migrate, you were already prompted to set this up.)
2. Define staged-file checks#
import { defineConfig } from 'vite-plus'
export default defineConfig({
staged: {
'*.{js,ts,tsx,vue,svelte}': 'vp check --fix',
},
})
3. See it run#
vp staged # run staged checks manually
vp staged --verbose
Once hooks are installed, vp staged runs automatically on git commit.
Gotchas#
- Only the
stagedblock format is supported. Non-JSON.lintstagedrcandlint-staged.config.*files are not migrated automatically — port them intostaged. - Disable hook installation from lifecycle scripts (
prepare/postinstall) withVITE_GIT_HOOKS=0— handy in CI where you don't want hooks installed. - Remember the
vp checkconfig interaction from lesson 1: if you disabled a step (sayfmt: false) in thecheckblock, avp checkin your staged rules skips it too. - Migrating from
lefthook/simple-git-hooks/yorkie? Move commands intostaged, point your lifecycle script atvp config, and create.vite-hooks/pre-commitrunningvp staged— then remove the old tool.
Recap#
vp config installs hooks; vp staged runs staged-file checks from the staged block in vite.config.ts — replacing Husky + lint-staged. That closes the Intermediate series: you understand vp check and vp test, the script-vs-built-in split, migration, and hooks. The Advanced series scales this up — monorepos, cache internals, CI/Docker, library packaging, and runtime control.