KC's Workspace
    Preparing search index...

    server.pluginContainer compatibility

    The default environment is in buildStart, buildEnd, watchChange, and closeBundle hooks, which are called once for all environments, or when no environment is passed in other hooks. The ssrEnvironment is needed for backward compatibility when the ssr flag is passed without an environment. The defaultEnvironment in the main pluginContainer in the server should be the client environment for backward compatibility.

    interface ServerOptions$1 {
        allowedHosts?: true | string[];
        cors?: boolean | CorsOptions;
        fs?: FileSystemServeOptions;
        headers?: OutgoingHttpHeaders;
        hmr?: boolean | HmrOptions;
        host?: string | boolean;
        hotUpdateEnvironments?: (
            server: ViteDevServer,
            hmr: (environment: DevEnvironment) => Promise<void>,
        ) => Promise<void>;
        https?: ServerOptions<typeof IncomingMessage, typeof ServerResponse>;
        middlewareMode?: boolean | { server: HttpServer };
        open?: string | boolean;
        origin?: string;
        perEnvironmentStartEndDuringDev?: boolean;
        perEnvironmentWatchChangeDuringDev?: boolean;
        port?: number;
        preTransformRequests?: boolean;
        proxy?: Record<string, string | ProxyOptions>;
        sourcemapIgnoreList?:
            | false
            | ((sourcePath: string, sourcemapPath: string) => boolean);
        strictPort?: boolean;
        warmup?: { clientFiles?: string[]; ssrFiles?: string[] };
        watch?: WatchOptions | null;
        ws?: false;
    }

    Hierarchy (View Summary)

    Index

    Properties

    allowedHosts?: true | string[]

    The hostnames that Vite is allowed to respond to. localhost and subdomains 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. This is not recommended as it will be vulnerable to DNS rebinding attacks.

    cors?: boolean | CorsOptions

    Configure CORS for the dev server. Uses https://github.com/expressjs/cors.

    When enabling this option, we recommend setting a specific value rather than true to avoid exposing the source code to untrusted origins.

    Set to true to allow all methods from any origin, or configure separately using an object.

    false
    

    Options for files served via '/@fs/'.

    Specify server response headers.

    hmr?: boolean | HmrOptions

    Configure HMR-specific options (port, host, path & protocol)

    host?: string | boolean

    Specify which IP addresses the server should listen on. Set to 0.0.0.0 to listen on all addresses, including LAN and public addresses.

    hotUpdateEnvironments?: (
        server: ViteDevServer,
        hmr: (environment: DevEnvironment) => Promise<void>,
    ) => Promise<void>

    Run HMR tasks, by default the HMR propagation is done in parallel for all environments

    Enable TLS + HTTP/2. Note: this downgrades to TLS only when the proxy option is also used.

    middlewareMode?: boolean | { server: HttpServer }

    Create Vite dev server to be used as a middleware in an existing server

    Type Declaration

    • boolean
    • { server: HttpServer }
      • server: HttpServer

        Parent server instance to attach to

        This is needed to proxy WebSocket connections to the parent server.

    false
    
    open?: string | boolean

    Open browser window on startup

    origin?: string

    Origin for the generated asset URLs.

    `http://127.0.0.1:8080`
    
    perEnvironmentStartEndDuringDev?: boolean

    Backward compatibility. The buildStart and buildEnd hooks were called only once for the client environment. This option enables per-environment buildStart and buildEnd hooks.

    false
    @experimental
    perEnvironmentWatchChangeDuringDev?: boolean

    Backward compatibility. The watchChange hook was called only once for the client environment. This option enables per-environment watchChange hooks.

    false
    @experimental
    port?: 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.

    preTransformRequests?: boolean

    Pre-transform known direct imports

    true
    
    proxy?: Record<string, string | ProxyOptions>

    Configure custom proxy rules for the dev server. Expects an object of { key: options } pairs. Uses http-proxy-3. Full options here.

    Example vite.config.js:

    module.exports = {
    proxy: {
    // string shorthand: /foo -> http://localhost:4567/foo
    '/foo': 'http://localhost:4567',
    // with options
    '/api': {
    target: 'http://jsonplaceholder.typicode.com',
    changeOrigin: true,
    rewrite: path => path.replace(/^/api/, '')
    }
    }
    }
    sourcemapIgnoreList?:
        | false
        | ((sourcePath: string, sourcemapPath: string) => boolean)

    Whether or not to ignore-list source files in the dev server sourcemap, used to populate the x_google_ignoreList source map extension.

    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.

    strictPort?: boolean

    If enabled, vite will exit if specified port is already in use

    warmup?: { clientFiles?: string[]; ssrFiles?: string[] }

    Warm-up files to transform and cache the results in advance. This improves the initial page load during server starts and prevents transform waterfalls.

    Type Declaration

    • OptionalclientFiles?: string[]

      The files to be transformed and used on the client-side. Supports glob patterns.

    • OptionalssrFiles?: string[]

      The files to be transformed and used in SSR. Supports glob patterns.

    watch?: WatchOptions | null

    chokidar watch options or null to disable FS watching https://github.com/paulmillr/chokidar/tree/3.6.0#api

    ws?: false

    Do not start the websocket connection.