Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

  • ViteDevServer

Index

Properties

config: Readonly<Omit<UserConfig, "plugins" | "css" | "assetsInclude" | "optimizeDeps" | "worker" | "build"> & { appType: AppType; base: string; build: ResolvedBuildOptions; cacheDir: string; command: "build" | "serve"; configFile: undefined | string; configFileDependencies: string[]; css: ResolvedCSSOptions; env: Record<string, any>; envDir: string; esbuild: false | ESBuildOptions; experimental: ExperimentalOptions; inlineConfig: InlineConfig; isProduction: boolean; isWorker: boolean; logger: Logger; mode: string; optimizeDeps: DepOptimizationOptions; plugins: readonly Plugin<any>[]; preview: ResolvedPreviewOptions; publicDir: string; resolve: Required<ResolveOptions> & { alias: Alias[] }; root: string; server: ResolvedServerOptions; ssr: ResolvedSSROptions; worker: ResolvedWorkerOptions; assetsInclude: any; createResolver: any } & PluginHookUtils>

The resolved vite config object

httpServer: null | HttpServer

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
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: null | ResolvedServerUrls

The resolved urls Vite prints on the CLI. null in middleware mode or before server.listen is called.

watcher: FSWatcher

chokidar watcher instance https://github.com/paulmillr/chokidar#api

web socket server with send(payload) method

Methods

  • close(): Promise<void>
  • Stop the server.

    Returns Promise<void>

  • listen(port?: number, isRestart?: boolean): Promise<ViteDevServer>
  • Start the server.

    Parameters

    • Optional port: number
    • Optional isRestart: boolean

    Returns Promise<ViteDevServer>

  • openBrowser(): void
  • Open browser

    Returns void

  • printUrls(): 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(forceOptimize?: boolean): Promise<void>
  • Restart the server.

    Parameters

    • Optional forceOptimize: boolean

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

    Returns Promise<void>

  • ssrFixStacktrace(e: Error): void
  • Mutates the given SSR error by rewriting the stacktrace

    Parameters

    • e: Error

    Returns void

  • ssrLoadModule(url: string, opts?: { fixStacktrace?: boolean }): Promise<Record<string, any>>
  • Load a given URL as an instantiated module for SSR.

    Parameters

    • url: string
    • Optional opts: { fixStacktrace?: boolean }
      • Optional fixStacktrace?: boolean

    Returns Promise<Record<string, any>>

  • ssrRewriteStacktrace(stack: string): string
  • Returns a fixed version of the given stack

    Parameters

    • stack: string

    Returns string

  • ssrTransform(code: string, inMap: null | SourceMap | { mappings: "" }, url: string, originalCode?: string): Promise<null | TransformResult>
  • Transform module code into SSR format.

    Parameters

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

    Returns Promise<null | TransformResult>

  • transformIndexHtml(url: string, html: string, originalUrl?: string): Promise<string>
  • Apply vite built-in HTML transforms and any plugin HTML transforms.

    Parameters

    • url: string
    • html: string
    • Optional originalUrl: 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<null | TransformResult>

  • 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>