(
inlineConfig: ResolvedConfig | InlineConfig | undefined = {},
options: {
listen: boolean
previousEnvironments?: Record<string, DevEnvironment>
previousShortcutsState?: ShortcutsState<ViteDevServer>
previousRestartPromise?: Promise<void> | null
previousForceOptimizeOnRestart?: boolean
},
)
| 477 | } |
| 478 | |
| 479 | export 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 |
no test coverage detected