Skip to content

Commit

Permalink
refactor: replace optimizeModulePreloadRelativePaths with `isRelati…
Browse files Browse the repository at this point in the history
…veBase`
  • Loading branch information
sapphi-red committed Aug 15, 2024
1 parent ec82e19 commit 3b29bd8
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions packages/vite/src/node/plugins/importAnalysisBuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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
Expand Down Expand Up @@ -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' : ''
})`,
)
}
Expand Down Expand Up @@ -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),
)
Expand Down

0 comments on commit 3b29bd8

Please sign in to comment.