Vite · VITE0032
Do not add serve-only hooks to build-only plugins
Reports configureServer, configurePreviewServer, handleHotUpdate, and hotUpdate hooks on Vite plugin objects with apply: "build".
Run this rule
pnpm vite-doctor . --framework vite --rules vite/plugin/no-unreachable-hook
Why it matters
Vite filters plugins by apply before calling these hooks. Dev, preview, and createServer use the serve command, so they exclude plugins whose apply is "build". Doctor checks objects it can trace to Vite config plugins or a factory with a Vite Plugin return type, and skips spreads, unresolved computed keys, and objects with unproven apply values. It does not report build output hooks on apply: "serve" plugins, because those can run in dev.
Recommended fix
Remove apply: "build" or change it to apply: "serve" if the hook should run, or delete the hook.
Useful links
Example
Keep serve hooks on plugins that run in serve
Before
import type { Plugin } from 'vite'
export function headers(): Plugin {
return {
name: 'headers',
apply: 'build',
configureServer(server) {
server.middlewares.use(setHeaders)
},
}
}
After
import type { Plugin } from 'vite'
export function headers(): Plugin {
return {
name: 'headers',
apply: 'serve',
configureServer(server) {
server.middlewares.use(setHeaders)
},
}
}