server.host
- Type:
string | boolean - Default:
'localhost'
0.0.0.0 or true to listen on all addresses, including LAN and public addresses.
This can be set via the CLI using --host 0.0.0.0 or --host.
There are cases when other servers might respond instead of Vite.The first case is when The second case is when wildcard hosts (e.g.
localhost is used. Node.js under v17 reorders the result of DNS-resolved addresses by default. When accessing localhost, browsers use DNS to resolve the address and that address might differ from the address which Vite is listening to. Vite prints the resolved address when it differs.You can set dns.setDefaultResultOrder('verbatim') to disable the reordering behavior. Vite will then print the address as localhost.vite.config.js
0.0.0.0) are used. This is because servers listening on non-wildcard hosts take priority over those listening on wildcard hosts.server.allowedHosts
- Type:
string[] | true - Default:
[]
localhost and domains under .localhost and all IP addresses are allowed by default.
When using HTTPS, this check is skipped.
If a string starts with ., it will allow that hostname without the . and all subdomains under the hostname. For example, .example.com will allow example.com, foo.example.com, and foo.bar.example.com. If set to true, the server is allowed to respond to requests for any hosts.
server.port
- Type:
number - Default:
5173
server.strictPort
- Type:
boolean
true to exit if port is already in use, instead of automatically trying the next available port.
server.https
- Type:
https.ServerOptions
https.createServer().
A valid certificate is needed. For a basic setup, you can add @vitejs/plugin-basic-ssl to the project plugins, which will automatically create and cache a self-signed certificate. But we recommend creating your own certificates.
server.open
- Type:
boolean | string
process.env.BROWSER (e.g. firefox). You can also set process.env.BROWSER_ARGS to pass additional arguments (e.g. --incognito).
BROWSER and BROWSER_ARGS are also special environment variables you can set in the .env file to configure it. See the open package for more details.
Example:
server.proxy
- Type:
Record<string, string | ProxyOptions>
{ key: options } pairs. Any requests that request path starts with that key will be proxied to that specified target. If the key starts with ^, it will be interpreted as a RegExp. The configure option can be used to access the proxy instance. If a request matches any of the configured proxy rules, the request won’t be transformed by Vite.
Note that if you are using non-relative base, you must prefix each key with that base.
Extends http-proxy-3. Additional options are here.
In some cases, you might also want to configure the underlying dev server (e.g. to add custom middlewares to the internal connect app). In order to do that, you need to write your own plugin and use configureServer function.
Example:
server.cors
- Type:
boolean | CorsOptions - Default:
{ origin: /^https?:\/\/(?:(?:[^:]+\.)?localhost|127\.0\.0\.1|\[::1\])(?::\d+)?$/ }(allows localhost,127.0.0.1and::1)
true to allow any origin.
server.headers
- Type:
OutgoingHttpHeaders
server.hmr
- Type:
boolean | { protocol?: string, host?: string, port?: number, path?: string, timeout?: number, overlay?: boolean, clientPort?: number, server?: Server }
server.hmr.overlay to false to disable the server error overlay.
protocol sets the WebSocket protocol used for the HMR connection: ws (WebSocket) or wss (WebSocket Secure).
clientPort is an advanced option that overrides the port only on the client side, allowing you to serve the websocket on a different port than the client code looks for it on.
When server.hmr.server is defined, Vite will process the HMR connection requests through the provided server. If not in middleware mode, Vite will attempt to process HMR connection requests through the existing server. This can be helpful when using self-signed certificates or when you want to expose Vite over a network on a single port.
Check out vite-setup-catalogue for some examples.
With the default configuration, reverse proxies in front of Vite are expected to support proxying WebSocket. If the Vite HMR client fails to connect WebSocket, the client will fall back to connecting the WebSocket directly to the Vite HMR server bypassing the reverse proxies:The error that appears in the Browser when the fallback happens can be ignored. To avoid the error by directly bypassing reverse proxies, you could either:
- configure the reverse proxy to proxy WebSocket too
- set
server.strictPort = trueand setserver.hmr.clientPortto the same value withserver.port - set
server.hmr.portto a different value fromserver.port
server.warmup
- Type:
{ clientFiles?: string[], ssrFiles?: string[] } - Related: Warm Up Frequently Used Files
clientFiles are files that are used in the client only, while ssrFiles are files that are used in SSR only. They accept an array of file paths or tinyglobby patterns relative to the root.
Make sure to only add files that are frequently used to not overload the Vite dev server on startup.
server.watch
- Type:
object | null
root and skips the .git/, node_modules/, test-results/, and Vite’s cacheDir and build.outDir directories by default. When updating a watched file, Vite will apply HMR and update the page only if needed.
If set to null, no files will be watched. server.watcher will provide a compatible event emitter, but calling add or unwatch will have no effect.
server.middlewareMode
- Type:
boolean - Default:
false
- Related: appType, SSR - Setting Up the Dev Server
- Example:
server.fs.strict
- Type:
boolean - Default:
true(enabled by default since Vite 2.7)
server.fs.allow
- Type:
string[]
/@fs/. When server.fs.strict is set to true, accessing files outside this directory list that aren’t imported from an allowed file will result in a 403.
Both directories and files can be provided.
Vite will search for the root of the potential workspace and use it as default. A valid workspace met the following conditions, otherwise will fall back to the project root.
- contains
workspacesfield inpackage.json - contains one of the following file
lerna.jsonpnpm-workspace.yaml
server.fs.allow is specified, the auto workspace root detection will be disabled. To extend the original behavior, a utility searchForWorkspaceRoot is exposed:
server.fs.deny
- Type:
string[] - Default:
['.env', '.env.*', '*.{crt,pem}', '**/.git/**']
server.fs.allow. picomatch patterns are supported.
This blocklist does not apply to the public directory. All files in the public directory are served without any filtering, since they are copied directly to the output directory during build.
server.origin
- Type:
string
server.sourcemapIgnoreList
- Type:
false | (sourcePath: string, sourcemapPath: string) => boolean - Default:
(sourcePath) => sourcePath.includes('node_modules')
x_google_ignoreList source map extension.
server.sourcemapIgnoreList is the equivalent of build.rollupOptions.output.sourcemapIgnoreList for the dev server. A difference between the two config options is that the rollup function is called with a relative path for sourcePath while server.sourcemapIgnoreList is called with an absolute path. During dev, most modules have the map and the source in the same folder, so the relative path for sourcePath is the file name itself. In these cases, absolute paths makes it convenient to be used instead.
By default, it excludes all paths containing node_modules. You can pass false to disable this behavior, or, for full control, a function that takes the source path and sourcemap path and returns whether to ignore the source path.
server.sourcemapIgnoreList and build.rollupOptions.output.sourcemapIgnoreList need to be set independently. server.sourcemapIgnoreList is a server only config and doesn’t get its default value from the defined rollup options.