Skip to content

May 9th, 2024

Vite Meetup SF

Preview Options

preview.host

Specify which IP addresses the server should listen on. Set this to 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.

NOTE

There are cases when other servers might respond instead of Vite. See server.host for more details.

preview.port

  • Type: number
  • Default: 4173

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.

Example:

js
export default defineConfig({
  server: {
    port: 3030,
  },
  preview: {
    port: 8080,
  },
})

preview.strictPort

Set to true to exit if port is already in use, instead of automatically trying the next available port.

preview.https

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().

preview.open

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. If you want to open the server in a specific browser you like, you can set the env 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.

preview.proxy

  • Type: Record<string, string | ProxyOptions>
  • Default: server.proxy

Configure custom proxy rules for the preview server. Expects an object of { key: options } pairs. If the key starts with ^, it will be interpreted as a RegExp. The configure option can be used to access the proxy instance.

Uses http-proxy. Full options here.

preview.cors

Configure CORS for the preview server. This is enabled by default and allows any origin. Pass an options object to fine tune the behavior or false to disable.

preview.headers

  • Type: OutgoingHttpHeaders

Specify server response headers.

Released under the MIT License. (53b21d88)