MCPcopy
hub / github.com/vitejs/vite / _createServer

Function _createServer

packages/vite/src/node/server/index.ts:479–1090  ·  packages/vite/src/node/server/index.ts::_createServer
(
  inlineConfig: ResolvedConfig | InlineConfig | undefined = {},
  options: {
    listen: boolean
    previousEnvironments?: Record<string, DevEnvironment>
    previousShortcutsState?: ShortcutsState<ViteDevServer>
    previousRestartPromise?: Promise<void> | null
    previousForceOptimizeOnRestart?: boolean
  },
)

Source from the content-addressed store, hash-verified

477}
478
479export async function _createServer(
480 inlineConfig: ResolvedConfig | InlineConfig | undefined = {},
481 options: {
482 listen: boolean
483 previousEnvironments?: Record<string, DevEnvironment>
484 previousShortcutsState?: ShortcutsState<ViteDevServer>
485 previousRestartPromise?: Promise<void> | null
486 previousForceOptimizeOnRestart?: boolean
487 },
488): Promise<ViteDevServer> {
489 class="cm">// The dev server is a long-running, interactive process whose outputs
490 class="cm">// (network responses, HMR updates) cannot be replayed from a cache.
491 disableCache()
492
493 const config = isResolvedConfig(inlineConfig)
494 ? inlineConfig
495 : await resolveConfig(inlineConfig, class="st">'serve')
496
497 if (usedConfigs.has(config)) {
498 throw new Error(`There is already a server associated with the config.`)
499 }
500
501 if (config.command !== class="st">'serve') {
502 throw new Error(
503 `Config was resolved for a class="st">"build", expected a class="st">"serve" command.`,
504 )
505 }
506
507 usedConfigs.add(config)
508
509 const initPublicFilesPromise = initPublicFiles(config)
510
511 const { root, server: serverConfig } = config
512 const httpsOptions = await resolveHttpsConfig(config.server.https)
513 const { middlewareMode } = serverConfig
514
515 const resolvedOutDirs = getResolvedOutDirs(
516 config.root,
517 config.build.outDir,
518 config.build.rolldownOptions.output,
519 )
520 const emptyOutDir = resolveEmptyOutDir(
521 config.build.emptyOutDir,
522 config.root,
523 resolvedOutDirs,
524 )
525 const resolvedWatchOptions = resolveChokidarOptions(
526 {
527 disableGlobbing: true,
528 ...serverConfig.watch,
529 },
530 resolvedOutDirs,
531 emptyOutDir,
532 config.cacheDir,
533 )
534
535 const middlewares = connect() as Connect.Server
536 const httpServer = middlewareMode

Callers 2

createServerFunction · 0.85
restartServerFunction · 0.85

Calls 15

isResolvedConfigFunction · 0.90
resolveConfigFunction · 0.90
initPublicFilesFunction · 0.90
resolveHttpsConfigFunction · 0.90
getResolvedOutDirsFunction · 0.90
resolveEmptyOutDirFunction · 0.90
resolveChokidarOptionsFunction · 0.90
resolveHttpServerFunction · 0.90
createWebSocketServerFunction · 0.90
setClientErrorHandlerFunction · 0.90
getEnvFilesForModeFunction · 0.90
createNoopWatcherFunction · 0.90

Tested by

no test coverage detected