Shared Options
root
Type:
string
Default:
process.cwd()
Project root directory (where
index.html
is located). Can be an absolute path, or a path relative from the location of the config file itself.See Project Root for more details.
base
Type:
string
Default:
/
Base public path when served in development or production. Valid values include:
- Absolute URL pathname, e.g.
/foo/
- Full URL, e.g.
https://foo.com/
- Empty string or
./
(for embedded deployment)
See Public Base Path for more details.
- Absolute URL pathname, e.g.
mode
Type:
string
Default:
'development'
for serve,'production'
for buildSpecifying this in config will override the default mode for both serve and build. This value can also be overridden via the command line
--mode
option.See Env Variables and Modes for more details.
define
Type:
Record<string, string>
Define global constant replacements. Entries will be defined as globals during dev and statically replaced during build.
Starting from
2.0.0-beta.70
, string values will be used as raw expressions, so if defining a string constant, it needs to be explicitly quoted (e.g. withJSON.stringify
).Replacements are performed only when the match is surrounded by word boundaries (
\b
).
Because it’s implemented as straightforward text replacements without any syntax analyzation, we recommend using
define
for CONSTANTS only.For example,
process.env.FOO
and__APP_VERSION__
are good fits. Butprocess
orglobal
should not be put into this option. Variables can be shimmed or polyfilled instead.
plugins
Type:
(Plugin | Plugin[])[]
Array of plugins to use. Falsy plugins are ignored and arrays of plugins are flattened. See Plugin API for more details on Vite plugins.
publicDir
Type:
string
Default:
"public"
Directory to serve as plain static assets. Files in this directory are served at
/
during dev and copied to the root ofoutDir
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.See The
public
Directory for more details.
cacheDir
Type:
string
Default:
"node_modules/.vite"
Directory to save cache files. Files in this directory are pre-bundled deps or some other cache files that generated by vite, which can improve the performance. You can use
--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.
resolve.alias
Type:
Record<string, string> | Array<{ find: string | RegExp, replacement: string }>
Will be passed to
@rollup/plugin-alias
as its entries option. Can either be an object, or an array of{ find, replacement }
pairs.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.
resolve.dedupe
Type:
string[]
If you have duplicated copies of the same dependency in your app (likely due to hoisting or linked packages in monorepos), use this option to force Vite to always resolve listed dependencies to the same copy (from project root).
resolve.conditions
Type:
string[]
Additional allowed conditions when resolving Conditional Exports from a package.
A package with conditional exports may have the following
exports
field in itspackage.json
:{
"exports": {
".": {
"import": "./index.esm.js",
"require": "./index.cjs.js"
}
}
}
Here,
import
andrequire
are “conditions”. Conditions can be nested and should be specified from most specific to least specific.Vite has a list of “allowed conditions” and will match the first condition that is in the allowed list. The default allowed conditions are:
import
,module
,browser
,default
, andproduction/development
based on current mode. Theresolve.conditions
config option allows specifying additional allowed conditions.
resolve.mainFields
Type:
string[]
Default:
['module', 'jsnext:main', 'jsnext']
List of fields in
package.json
to try when resolving a package’s entry point. Note this takes lower precedence than conditional exports resolved from theexports
field: if an entry point is successfully resolved fromexports
, the main field will be ignored.
resolve.extensions
Type:
string[]
Default:
['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json']
List of file extensions to try for imports that omit extensions. Note it is NOT recommended to omit extensions for custom import types (e.g.
.vue
) since it can interfere with IDE and type support.
css.modules
Type:
interface CSSModulesOptions {
scopeBehaviour?: 'global' | 'local'
globalModulePaths?: string[]
generateScopedName?:
| string
| ((name: string, filename: string, css: string) => string)
hashPrefix?: string
/**
* default: 'camelCaseOnly'
*/
localsConvention?: 'camelCase' | 'camelCaseOnly' | 'dashes' | 'dashesOnly'
}
Configure CSS modules behavior. The options are passed on to postcss-modules.
css.postcss
Type:
string | (postcss.ProcessOptions & { plugins?: postcss.Plugin[] })
Inline PostCSS config (expects the same format as
postcss.config.js
), or a custom path to search PostCSS config from (default is project root). The search is done using postcss-load-config.Note if an inline config is provided, Vite will not search for other PostCSS config sources.
css.preprocessorOptions
Type:
Record<string, object>
Specify options to pass to CSS pre-processors. Example:
export default {
css: {
preprocessorOptions: {
scss: {
additionalData: `$injectedColor: orange;`
}
}
}
}
json.namedExports
Type:
boolean
Default:
true
Whether to support named imports from
.json
files.
json.stringify
Type:
boolean
Default:
false
If set to
true
, imported JSON will be transformed intoexport default JSON.parse("...")
which is significantly more performant than Object literals, especially when the JSON file is large.Enabling this disables named imports.
esbuild
Type:
ESBuildOptions | false
ESBuildOptions
extends ESbuild’s own transform options. The most common use case is customizing JSX:export default {
esbuild: {
jsxFactory: 'h',
jsxFragment: 'Fragment'
}
}
By default, ESBuild is applied to
ts
,jsx
andtsx
files. You can customize this withesbuild.include
andesbuild.exclude
, both of which expects type ofstring | RegExp | (string | RegExp)[]
.In addition, you can also use
esbuild.jsxInject
to automatically inject JSX helper imports for every file transformed by ESBuild:export default {
esbuild: {
jsxInject: `import React from 'react'`
}
}
Set to
false
to disable ESbuild transforms.
assetsInclude
Type:
string | RegExp | (string | RegExp)[]
Related: Static Asset Handling
Specify additional file types to be treated as static assets so that:
They will be excluded from the plugin transform pipeline when referenced from HTML or directly requested over
fetch
or 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).
The built-in asset type list can be found here.
logLevel
Type:
'info' | 'warn' | 'error' | 'silent'
Adjust console output verbosity. Default is
'info'
.
clearScreen
Type:
boolean
Default:
true
Set to
false
to prevent Vite from clearing the terminal screen when logging certain messages. Via command line, use--clearScreen false
.