loadConfigFromBundledFile() — vite Function Reference
Architecture documentation for the loadConfigFromBundledFile() function in config.ts from the vite codebase.
Entity Profile
Dependency Diagram
graph TD e46831fe_fe57_af33_e590_6a52696d5e24["loadConfigFromBundledFile()"] 7da774f9_eca5_d54e_6e01_6bee7d460a2b["config.ts"] e46831fe_fe57_af33_e590_6a52696d5e24 -->|defined in| 7da774f9_eca5_d54e_6e01_6bee7d460a2b de2a20c0_a4a2_f7c1_abd6_414c8a78818e["bundleAndLoadConfigFile()"] de2a20c0_a4a2_f7c1_abd6_414c8a78818e -->|calls| e46831fe_fe57_af33_e590_6a52696d5e24 aae4a831_d171_baad_6619_f1acbd0d7fae["findNearestNodeModules()"] e46831fe_fe57_af33_e590_6a52696d5e24 -->|calls| aae4a831_d171_baad_6619_f1acbd0d7fae dfa2b928_25a4_a78f_1e11_1e7e643cae09["resolve()"] e46831fe_fe57_af33_e590_6a52696d5e24 -->|calls| dfa2b928_25a4_a78f_1e11_1e7e643cae09 style e46831fe_fe57_af33_e590_6a52696d5e24 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/vite/src/node/config.ts lines 2544–2611
async function loadConfigFromBundledFile(
fileName: string,
bundledCode: string,
isESM: boolean,
): Promise<UserConfigExport> {
// for esm, before we can register loaders without requiring users to run node
// with --experimental-loader themselves, we have to do a hack here:
// write it to disk, load it with native Node ESM, then delete the file.
if (isESM) {
// Storing the bundled file in node_modules/ is avoided for Deno
// because Deno only supports Node.js style modules under node_modules/
// and configs with `npm:` import statements will fail when executed.
let nodeModulesDir =
typeof process.versions.deno === 'string'
? undefined
: findNearestNodeModules(path.dirname(fileName))
if (nodeModulesDir) {
try {
await fsp.mkdir(path.resolve(nodeModulesDir, '.vite-temp/'), {
recursive: true,
})
} catch (e) {
if (e.code === 'EACCES') {
// If there is no access permission, a temporary configuration file is created by default.
nodeModulesDir = undefined
} else {
throw e
}
}
}
const hash = `timestamp-${Date.now()}-${Math.random().toString(16).slice(2)}`
const tempFileName = nodeModulesDir
? path.resolve(
nodeModulesDir,
`.vite-temp/${path.basename(fileName)}.${hash}.mjs`,
)
: `${fileName}.${hash}.mjs`
await fsp.writeFile(tempFileName, bundledCode)
try {
return (await import(pathToFileURL(tempFileName).href)).default
} finally {
fs.unlink(tempFileName, () => {}) // Ignore errors
}
}
// for cjs, we can register a custom loader via `_require.extensions`
else {
const extension = path.extname(fileName)
// We don't use fsp.realpath() here because it has the same behaviour as
// fs.realpath.native. On some Windows systems, it returns uppercase volume
// letters (e.g. "C:\") while the Node.js loader uses lowercase volume letters.
// See https://github.com/vitejs/vite/issues/12923
const realFileName = await promisifiedRealpath(fileName)
const loaderExt = extension in _require.extensions ? extension : '.js'
const defaultLoader = _require.extensions[loaderExt]!
_require.extensions[loaderExt] = (module: NodeModule, filename: string) => {
if (filename === realFileName) {
;(module as NodeModuleWithCompile)._compile(bundledCode, filename)
} else {
defaultLoader(module, filename)
}
}
// clear cache in case of server restart
delete _require.cache[_require.resolve(fileName)]
const raw = _require(fileName)
_require.extensions[loaderExt] = defaultLoader
return raw.__esModule ? raw.default : raw
}
}
Domain
Subdomains
Defined In
Called By
Source
Frequently Asked Questions
What does loadConfigFromBundledFile() do?
loadConfigFromBundledFile() is a function in the vite codebase, defined in packages/vite/src/node/config.ts.
Where is loadConfigFromBundledFile() defined?
loadConfigFromBundledFile() is defined in packages/vite/src/node/config.ts at line 2544.
What does loadConfigFromBundledFile() call?
loadConfigFromBundledFile() calls 2 function(s): findNearestNodeModules, resolve.
What calls loadConfigFromBundledFile()?
loadConfigFromBundledFile() is called by 1 function(s): bundleAndLoadConfigFile.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free