KC's Workspace
    Preparing search index...
    interface ViteDevServer {
        config: ResolvedConfig;
        environments: Record<"client" | "ssr" | string & {}, DevEnvironment>;
        hot: NormalizedHotChannel;
        httpServer: HttpServer | null;
        middlewares: Server;
        moduleGraph: ModuleGraph;
        pluginContainer: PluginContainer;
        resolvedUrls: ResolvedServerUrls | null;
        waitForRequestsIdle: (ignoredId?: string) => Promise<void>;
        watcher: FSWatcher;
        ws: WebSocketServer;
        bindCLIShortcuts(options?: BindCLIShortcutsOptions<ViteDevServer>): void;
        close(): Promise<void>;
        listen(port?: number, isRestart?: boolean): Promise<ViteDevServer>;
        openBrowser(): void;
        printUrls(): void;
        reloadModule(module: ModuleNode): Promise<void>;
        restart(forceOptimize?: boolean): Promise<void>;
        ssrFixStacktrace(e: Error): void;
        ssrLoadModule(
            url: string,
            opts?: { fixStacktrace?: boolean },
        ): Promise<Record<string, any>>;
        ssrRewriteStacktrace(stack: string): string;
        ssrTransform(
            code: string,
            inMap: SourceMap | { mappings: "" } | null,
            url: string,
            originalCode?: string,
        ): Promise<TransformResult | null>;
        transformIndexHtml(
            url: string,
            html: string,
            originalUrl?: string,
        ): Promise<string>;
        transformRequest(
            url: string,
            options?: TransformOptions,
        ): Promise<TransformResult | null>;
        warmupRequest(url: string, options?: TransformOptions): Promise<void>;
    }
    Index

    Properties

    The resolved vite config object

    environments: Record<"client" | "ssr" | string & {}, DevEnvironment>

    Module execution environments attached to the Vite server.

    An alias to server.environments.client.hot. If you want to interact with all environments, loop over server.environments.

    httpServer: HttpServer | null

    native Node http server instance will be null in middleware mode

    middlewares: Server

    A connect app instance.

    • Can be used to attach custom middlewares to the dev server.
    • Can also be used as the handler function of a custom http server or as a middleware in any connect-style Node.js frameworks

    https://github.com/senchalabs/connect#use-middleware

    moduleGraph: ModuleGraph

    Module graph that tracks the import relationships, url to file mapping and hmr state.

    pluginContainer: PluginContainer

    Rollup plugin container that can run plugin hooks on a given file

    resolvedUrls: ResolvedServerUrls | null

    The resolved urls Vite prints on the CLI (URL-encoded). Returns null in middleware mode or if the server is not listening on any port.

    waitForRequestsIdle: (ignoredId?: string) => Promise<void>

    Calling await server.waitForRequestsIdle(id) will wait until all static imports are processed. If called from a load or transform plugin hook, the id needs to be passed as a parameter to avoid deadlocks. Calling this function after the first static imports section of the module graph has been processed will resolve immediately.

    watcher: FSWatcher

    Chokidar watcher instance. If config.server.watch is set to null, it will not watch any files and calling add or unwatch will have no effect. https://github.com/paulmillr/chokidar/tree/3.6.0#api

    WebSocket server with send(payload) method

    Methods

    • Stop the server.

      Returns Promise<void>

    • Start the server.

      Parameters

      • Optionalport: number
      • OptionalisRestart: boolean

      Returns Promise<ViteDevServer>

    • Open browser

      Returns void

    • Print server urls

      Returns void

    • Triggers HMR for a module in the module graph. You can use the server.moduleGraph API to retrieve the module to be reloaded. If hmr is false, this is a no-op.

      Parameters

      Returns Promise<void>

    • Restart the server.

      Parameters

      • OptionalforceOptimize: boolean

        force the optimizer to re-bundle, same as --force cli flag

      Returns Promise<void>

    • Mutates the given SSR error by rewriting the stacktrace

      Parameters

      Returns void

    • Load a given URL as an instantiated module for SSR.

      Parameters

      • url: string
      • Optionalopts: { fixStacktrace?: boolean }

      Returns Promise<Record<string, any>>

    • Returns a fixed version of the given stack

      Parameters

      • stack: string

      Returns string

    • Transform module code into SSR format.

      Parameters

      • code: string
      • inMap: SourceMap | { mappings: "" } | null
      • url: string
      • OptionaloriginalCode: string

      Returns Promise<TransformResult | null>

    • Apply vite built-in HTML transforms and any plugin HTML transforms.

      Parameters

      • url: string
      • html: string
      • OptionaloriginalUrl: string

      Returns Promise<string>

    • Programmatically resolve, load and transform a URL and get the result without going through the http request pipeline.

      Parameters

      Returns Promise<TransformResult | null>

    • Same as transformRequest but only warm up the URLs so the next request will already be cached. The function will never throw as it handles and reports errors internally.

      Parameters

      Returns Promise<void>