@@ -122,8 +122,9 @@ function preload(
122
122
link . as = 'script'
123
123
// @ts -expect-error crossOrigin is declared before preload.toString()
124
124
if ( crossOrigin )
125
- // @ts -expect-error crossOrigin is declared before preload.toString()
126
- link . crossOrigin = typeof crossOrigin === 'string' ? crossOrigin : ''
125
+ link . crossOrigin =
126
+ // @ts -expect-error crossOrigin is declared before preload.toString()
127
+ typeof crossOrigin === 'string' ? crossOrigin : ''
127
128
}
128
129
link . href = dep
129
130
if ( cspNonce ) {
@@ -190,18 +191,21 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {
190
191
// configurable.
191
192
const assetsURL = customModulePreloadPaths
192
193
? // If `experimental.renderBuiltUrl` or `build.modulePreload.resolveDependencies` are used
193
- // the dependencies are already resolved. To avoid the need for `new URL(dep, import.meta.url)`
194
- // a helper `__vitePreloadRelativeDep` is used to resolve from relative paths which can be minimized.
195
- `function(dep, importerUrl) { return dep[0] === '.' ? new URL(dep, importerUrl).href : dep }`
194
+ // the dependencies are already resolved. To avoid the need for `new URL(dep, import.meta.url)`
195
+ // a helper `__vitePreloadRelativeDep` is used to resolve from relative paths which can be minimized.
196
+ `function(dep, importerUrl) { return dep[0] === '.' ? new URL(dep, importerUrl).href : dep }`
196
197
: optimizeModulePreloadRelativePaths
197
198
? // If there isn't custom resolvers affecting the deps list, deps in the list are relative
198
- // to the current chunk and are resolved to absolute URL by the __vitePreload helper itself.
199
- // The importerUrl is passed as third parameter to __vitePreload in this case
200
- `function(dep, importerUrl) { return new URL(dep, importerUrl).href }`
199
+ // to the current chunk and are resolved to absolute URL by the __vitePreload helper itself.
200
+ // The importerUrl is passed as third parameter to __vitePreload in this case
201
+ `function(dep, importerUrl) { return new URL(dep, importerUrl).href }`
201
202
: // If the base isn't relative, then the deps are relative to the projects `outDir` and the base
202
- // is appended inside __vitePreload too.
203
- `function(dep) { return ${ JSON . stringify ( config . base ) } +dep }`
204
- const crossOrigin = typeof modulePreloadCrossOrigin === 'string' ? `'${ modulePreloadCrossOrigin } '` : modulePreloadCrossOrigin
203
+ // is appended inside __vitePreload too.
204
+ `function(dep) { return ${ JSON . stringify ( config . base ) } +dep }`
205
+ const crossOrigin =
206
+ typeof modulePreloadCrossOrigin === 'string'
207
+ ? `'${ modulePreloadCrossOrigin } '`
208
+ : modulePreloadCrossOrigin
205
209
const preloadCode = `const scriptRel = ${ scriptRel } ;const assetsURL = ${ assetsURL } ;const seen = {};const crossOrigin = ${ crossOrigin } ;export const ${ preloadMethod } = ${ preload . toString ( ) } `
206
210
207
211
return {
@@ -274,9 +278,10 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {
274
278
str ( ) . prependLeft ( expStart , `${ preloadMethod } (() => ` )
275
279
str ( ) . appendRight (
276
280
expEnd ,
277
- `,${ isModernFlag } ?${ preloadMarker } :void 0${ optimizeModulePreloadRelativePaths || customModulePreloadPaths
278
- ? ',import.meta.url'
279
- : ''
281
+ `,${ isModernFlag } ?${ preloadMarker } :void 0${
282
+ optimizeModulePreloadRelativePaths || customModulePreloadPaths
283
+ ? ',import.meta.url'
284
+ : ''
280
285
} )`,
281
286
)
282
287
}
@@ -501,12 +506,12 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {
501
506
// the dep list includes the main chunk, so only need to reload when there are actual other deps.
502
507
const depsArray =
503
508
deps . size > 1 ||
504
- // main chunk is removed
505
- ( hasRemovedPureCssChunk && deps . size > 0 )
509
+ // main chunk is removed
510
+ ( hasRemovedPureCssChunk && deps . size > 0 )
506
511
? modulePreload === false
507
512
? // CSS deps use the same mechanism as module preloads, so even if disabled,
508
- // we still need to pass these deps to the preload helper in dynamic imports.
509
- [ ...deps ] . filter ( ( d ) => d . endsWith ( '.css' ) )
513
+ // we still need to pass these deps to the preload helper in dynamic imports.
514
+ [ ...deps ] . filter ( ( d ) => d . endsWith ( '.css' ) )
510
515
: [ ...deps ]
511
516
: [ ]
512
517
@@ -523,7 +528,7 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {
523
528
const cssDeps : string [ ] = [ ]
524
529
const otherDeps : string [ ] = [ ]
525
530
for ( const dep of depsArray ) {
526
- ; ( dep . endsWith ( '.css' ) ? cssDeps : otherDeps ) . push ( dep )
531
+ ; ( dep . endsWith ( '.css' ) ? cssDeps : otherDeps ) . push ( dep )
527
532
}
528
533
resolvedDeps = [
529
534
...resolveDependencies ( normalizedFile , otherDeps , {
0 commit comments