Home / Function/ serve() — vite Function Reference

serve() — vite Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  bda7366d_bfdd_9089_3913_50d119a4ba09["serve()"]
  69787096_db2c_92e4_449c_afb1439f9f27["serve.ts"]
  bda7366d_bfdd_9089_3913_50d119a4ba09 -->|defined in| 69787096_db2c_92e4_449c_afb1439f9f27
  349580dc_2cf4_270a_24b1_7820936a649b["setupConsoleWarnCollector()"]
  bda7366d_bfdd_9089_3913_50d119a4ba09 -->|calls| 349580dc_2cf4_270a_24b1_7820936a649b
  style bda7366d_bfdd_9089_3913_50d119a4ba09 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

playground/lib/__tests__/serve.ts lines 21–145

export async function serve(): Promise<{ close(): Promise<void> }> {
  setupConsoleWarnCollector()

  if (!isBuild) {
    const { createServer } = await import('vite')
    process.env.VITE_INLINE = 'inline-serve'
    const viteServer = await (
      await createServer({
        root: rootDir,
        logLevel: 'silent',
        server: {
          port,
          strictPort: true,
          watch: {
            usePolling: true,
            interval: 100,
          },
          host: true,
          fs: {
            strict: !isBuild,
          },
        },
        build: {
          target: 'esnext',
        },
      })
    ).listen()
    // use resolved port/base from server
    const devBase = viteServer.config.base === '/' ? '' : viteServer.config.base
    setViteUrl(`http://localhost:${port}${devBase}`)
    await page.goto(viteTestUrl)

    return viteServer
  } else {
    const { build } = await import('vite')
    await build({
      root: rootDir,
      logLevel: 'silent',
      configFile: path.resolve(dirname, '../vite.config.js'),
    })

    await build({
      root: rootDir,
      logLevel: 'warn', // output esbuild warns
      configFile: path.resolve(dirname, '../vite.dyimport.config.js'),
    })

    await build({
      root: rootDir,
      logLevel: 'warn', // output esbuild warns
      configFile: path.resolve(dirname, '../vite.multiple-output.config.js'),
    })

    await build({
      root: rootDir,
      logLevel: 'warn', // output esbuild warns
      configFile: path.resolve(dirname, '../vite.nominify.config.js'),
    })

    await build({
      root: rootDir,
      logLevel: 'warn', // output esbuild warns
      configFile: path.resolve(dirname, '../vite.helpers-injection.config.js'),
    })

    await build({
      root: rootDir,
      logLevel: 'warn', // output esbuild warns
      configFile: path.resolve(dirname, '../vite.named-exports.config.js'),
    })

    await build({
      root: rootDir,
      logLevel: 'warn', // output esbuild warns
      configFile: path.resolve(dirname, '../vite.css-single-entry.config.js'),
    })

    await build({
      root: rootDir,
      logLevel: 'warn', // output esbuild warns
      configFile: path.resolve(dirname, '../vite.css-multi-entry.config.js'),

Domain

Subdomains

Frequently Asked Questions

What does serve() do?
serve() is a function in the vite codebase, defined in playground/lib/__tests__/serve.ts.
Where is serve() defined?
serve() is defined in playground/lib/__tests__/serve.ts at line 21.
What does serve() call?
serve() calls 1 function(s): setupConsoleWarnCollector.

Analyze Your Own Codebase

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

Try Supermodel Free