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:

    1. export default {
    2. server: {
    3. open: '/docs/index.html'
    4. }
    5. }

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 a RegExp.

    Uses http-proxy. Full options here.

    Example:

    1. export default {
    2. server: {
    3. proxy: {
    4. // string shorthand
    5. '/foo': 'http://localhost:4567/foo',
    6. // with options
    7. '/api': {
    8. target: 'http://jsonplaceholder.typicode.com',
    9. changeOrigin: true,
    10. rewrite: (path) => path.replace(/^\/api/, '')
    11. }
    12. // with RegEx
    13. '^/fallback/.*': {
    14. target: 'http://jsonplaceholder.typicode.com',
    15. changeOrigin: true,
    16. rewrite: (path) => path.replace(/^\/fallback/, '')
    17. }
    18. }
    19. }
    20. }

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

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 to false to disable the server error overlay.

server.watch

  • Type: object

    File system watcher options to pass on to chokidar.