| 273 | } |
| 274 | |
| 275 | export 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) |