From 98c89c6fcceb40eff98487553241243871ea50f7 Mon Sep 17 00:00:00 2001 From: FinalAshen <819712530@qq.com> Date: Wed, 17 Apr 2024 18:57:07 +0800 Subject: [PATCH 1/2] fix: add base to virtual html --- packages/vite/src/node/server/middlewares/indexHtml.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vite/src/node/server/middlewares/indexHtml.ts b/packages/vite/src/node/server/middlewares/indexHtml.ts index 5d06f1292b87fa..9213b59e11417e 100644 --- a/packages/vite/src/node/server/middlewares/indexHtml.ts +++ b/packages/vite/src/node/server/middlewares/indexHtml.ts @@ -200,7 +200,7 @@ const devHtmlHook: IndexHtmlTransformHook = async ( // and ids are properly handled const validPath = `${htmlPath}${trailingSlash ? 'index.html' : ''}` proxyModulePath = `\0${validPath}` - proxyModuleUrl = wrapId(proxyModulePath) + proxyModuleUrl = joinUrlSegments(base, wrapId(proxyModulePath)) } const s = new MagicString(html) From 108c9bc484bff25091dc06ac227f4d3a9a399a6d Mon Sep 17 00:00:00 2001 From: FinalAshen <819712530@qq.com> Date: Thu, 18 Apr 2024 23:12:59 +0800 Subject: [PATCH 2/2] chore: logic adjustment --- packages/vite/src/node/server/middlewares/indexHtml.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/vite/src/node/server/middlewares/indexHtml.ts b/packages/vite/src/node/server/middlewares/indexHtml.ts index 9213b59e11417e..b5893dd072b972 100644 --- a/packages/vite/src/node/server/middlewares/indexHtml.ts +++ b/packages/vite/src/node/server/middlewares/indexHtml.ts @@ -191,7 +191,7 @@ const devHtmlHook: IndexHtmlTransformHook = async ( const trailingSlash = htmlPath.endsWith('/') if (!trailingSlash && getFsUtils(config).existsSync(filename)) { proxyModulePath = htmlPath - proxyModuleUrl = joinUrlSegments(base, htmlPath) + proxyModuleUrl = proxyModulePath } else { // There are users of vite.transformIndexHtml calling it with url '/' // for SSR integrations #7993, filename is root for this case @@ -200,8 +200,9 @@ const devHtmlHook: IndexHtmlTransformHook = async ( // and ids are properly handled const validPath = `${htmlPath}${trailingSlash ? 'index.html' : ''}` proxyModulePath = `\0${validPath}` - proxyModuleUrl = joinUrlSegments(base, wrapId(proxyModulePath)) + proxyModuleUrl = wrapId(proxyModulePath) } + proxyModuleUrl = joinUrlSegments(base, proxyModuleUrl) const s = new MagicString(html) let inlineModuleIndex = -1