# Shared Options
Unless noted, the options in this section are applied to all dev, build, and preview.
## root
- **Type:** `string`
- **Default:** `process.cwd()`
Project root directory (where `index.html` is located). Can be an absolute path, or a path relative to the current working directory.
See [Project Root](/guide/#index-html-and-project-root) for more details.
## base
- **Type:** `string`
- **Default:** `/`
- **Related:** [`server.origin`](/config/server-options.md#server-origin)
Base public path when served in development or production. Valid values include:
- 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)
See [Public Base Path](/guide/build#public-base-path) for more details.
## mode
- **Type:** `string`
- **Default:** `'development'` for serve, `'production'` for build
Specifying 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](/guide/env-and-mode) for more details.
## input
- **Type:** `string | string[] | { [entryAlias: string]: string }`
Entry points of your application, resolved relative to the project root. This works as the default value for [`build.rolldownOptions.input`](/config/build-options#build-rolldownoptions), [`build.lib.entry`](/config/build-options#build-lib), [`build.ssr`](/config/build-options#build-ssr) (if `true`), and [`optimizeDeps.entries`](/config/dep-optimization-options#optimizedeps-entries) when those are not set explicitly.
This is useful when your application does not use an `index.html` entry, so you only need to declare the entry once instead of repeating it across the options above.
```js twoslash [vite.config.js]
import { defineConfig } from 'vite'
export default defineConfig({
input: 'src/main.ts',
})
```
## define
- **Type:** `Record`
Define global constant replacements. Entries will be defined as globals during dev and statically replaced during build.
Vite uses [Oxc's define feature](https://oxc.rs/docs/guide/usage/transformer/global-variable-replacement#define) to perform replacements, so value expressions must be a string that contains a JSON-serializable value (null, boolean, number, string, array, or object) or a single identifier. For non-string values, Vite will automatically convert it to a string with `JSON.stringify`.
**Example:**
```js
export default defineConfig({
define: {
__APP_VERSION__: JSON.stringify('v1.0.0'),
__API_URL__: 'window.__backend_api_url',
},
})
```
::: tip NOTE
For TypeScript users, make sure to add the type declarations in the `vite-env.d.ts` file to get type checks and Intellisense.
Example:
```ts
// vite-env.d.ts
declare const __APP_VERSION__: string
```
:::
## plugins
- **Type:** `(Plugin | Plugin[] | Promise)[]`
Array of plugins to use. Falsy plugins are ignored and arrays of plugins are flattened. If a promise is returned, it would be resolved before running. See [Plugin API](/guide/api-plugin) for more details on Vite plugins.
## publicDir
- **Type:** `string | false`
- **Default:** `"public"`
Directory to serve as plain static assets. Files in this directory are served at `/` 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](/guide/assets#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 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. Default to `.vite` when no `package.json` is detected.
## resolve.alias
- **Type:**
`Record | Array<{ find: string | RegExp, replacement: string }>`
Defines aliases used to replace values in `import` or `require` statements. This works similar to [`@rollup/plugin-alias`](https://github.com/rollup/plugins/tree/master/packages/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](/guide/api-plugin).
::: warning Using with SSR
If you have configured aliases for [SSR externalized dependencies](/guide/ssr.md#ssr-externals), you may want to alias the actual `node_modules` packages. Both [Yarn](https://classic.yarnpkg.com/en/docs/cli/add/#toc-yarn-add-alias) and [pnpm](https://pnpm.io/aliases/) support aliasing via the `npm:` prefix.
:::
### Object Format (`Record`)
The Object format allows specifying aliases as a key, and the corresponding value as the actual import value. For example:
```js
resolve: {
alias: {
utils: '../../../utils',
'batman-1.0.0': './joker-1.5.0'
}
}
```
### 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.
```js
resolve: {
alias: [
{ find: 'utils', replacement: '../../../utils' },
{ find: 'batman-1.0.0', replacement: './joker-1.5.0' },
]
}
```
When `find` is a regular expression, the `replacement` can use [replacement patterns](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#specifying_a_string_as_the_replacement), such as `$1`. For example, to remove extensions with another, a pattern like the following might be used:
```js
{ find:/^(.*)\.js$/, replacement: '$1.alias' }
```
## 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).
:::warning SSR + ESM
For SSR builds, deduplication does not work for ESM build outputs configured from `build.rolldownOptions.output`. A workaround is to use CJS build outputs until ESM has better plugin support for module loading.
:::
## resolve.conditions
- **Type:** `string[]`
- **Default:** `['module', 'browser', 'development|production']` (`defaultClientConditions`)
Additional allowed conditions when resolving [Conditional Exports](https://nodejs.org/api/packages.html#packages_conditional_exports) from a package.
A package with conditional exports may have the following `exports` field in its `package.json`:
```json
{
"exports": {
".": {
"import": "./index.mjs",
"require": "./index.js"
}
}
}
```
Here, `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`)
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 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']`
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.
## resolve.preserveSymlinks
- **Type:** `boolean`
- **Default:** `false`
Enabling this setting causes vite to determine file identity by the original file path (i.e. the path without following symlinks) instead of the real file path (i.e. the path after following symlinks).
- **Related:** [esbuild#preserve-symlinks](https://esbuild.github.io/api/#preserve-symlinks), [webpack#resolve.symlinks
](https://webpack.js.org/configuration/resolve/#resolvesymlinks)
## resolve.tsconfigPaths
- **Type:** `boolean`
- **Default:** `false`
Enables the tsconfig paths resolution feature. `paths` option in `tsconfig.json` will be used to resolve imports. See [Features](/guide/features.md#paths) for more details.
`paths` only applies to a file matched by a `tsconfig.json` through its `files` or `include`. Non-JS extension files should be explicitly listed in them, since a bare `"src"` or `"**/*"` `include` only matches TS/JS extensions, aligning with TypeScript's behavior. For example, to use a `paths` alias inside a CSS file (such as `@import '@/foo.css'`), list those files in `files`, or add an explicit extension to `include`:
```json [tsconfig.json]
{
"include": ["src", "src/**/*.css", "src/**/*.scss"]
}
```
::: warning Less is not supported
`resolve.tsconfigPaths` does not apply inside `.less` files. Less only gives Vite the importing file's directory, not the file itself, so Vite cannot find the `tsconfig.json` that matches it. Use a relative path or [`resolve.alias`](#resolve-alias) for `@import` in Less.
:::
## html.cspNonce
- **Type:** `string`
- **Related:** [Content Security Policy (CSP)](/guide/features#content-security-policy-csp)
A nonce value placeholder that will be used when generating script / style tags. Setting this value will also generate a meta tag with nonce value.
## html.additionalAssetSources
- **Type:** `Record`
```ts
interface HtmlAssetSource {
srcAttributes?: string[]
srcsetAttributes?: string[]
filter?: (data: {
key: string
value: string
attributes: Record
}) => boolean
}
```
Define additional HTML elements and attributes to be treated as asset sources. This extends the built-in list that includes standard elements like ``, `