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

Function startDefaultServe

playground/vitestSetup.ts:275–334  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

273}
274
275export async function startDefaultServe(): Promise<void> {
276 setupConsoleWarnCollector(serverLogs)
277
278 if (!isBuild) {
279 process.env.VITE_INLINE = 'inline-serve'
280 const config = await loadConfig({ command: 'serve', mode: 'development' })
281 viteServer = server = await (await createServer(config)).listen()
282 viteTestUrl = stripTrailingSlashIfNeeded(
283 server.resolvedUrls.local[0],
284 server.config.base,
285 )
286 await page.goto(viteTestUrl)
287 } else {
288 process.env.VITE_INLINE = 'inline-build'
289 let resolvedConfig: ResolvedConfig
290 // determine build watch
291 const resolvedPlugin: () => PluginOption = () => ({
292 name: 'vite-plugin-watcher',
293 configResolved(config) {
294 resolvedConfig = config
295 },
296 })
297 const buildConfig = mergeConfig(
298 await loadConfig({ command: 'build', mode: 'production' }),
299 {
300 plugins: [resolvedPlugin()],
301 },
302 )
303 if (buildConfig.builder) {
304 const builder = await createBuilder(buildConfig)
305 await builder.buildApp()
306 } else {
307 const rollupOutput = await build(buildConfig)
308 const isWatch = !!resolvedConfig!.build.watch
309 // in build watch,call startStaticServer after the build is complete
310 if (isWatch) {
311 watcher = rollupOutput as RolldownWatcher
312 await notifyRebuildComplete(watcher)
313 }
314 if (buildConfig.__test__) {
315 buildConfig.__test__()
316 }
317 }
318
319 const previewConfig = await loadConfig({
320 command: 'serve',
321 mode: 'development',
322 isPreview: true,
323 })
324 const _nodeEnv = process.env.NODE_ENV
325 const previewServer = await preview(previewConfig)
326 // prevent preview change NODE_ENV
327 process.env.NODE_ENV = _nodeEnv
328 viteTestUrl = stripTrailingSlashIfNeeded(
329 previewServer.resolvedUrls.local[0],
330 previewServer.config.base,
331 )
332 await page.goto(viteTestUrl)

Callers 4

vitestSetup.tsFile · 0.85
serveFunction · 0.85

Calls 12

createServerFunction · 0.90
mergeConfigFunction · 0.90
createBuilderFunction · 0.90
buildFunction · 0.90
previewFunction · 0.90
loadConfigFunction · 0.85
resolvedPluginFunction · 0.85
notifyRebuildCompleteFunction · 0.85
buildAppMethod · 0.80
listenMethod · 0.65

Tested by 1

serveFunction · 0.68