Skip to content

Commit 3b29bd8

Browse files
committed
refactor: replace optimizeModulePreloadRelativePaths with isRelativeBase
1 parent ec82e19 commit 3b29bd8

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

packages/vite/src/node/plugins/importAnalysisBuild.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {
168168

169169
const renderBuiltUrl = config.experimental.renderBuiltUrl
170170
const isRelativeBase = config.base === './' || config.base === ''
171-
const optimizeModulePreloadRelativePaths = isRelativeBase && !renderBuiltUrl
172171

173172
const { modulePreload } = config.build
174173
const scriptRel =
@@ -184,7 +183,7 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {
184183
// using regex over this list to workaround the fact that module preload wasn't
185184
// configurable.
186185
const assetsURL =
187-
renderBuiltUrl || optimizeModulePreloadRelativePaths
186+
renderBuiltUrl || isRelativeBase
188187
? // If `experimental.renderBuiltUrl` is used, the dependencies might be relative to the current chunk.
189188
// If relative base is used, the dependencies are relative to the current chunk.
190189
// The importerUrl is passed as third parameter to __vitePreload in this case
@@ -343,9 +342,7 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {
343342
str().appendRight(
344343
expEnd,
345344
`,${isModernFlag}?${preloadMarker}:void 0${
346-
optimizeModulePreloadRelativePaths || renderBuiltUrl
347-
? ',import.meta.url'
348-
: ''
345+
renderBuiltUrl || isRelativeBase ? ',import.meta.url' : ''
349346
})`,
350347
)
351348
}
@@ -623,7 +620,7 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {
623620
renderedDeps = depsArray.map((d) =>
624621
// Don't include the assets dir if the default asset file names
625622
// are used, the path will be reconstructed by the import preload helper
626-
optimizeModulePreloadRelativePaths
623+
isRelativeBase
627624
? addFileDep(toRelativePath(d, file))
628625
: addFileDep(d),
629626
)

0 commit comments

Comments
 (0)