Home / Function/ startDefaultServe() — vite Function Reference

startDefaultServe() — vite Function Reference

Architecture documentation for the startDefaultServe() function in vitestSetup.ts from the vite codebase.

Entity Profile

Dependency Diagram

graph TD
  434087ce_6cf5_5cbc_f3dc_7499162ee37b["startDefaultServe()"]
  804dc5f9_3eef_472e_8575_1233b4358f17["vitestSetup.ts"]
  434087ce_6cf5_5cbc_f3dc_7499162ee37b -->|defined in| 804dc5f9_3eef_472e_8575_1233b4358f17
  e3c943f2_4f6d_1f4b_1ee8_10b6692eae65["setupConsoleWarnCollector()"]
  434087ce_6cf5_5cbc_f3dc_7499162ee37b -->|calls| e3c943f2_4f6d_1f4b_1ee8_10b6692eae65
  9c39db4a_5ddd_67a5_69e8_01c342e795f3["loadConfig()"]
  434087ce_6cf5_5cbc_f3dc_7499162ee37b -->|calls| 9c39db4a_5ddd_67a5_69e8_01c342e795f3
  5482e955_5cfd_a2d6_e75a_c9419c3e701c["stripTrailingSlashIfNeeded()"]
  434087ce_6cf5_5cbc_f3dc_7499162ee37b -->|calls| 5482e955_5cfd_a2d6_e75a_c9419c3e701c
  85a2e1c1_0cd4_4b7b_8498_e3c0ddfe4db8["notifyRebuildComplete()"]
  434087ce_6cf5_5cbc_f3dc_7499162ee37b -->|calls| 85a2e1c1_0cd4_4b7b_8498_e3c0ddfe4db8
  style 434087ce_6cf5_5cbc_f3dc_7499162ee37b fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

playground/vitestSetup.ts lines 276–335

export async function startDefaultServe(): Promise<void> {
  setupConsoleWarnCollector(serverLogs)

  if (!isBuild) {
    process.env.VITE_INLINE = 'inline-serve'
    const config = await loadConfig({ command: 'serve', mode: 'development' })
    viteServer = server = await (await createServer(config)).listen()
    viteTestUrl = stripTrailingSlashIfNeeded(
      server.resolvedUrls.local[0],
      server.config.base,
    )
    await page.goto(viteTestUrl)
  } else {
    process.env.VITE_INLINE = 'inline-build'
    let resolvedConfig: ResolvedConfig
    // determine build watch
    const resolvedPlugin: () => PluginOption = () => ({
      name: 'vite-plugin-watcher',
      configResolved(config) {
        resolvedConfig = config
      },
    })
    const buildConfig = mergeConfig(
      await loadConfig({ command: 'build', mode: 'production' }),
      {
        plugins: [resolvedPlugin()],
      },
    )
    if (buildConfig.builder) {
      const builder = await createBuilder(buildConfig)
      await builder.buildApp()
    } else {
      const rollupOutput = await build(buildConfig)
      const isWatch = !!resolvedConfig!.build.watch
      // in build watch,call startStaticServer after the build is complete
      if (isWatch) {
        watcher = rollupOutput as RolldownWatcher
        await notifyRebuildComplete(watcher)
      }
      if (buildConfig.__test__) {
        buildConfig.__test__()
      }
    }

    const previewConfig = await loadConfig({
      command: 'serve',
      mode: 'development',
      isPreview: true,
    })
    const _nodeEnv = process.env.NODE_ENV
    const previewServer = await preview(previewConfig)
    // prevent preview change NODE_ENV
    process.env.NODE_ENV = _nodeEnv
    viteTestUrl = stripTrailingSlashIfNeeded(
      previewServer.resolvedUrls.local[0],
      previewServer.config.base,
    )
    await page.goto(viteTestUrl)
  }
}

Domain

Subdomains

Frequently Asked Questions

What does startDefaultServe() do?
startDefaultServe() is a function in the vite codebase, defined in playground/vitestSetup.ts.
Where is startDefaultServe() defined?
startDefaultServe() is defined in playground/vitestSetup.ts at line 276.
What does startDefaultServe() call?
startDefaultServe() calls 4 function(s): loadConfig, notifyRebuildComplete, setupConsoleWarnCollector, stripTrailingSlashIfNeeded.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free