Server Options
server.host
Type:
string
Specify server hostname.
server.port
Type:
number
Specify server port. Note if the port is already being used, Vite will automatically try the next available port so this may not be the actual port the server ends up listening on.
server.strictPort
Type:
boolean
Set to
true
to exit if port is already in use, instead of automatically try the next available port.
server.https
Type:
boolean | https.ServerOptions
Enable TLS + HTTP/2. Note this downgrades to TLS only when the
server.proxy
option is also used.The value can also be an options object passed to
https.createServer()
.
server.open
Type:
boolean | string
Automatically open the app in the browser on server start. When the value is a string, it will be used as the URL’s pathname.
Example:
export default {
server: {
open: '/docs/index.html'
}
}
server.proxy
Type:
Record<string, string | ProxyOptions>
Configure custom proxy rules for the dev server. Expects an object of
{ key: options }
pairs. If the key starts with^
, it will be interpreted as aRegExp
.Uses
http-proxy
. Full options here.Example:
export default {
server: {
proxy: {
// string shorthand
'/foo': 'http://localhost:4567/foo',
// with options
'/api': {
target: 'http://jsonplaceholder.typicode.com',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, '')
}
// with RegEx
'^/fallback/.*': {
target: 'http://jsonplaceholder.typicode.com',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/fallback/, '')
}
}
}
}
server.cors
Type:
boolean | CorsOptions
Configure CORS for the dev server. This is enabled by default and allows any origin. Pass an options object to fine tune the behavior or
false
to disable.
server.force
Type:
boolean
Related: Dependency Pre-Bundling
Set to
true
to force dependency pre-bundling.
server.hmr
Type:
boolean | { protocol?: string, host?: string, port?: number, path?: string, timeout?: number, overlay?: boolean }
Disable or configure HMR connection (in cases where the HMR websocket must use a different address from the http server).
Set
server.hmr.overlay
tofalse
to disable the server error overlay.
server.watch
Type:
object
File system watcher options to pass on to chokidar.