The config
hook is one of the first hooks Vite calls. It lets your plugin extend or modify the Vite config before it is fully resolved. This is useful for setting default values, adding aliases, or conditionally changing behavior based on mode (development or production).
It receives the initial user config and the current command ('serve'
or 'build'
) and returns either a new config or a partial config to merge.
You can think of this hook as a way to intercept and tweak the setup before Vite does anything else.
Add a config
hook that logs the current command (serve
or build
) and sets a custom define variable like __MY_PLUGIN__ = true
.
If you need help adding a define
variable into the result then feel free to ask!