diff --git a/packages/dev-server/src/dev-server.ts b/packages/dev-server/src/dev-server.ts index 87bca07..1586e55 100644 --- a/packages/dev-server/src/dev-server.ts +++ b/packages/dev-server/src/dev-server.ts @@ -165,7 +165,7 @@ export function devServer(options?: DevServerOptions): VitePlugin { response.headers.get('content-type')?.match(/^text\/html/) ) { const script = '' - return injectStringToResponse(response, script) + return transformHTML(injectStringToResponse(response, script), server, req.url) } return response }, @@ -277,3 +277,10 @@ function injectStringToResponse(response: Response, content: string) { status: response.status, }) } + +async function transformHTML (response: Response | null, viteServer: ViteDevServer, url: string) { + if(!response) return null + const html = await response.text() + const htmlTransformed = await viteServer.transformIndexHtml(url, html) + return new Response(htmlTransformed, {headers: response.headers, status: response.status}) +}