Config File
Config File Resolving
When running vite
from the command line, Vite will automatically try to resolve a config file named vite.config.js
inside project root.
The most basic config file looks like this:
// vite.config.js
export default {
// config options
}
Note Vite supports using ES modules syntax in the config file even if the project is not using native Node ESM via type: "module"
. In this case the config file is auto pre-processed before load.
You can also explicitly specify a config file to use with the --config
CLI option (resolved relative to cwd
):
vite --config my-config.js
Config Intellisense
Since Vite ships with TypeScript typings, you can leverage your IDE’s intellisense with jsdoc type hints:
/**
* type {import('vite').UserConfig}
*/
export default {
// ...
}
Vite also directly supports TS config files. You can use vite.config.ts
instead:
import { defineConfig } from 'vite'
export default defineConfig({
// ...
})
Conditional Config
If the config needs to conditional determine options based on the command (serve
or build
) or the mode being used, it can export a function instead:
export default ({ command, mode }) => {
if (command === 'serve') {
return {
// serve specific config
}
} else {
return {
// build specific config
}
}
}