getPreloadCode() — vite Function Reference
Architecture documentation for the getPreloadCode() function in importAnalysisBuild.ts from the vite codebase.
Entity Profile
Dependency Diagram
graph TD 36e0844c_58c5_5f68_8102_cdd7d207e92c["getPreloadCode()"] 04ad4685_2ce3_556a_152b_c93668a74b3b["importAnalysisBuild.ts"] 36e0844c_58c5_5f68_8102_cdd7d207e92c -->|defined in| 04ad4685_2ce3_556a_152b_c93668a74b3b 6d315957_5b5c_845c_10c4_b8cb46bc58eb["buildImportAnalysisPlugin()"] 6d315957_5b5c_845c_10c4_b8cb46bc58eb -->|calls| 36e0844c_58c5_5f68_8102_cdd7d207e92c style 36e0844c_58c5_5f68_8102_cdd7d207e92c fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/vite/src/node/plugins/importAnalysisBuild.ts lines 165–195
function getPreloadCode(
environment: PartialEnvironment,
renderBuiltUrlBoolean: boolean,
isRelativeBase: boolean,
) {
const { modulePreload } = environment.config.build
const scriptRel =
modulePreload && modulePreload.polyfill
? `'modulepreload'`
: `/* @__PURE__ */ (${detectScriptRel.toString()})()`
// There are two different cases for the preload list format in __vitePreload
//
// __vitePreload(() => import(asyncChunk), [ ...deps... ])
//
// This is maintained to keep backwards compatibility as some users developed plugins
// using regex over this list to workaround the fact that module preload wasn't
// configurable.
const assetsURL =
renderBuiltUrlBoolean || 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
`function(dep, importerUrl) { return new URL(dep, importerUrl).href }`
: // If the base isn't relative, then the deps are relative to the projects `outDir` and the base
// is appended inside __vitePreload too.
`function(dep) { return ${JSON.stringify(environment.config.base)}+dep }`
const preloadCode = `const scriptRel = ${scriptRel};const assetsURL = ${assetsURL};const seen = {};export const ${preloadMethod} = ${preload.toString()}`
return preloadCode
}
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does getPreloadCode() do?
getPreloadCode() is a function in the vite codebase, defined in packages/vite/src/node/plugins/importAnalysisBuild.ts.
Where is getPreloadCode() defined?
getPreloadCode() is defined in packages/vite/src/node/plugins/importAnalysisBuild.ts at line 165.
What calls getPreloadCode()?
getPreloadCode() is called by 1 function(s): buildImportAnalysisPlugin.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free