From 8be0cd8b6a2a4183c11652ce7b0bf9f9a63c9fc9 Mon Sep 17 00:00:00 2001 From: Alec Larson <1925840+aleclarson@users.noreply.github.com> Date: Tue, 7 May 2024 18:37:47 -0400 Subject: [PATCH] fix: ensure transformIndexHtml url is relative to config.root --- packages/vite/src/node/server/middlewares/indexHtml.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/vite/src/node/server/middlewares/indexHtml.ts b/packages/vite/src/node/server/middlewares/indexHtml.ts index b5893dd072b972..88ec99edecdbcd 100644 --- a/packages/vite/src/node/server/middlewares/indexHtml.ts +++ b/packages/vite/src/node/server/middlewares/indexHtml.ts @@ -435,7 +435,14 @@ export function indexHtmlMiddleware( try { let html = await fsp.readFile(filePath, 'utf-8') if (isDev) { - html = await server.transformIndexHtml(url, html, req.originalUrl) + const resolvedUrl = + '/' + path.relative(server.config.root, filePath) + + html = await server.transformIndexHtml( + resolvedUrl, + html, + req.originalUrl, + ) } return send(req, res, html, 'html', { headers }) } catch (e) {