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}
*/
const config = {
// ...
}
export default config
Alternatively you can use the defineConfig
helper which should provide intellisense without the need for jsdoc annotations:
import { defineConfig } from 'vite'
export default defineConfig({
// ...
})
Vite also directly supports TS config files. You can use vite.config.ts
with the defineConfig
helper as well.
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
}
}
}
Async Config
If the config needs to call async function, it can export a async function instead:
export default async ({ command, mode }) => {
const data = await asyncFunction();
return {
// build specific config
}
}