optimizerResolvePlugin() — vite Function Reference
Architecture documentation for the optimizerResolvePlugin() function in resolve.ts from the vite codebase.
Entity Profile
Dependency Diagram
graph TD 7afe7894_efd7_32c4_3b59_4a2cdc5ba6a2["optimizerResolvePlugin()"] dcff87b0_a8ea_57a2_3b29_a7b8f19986f3["resolve.ts"] 7afe7894_efd7_32c4_3b59_4a2cdc5ba6a2 -->|defined in| dcff87b0_a8ea_57a2_3b29_a7b8f19986f3 0ac6860f_bc2f_9818_86d4_22179cc9c8ba["oxcResolvePlugin()"] 0ac6860f_bc2f_9818_86d4_22179cc9c8ba -->|calls| 7afe7894_efd7_32c4_3b59_4a2cdc5ba6a2 cf8cccc0_fa2a_e8ac_480a_47c54435825c["isDepOptimizationDisabled()"] 7afe7894_efd7_32c4_3b59_4a2cdc5ba6a2 -->|calls| cf8cccc0_fa2a_e8ac_480a_47c54435825c 2f0da199_9f02_5b00_9a83_0406650f871a["fsPathFromId()"] 7afe7894_efd7_32c4_3b59_4a2cdc5ba6a2 -->|calls| 2f0da199_9f02_5b00_9a83_0406650f871a a4adb1a7_cf54_091f_eb63_8217e684a8e1["normalizePath()"] 7afe7894_efd7_32c4_3b59_4a2cdc5ba6a2 -->|calls| a4adb1a7_cf54_091f_eb63_8217e684a8e1 298b86d6_4810_9884_d5fa_3e3077e2206a["isDataUrl()"] 7afe7894_efd7_32c4_3b59_4a2cdc5ba6a2 -->|calls| 298b86d6_4810_9884_d5fa_3e3077e2206a 23257aa1_5e3f_7e6e_1b43_875b139e4ec5["isExternalUrl()"] 7afe7894_efd7_32c4_3b59_4a2cdc5ba6a2 -->|calls| 23257aa1_5e3f_7e6e_1b43_875b139e4ec5 0e7dedc8_f980_705d_9b47_79e0785d8853["optimizedDepInfoFromFile()"] 7afe7894_efd7_32c4_3b59_4a2cdc5ba6a2 -->|calls| 0e7dedc8_f980_705d_9b47_79e0785d8853 1948f092_e5a5_076b_2f59_79ef22dec191["injectQuery()"] 7afe7894_efd7_32c4_3b59_4a2cdc5ba6a2 -->|calls| 1948f092_e5a5_076b_2f59_79ef22dec191 a2e55a70_b7b6_bce2_e066_aea4c516313e["tryOptimizedResolve()"] 7afe7894_efd7_32c4_3b59_4a2cdc5ba6a2 -->|calls| a2e55a70_b7b6_bce2_e066_aea4c516313e style 7afe7894_efd7_32c4_3b59_4a2cdc5ba6a2 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/vite/src/node/plugins/resolve.ts lines 387–489
function optimizerResolvePlugin(
resolveOptions: ResolvePluginOptionsWithOverrides,
): Plugin {
const { root, asSrc } = resolveOptions
return {
name: 'vite:resolve-dev',
applyToEnvironment(environment) {
return (
!environment.config.experimental.bundledDev &&
!isDepOptimizationDisabled(environment.config.optimizeDeps)
)
},
resolveId: {
filter: {
id: {
exclude: [
/^\0/,
/^virtual:/,
// When injected directly in html/client code
/^\/virtual:/,
/^__vite-/,
],
},
},
async handler(id, importer, resolveOpts) {
// The resolve plugin is used for createIdResolver and the depsOptimizer should be
// disabled in that case, so deps optimization is opt-in when creating the plugin.
const depsOptimizer =
resolveOptions.optimizeDeps && this.environment.mode === 'dev'
? this.environment.depsOptimizer
: undefined
if (!depsOptimizer) {
return
}
const options: InternalResolveOptions = {
isRequire: resolveOpts.kind === 'require-call',
...this.environment.config.resolve,
...resolveOptions,
scan: resolveOpts.scan ?? resolveOptions.scan,
}
options.preferRelative ||= importer?.endsWith('.html')
// resolve pre-bundled deps requests, these could be resolved by
// tryFileResolve or /fs/ resolution but these files may not yet
// exists if we are in the middle of a deps re-processing
if (asSrc && depsOptimizer.isOptimizedDepUrl(id)) {
const optimizedPath = id.startsWith(FS_PREFIX)
? fsPathFromId(id)
: normalizePath(path.resolve(root, id.slice(1)))
return optimizedPath
}
if (!isDataUrl(id) && !isExternalUrl(id)) {
if (
id[0] === '.' ||
(options.preferRelative && startsWithWordCharRE.test(id))
) {
const basedir = importer ? path.dirname(importer) : root
const fsPath = path.resolve(basedir, id)
// handle browser field mapping for relative imports
const normalizedFsPath = normalizePath(fsPath)
if (depsOptimizer.isOptimizedDepFile(normalizedFsPath)) {
// Optimized files could not yet exist in disk, resolve to the full path
// Inject the current browserHash version if the path doesn't have one
if (!DEP_VERSION_RE.test(normalizedFsPath)) {
const browserHash = optimizedDepInfoFromFile(
depsOptimizer.metadata,
normalizedFsPath,
)?.browserHash
if (browserHash) {
return injectQuery(normalizedFsPath, `v=${browserHash}`)
}
}
return normalizedFsPath
}
}
Domain
Subdomains
Defined In
Calls
Called By
Source
Frequently Asked Questions
What does optimizerResolvePlugin() do?
optimizerResolvePlugin() is a function in the vite codebase, defined in packages/vite/src/node/plugins/resolve.ts.
Where is optimizerResolvePlugin() defined?
optimizerResolvePlugin() is defined in packages/vite/src/node/plugins/resolve.ts at line 387.
What does optimizerResolvePlugin() call?
optimizerResolvePlugin() calls 8 function(s): fsPathFromId, injectQuery, isDataUrl, isDepOptimizationDisabled, isExternalUrl, normalizePath, optimizedDepInfoFromFile, tryOptimizedResolve.
What calls optimizerResolvePlugin()?
optimizerResolvePlugin() is called by 1 function(s): oxcResolvePlugin.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free