@@ -168,29 +168,24 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {
168
168
169
169
const renderBuiltUrl = config . experimental . renderBuiltUrl
170
170
const isRelativeBase = config . base === './' || config . base === ''
171
- const optimizeModulePreloadRelativePaths = isRelativeBase && ! renderBuiltUrl
172
171
173
172
const { modulePreload } = config . build
174
173
const scriptRel =
175
174
modulePreload && modulePreload . polyfill
176
175
? `'modulepreload'`
177
176
: `(${ detectScriptRel . toString ( ) } )()`
178
177
179
- // There are three different cases for the preload list format in __vitePreload
178
+ // There are two different cases for the preload list format in __vitePreload
180
179
//
181
180
// __vitePreload(() => import(asyncChunk), [ ...deps... ])
182
181
//
183
182
// This is maintained to keep backwards compatibility as some users developed plugins
184
183
// using regex over this list to workaround the fact that module preload wasn't
185
184
// configurable.
186
- const assetsURL = renderBuiltUrl
187
- ? // If `experimental.renderBuiltUrl` is used, the dependencies are already resolved.
188
- // To avoid the need for `new URL(dep, import.meta.url)`, a helper `__vitePreloadRelativeDep` is
189
- // used to resolve from relative paths which can be minimized.
190
- `function(dep, importerUrl) { return dep[0] === '.' ? new URL(dep, importerUrl).href : dep }`
191
- : optimizeModulePreloadRelativePaths
192
- ? // If there isn't custom resolvers affecting the deps list, deps in the list are relative
193
- // to the current chunk and are resolved to absolute URL by the __vitePreload helper itself.
185
+ const assetsURL =
186
+ renderBuiltUrl || isRelativeBase
187
+ ? // If `experimental.renderBuiltUrl` is used, the dependencies might be relative to the current chunk.
188
+ // If relative base is used, the dependencies are relative to the current chunk.
194
189
// The importerUrl is passed as third parameter to __vitePreload in this case
195
190
`function(dep, importerUrl) { return new URL(dep, importerUrl).href }`
196
191
: // If the base isn't relative, then the deps are relative to the projects `outDir` and the base
@@ -347,9 +342,7 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {
347
342
str ( ) . appendRight (
348
343
expEnd ,
349
344
`,${ isModernFlag } ?${ preloadMarker } :void 0${
350
- optimizeModulePreloadRelativePaths || renderBuiltUrl
351
- ? ',import.meta.url'
352
- : ''
345
+ renderBuiltUrl || isRelativeBase ? ',import.meta.url' : ''
353
346
} )`,
354
347
)
355
348
}
@@ -627,7 +620,7 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {
627
620
renderedDeps = depsArray . map ( ( d ) =>
628
621
// Don't include the assets dir if the default asset file names
629
622
// are used, the path will be reconstructed by the import preload helper
630
- optimizeModulePreloadRelativePaths
623
+ isRelativeBase
631
624
? addFileDep ( toRelativePath ( d , file ) )
632
625
: addFileDep ( d ) ,
633
626
)
0 commit comments