From 3b29bd86f385d8dad2918f588639f4a9d226fac2 Mon Sep 17 00:00:00 2001 From: sapphi-red <49056869+sapphi-red@users.noreply.github.com> Date: Thu, 15 Aug 2024 17:51:17 +0900 Subject: [PATCH] refactor: replace `optimizeModulePreloadRelativePaths` with `isRelativeBase` --- packages/vite/src/node/plugins/importAnalysisBuild.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/packages/vite/src/node/plugins/importAnalysisBuild.ts b/packages/vite/src/node/plugins/importAnalysisBuild.ts index 851d455f8fe2e6..f02f2119ebdbf3 100644 --- a/packages/vite/src/node/plugins/importAnalysisBuild.ts +++ b/packages/vite/src/node/plugins/importAnalysisBuild.ts @@ -168,7 +168,6 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin { const renderBuiltUrl = config.experimental.renderBuiltUrl const isRelativeBase = config.base === './' || config.base === '' - const optimizeModulePreloadRelativePaths = isRelativeBase && !renderBuiltUrl const { modulePreload } = config.build const scriptRel = @@ -184,7 +183,7 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin { // using regex over this list to workaround the fact that module preload wasn't // configurable. const assetsURL = - renderBuiltUrl || optimizeModulePreloadRelativePaths + renderBuiltUrl || isRelativeBase ? // If `experimental.renderBuiltUrl` is used, the dependencies might be relative to the current chunk. // If relative base is used, the dependencies are relative to the current chunk. // The importerUrl is passed as third parameter to __vitePreload in this case @@ -343,9 +342,7 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin { str().appendRight( expEnd, `,${isModernFlag}?${preloadMarker}:void 0${ - optimizeModulePreloadRelativePaths || renderBuiltUrl - ? ',import.meta.url' - : '' + renderBuiltUrl || isRelativeBase ? ',import.meta.url' : '' })`, ) } @@ -623,7 +620,7 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin { renderedDeps = depsArray.map((d) => // Don't include the assets dir if the default asset file names // are used, the path will be reconstructed by the import preload helper - optimizeModulePreloadRelativePaths + isRelativeBase ? addFileDep(toRelativePath(d, file)) : addFileDep(d), )