root
- Type:
string - Default:
process.cwd()
index.html is located). Can be an absolute path, or a path relative to the current working directory.
See Project Root for more details.
base
- Type:
string - Default:
/ - Related:
server.origin
- Absolute URL pathname, e.g.
/foo/ - Full URL, e.g.
https://bar.com/foo/(The origin part won’t be used in development so the value is the same as/foo/) - Empty string or
./(for embedded deployment)
mode
- Type:
string - Default:
'development'for serve,'production'for build
--mode option.
See Env Variables and Modes for more details.
define
- Type:
Record<string, any>
JSON.stringify.
Example:
plugins
- Type:
(Plugin | Plugin[] | Promise<Plugin | Plugin[]>)[]
publicDir
- Type:
string | false - Default:
"public"
/ during dev and copied to the root of outDir during build, and are always served or copied as-is without transform. The value can be either an absolute file system path or a path relative to project root.
Defining publicDir as false disables this feature.
See The public Directory for more details.
cacheDir
- Type:
string - Default:
"node_modules/.vite"
--force flag or manually delete the directory to regenerate the cache files. The value can be either an absolute file system path or a path relative to project root. Default to .vite when no package.json is detected.
resolve.alias
- Type:
Record<string, string> | Array<{ find: string | RegExp, replacement: string }>
import or require statements. This works similar to @rollup/plugin-alias.
The order of the entries is important, in that the first defined rules are applied first.
When aliasing to file system paths, always use absolute paths. Relative alias values will be used as-is and will not be resolved into file system paths.
More advanced custom resolution can be achieved through plugins.
Object Format (Record<string, string>)
The Object format allows specifying aliases as a key, and the corresponding value as the actual import value. For example:
Array Format (Array<{ find: string | RegExp, replacement: string }>)
The Array format allows specifying aliases as objects, which can be useful for complex key/value pairs.
find is a regular expression, the replacement can use replacement patterns, such as $1. For example, to remove extensions with another, a pattern like the following might be used:
resolve.dedupe
- Type:
string[]
resolve.conditions
- Type:
string[] - Default:
['module', 'browser', 'development|production'](defaultClientConditions)
exports field in its package.json:
import and require are “conditions”. Conditions can be nested and should be specified from most specific to least specific.
development|production is a special value that is replaced with production or development depending on the value of process.env.NODE_ENV. It is replaced with production when process.env.NODE_ENV === 'production' and development otherwise.
Note that import, require, default conditions are always applied if the requirements are met.
In addition, the style condition is applied when resolving style imports, e.g. @import 'my-library'. For some CSS pre-processors, their corresponding conditions are also applied, i.e. sass for Sass and less for Less.
resolve.mainFields
- Type:
string[] - Default:
['browser', 'module', 'jsnext:main', 'jsnext'](defaultClientMainFields)
package.json to try when resolving a package’s entry point. Note this takes lower precedence than conditional exports resolved from the exports field: if an entry point is successfully resolved from exports, the main field will be ignored.
resolve.extensions
- Type:
string[] - Default:
['.mjs', '.js', '.mts', '.ts', '.jsx', '.tsx', '.json']
.vue) since it can interfere with IDE and type support.
resolve.preserveSymlinks
- Type:
boolean - Default:
false
resolve.tsconfigPaths
- Type:
boolean - Default:
false
paths option in tsconfig.json will be used to resolve imports. See Features for more details.
html.cspNonce
- Type:
string - Related: Content Security Policy (CSP)
css.modules
- Type:
css.lightningcss.cssModules should be used instead.
css.postcss
- Type:
string | (postcss.ProcessOptions & { plugins?: postcss.AcceptedPlugin[] })
postcss.config.js. But for plugins property, only array format can be used.
The search is done using postcss-load-config and only the supported config file names are loaded. Config files outside the workspace root (or the project root if no workspace is found) are not searched by default. You can specify a custom path outside of the root to load the specific config file instead if needed.
Note if an inline config is provided, Vite will not search for other PostCSS config sources.
css.preprocessorOptions
- Type:
Record<string, object>
sass/scss:- Uses
sass-embeddedif installed, otherwise usessass. For the best performance, it’s recommended to install thesass-embeddedpackage. - Options
- Uses
less: Options.styl/stylus: Onlydefineis supported, which can be passed as an object.
css.preprocessorOptions[extension].additionalData
- Type:
string | ((source: string, filename: string) => (string | { content: string; map?: SourceMap }))
css.preprocessorMaxWorkers
- Type:
number | true - Default:
true
true means up to the number of CPUs minus 1. When set to 0, Vite will not create any workers and will run the preprocessors in the main thread.
Depending on the preprocessor options, Vite may run the preprocessors on the main thread even if this option is not set to 0.
css.devSourcemap
- Experimental: Give Feedback
- Type:
boolean - Default:
false
css.transformer
- Experimental: Give Feedback
- Type:
'postcss' | 'lightningcss' - Default:
'postcss'
Note that postcss (postcss-import) has a different behavior with duplicated
@import from browsers. See postcss/postcss-import#462.css.lightningcss
- Experimental: Give Feedback
- Type:
json.namedExports
- Type:
boolean - Default:
true
.json files.
json.stringify
- Type:
boolean | 'auto' - Default:
'auto'
true, imported JSON will be transformed into export default JSON.parse("...") which is significantly more performant than Object literals, especially when the JSON file is large.
If set to 'auto', the data will be stringified only if the data is bigger than 10kB.
oxc
- Type:
OxcOptions | false
OxcOptions extends Oxc Transformer’s options. The most common use case is customizing JSX:
ts, jsx and tsx files. You can customize this with oxc.include and oxc.exclude, which can be a regex, a picomatch pattern, or an array of either.
In addition, you can also use oxc.jsxInject to automatically inject JSX helper imports for every file transformed by Oxc:
false to disable transformation by Oxc.
esbuild
- Type:
ESBuildOptions | false - Deprecated
oxc option internally. Use oxc option instead.
assetsInclude
- Type:
string | RegExp | (string | RegExp)[] - Related: Static Asset Handling
-
They will be excluded from the plugin transform pipeline when referenced from HTML or directly requested over
fetchor XHR. -
Importing them from JS will return their resolved URL string (this can be overwritten if you have a
enforce: 'pre'plugin to handle the asset type differently).
logLevel
- Type:
'info' | 'warn' | 'error' | 'silent'
'info'.
customLogger
- Type:
createLogger API to get the default logger and customize it to, for example, change the message or filter out certain warnings.
clearScreen
- Type:
boolean - Default:
true
false to prevent Vite from clearing the terminal screen when logging certain messages. Via command line, use --clearScreen false.
envDir
- Type:
string | false - Default:
root
.env files are loaded. Can be an absolute path, or a path relative to the project root. false will disable the .env file loading.
See here for more about environment files.
envPrefix
- Type:
string | string[] - Default:
VITE_
envPrefix will be exposed to your client source code via import.meta.env.
appType
- Type:
'spa' | 'mpa' | 'custom' - Default:
'spa'
'spa': include HTML middlewares and use SPA fallback. Configure sirv withsingle: truein preview'mpa': include HTML middlewares'custom': don’t include HTML middlewares
server.middlewareMode.
devtools
- Experimental: Give Feedback
- Type:
boolean|DevToolsConfig - Default:
false
@vitejs/devtools is installed as a dependency. This feature is currently supported only in build mode.
See Vite DevTools for more details.
future
- Type:
Record<string, 'warn' | undefined> - Related: Breaking Changes