async function createViteHandler(router, app, serveConfig) {
	const vite = await import("vite");
	const { getRandomPort } = await import("get-port-please");
	const port = router.server?.hmr?.port ?? (await getRandomPort());
	const plugins = [
		// ...(serveConfig.devtools ? [inspect()] : []),
		...(((await router.internals.type.dev.plugins?.(router, app)) ?? []).filter(
			Boolean,
		) || []),
		...(((await router.plugins?.(router)) ?? []).filter(Boolean) || []),
	].filter(Boolean);

	let base = join(app.config.server.baseURL ?? "/", router.base);

	const viteDevServer = await createViteDevServer({
		configFile: false,
		root: router.root,
		base,
		plugins,
		optimizeDeps: {
			force: serveConfig.force,
		},
		dev: serveConfig,
		mode: app.config.mode,
		router,
		app,
		server: {
			fs: {
				allow: [
					normalize(fileURLToPath(new URL("../", import.meta.url))),
					vite.searchForWorkspaceRoot(process.cwd()),
				],
			},
			middlewareMode: true,
			hmr: {
				...router.server?.hmr,
				port,
			},
			https: serveConfig.https,
		},
	});

	router.internals.devServer = viteDevServer;

	return viteDevServer;
}
@param {import('./app.js').App} app
@param {import('./router-mode.d.ts').Router<{ plugins?: any }>} router
@param {DevConfig} serveConfig
@returns {Promise<import("vite").ViteDevServer>}