Skip to content

Commit ec27480

Browse files
committed
chore: format code
1 parent 6debed4 commit ec27480

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

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

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,9 @@ function preload(
122122
link.as = 'script'
123123
// @ts-expect-error crossOrigin is declared before preload.toString()
124124
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 : ''
127128
}
128129
link.href = dep
129130
if (cspNonce) {
@@ -190,18 +191,21 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {
190191
// configurable.
191192
const assetsURL = customModulePreloadPaths
192193
? // 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 }`
196197
: optimizeModulePreloadRelativePaths
197198
? // 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 }`
201202
: // 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
205209
const preloadCode = `const scriptRel = ${scriptRel};const assetsURL = ${assetsURL};const seen = {};const crossOrigin = ${crossOrigin};export const ${preloadMethod} = ${preload.toString()}`
206210

207211
return {
@@ -274,9 +278,10 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {
274278
str().prependLeft(expStart, `${preloadMethod}(() => `)
275279
str().appendRight(
276280
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+
: ''
280285
})`,
281286
)
282287
}
@@ -501,12 +506,12 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {
501506
// the dep list includes the main chunk, so only need to reload when there are actual other deps.
502507
const depsArray =
503508
deps.size > 1 ||
504-
// main chunk is removed
505-
(hasRemovedPureCssChunk && deps.size > 0)
509+
// main chunk is removed
510+
(hasRemovedPureCssChunk && deps.size > 0)
506511
? modulePreload === false
507512
? // 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'))
510515
: [...deps]
511516
: []
512517

@@ -523,7 +528,7 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {
523528
const cssDeps: string[] = []
524529
const otherDeps: string[] = []
525530
for (const dep of depsArray) {
526-
; (dep.endsWith('.css') ? cssDeps : otherDeps).push(dep)
531+
;(dep.endsWith('.css') ? cssDeps : otherDeps).push(dep)
527532
}
528533
resolvedDeps = [
529534
...resolveDependencies(normalizedFile, otherDeps, {

0 commit comments

Comments
 (0)