From 9164da0fe62cb85e77752849ea6d7a68287fb576 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Wouts?= Date: Fri, 24 Sep 2021 23:56:27 +1000 Subject: [PATCH] fix: normalize away `base` in imported URLs (#5065) * fix: normalize away `base` in imported URLs This fixes hot-reloading issues reported in https://github.com/vitejs/vite/issues/5063. * Update importAnalysis.ts Co-authored-by: Evan You --- packages/vite/src/node/plugins/importAnalysis.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/vite/src/node/plugins/importAnalysis.ts b/packages/vite/src/node/plugins/importAnalysis.ts index 191754572cb7a9..fa2d261f577004 100644 --- a/packages/vite/src/node/plugins/importAnalysis.ts +++ b/packages/vite/src/node/plugins/importAnalysis.ts @@ -312,6 +312,7 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin { str().prepend(importsString) str().overwrite(expStart, endIndex, exp) imports.forEach((url) => { + url = url.replace(base, '/') importedUrls.add(url) if (isEager) staticImportedUrls.add(url) }) @@ -411,10 +412,11 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin { // record for HMR import chain analysis // make sure to normalize away base - importedUrls.add(url) + const urlWithoutBase = url.replace(base, '/') + importedUrls.add(urlWithoutBase) if (!isDynamicImport) { // for pre-transforming - staticImportedUrls.add(url) + staticImportedUrls.add(urlWithoutBase) } } else if (!importer.startsWith(clientDir) && !ssr) { // check @vite-ignore which suppresses dynamic import warning