MCPcopy
hub / github.com/vitejs/vite / bundleConfigFile

Function bundleConfigFile

packages/vite/src/node/config.ts:2421–2584  ·  view source on GitHub ↗
(
  fileName: string,
  isESM: boolean,
)

Source from the content-addressed store, hash-verified

2419}
2420
2421async function bundleConfigFile(
2422 fileName: string,
2423 isESM: boolean,
2424): Promise<{ code: string; dependencies: string[] }> {
2425 let importMetaResolverRegistered = false
2426
2427 const root = path.dirname(fileName)
2428 const dirnameVarName = '__vite_injected_original_dirname'
2429 const filenameVarName = '__vite_injected_original_filename'
2430 const importMetaUrlVarName = '__vite_injected_original_import_meta_url'
2431 const importMetaResolveVarName =
2432 '__vite_injected_original_import_meta_resolve'
2433 const importMetaResolveRegex = /import\.meta\s*\.\s*resolve/
2434
2435 const bundle = await rolldown({
2436 input: fileName,
2437 // target: [`node${process.versions.node}`],
2438 platform: 'node',
2439 resolve: {
2440 mainFields: ['main'],
2441 },
2442 transform: {
2443 define: {
2444 __dirname: dirnameVarName,
2445 __filename: filenameVarName,
2446 'import.meta.url': importMetaUrlVarName,
2447 'import.meta.dirname': dirnameVarName,
2448 'import.meta.filename': filenameVarName,
2449 'import.meta.resolve': importMetaResolveVarName,
2450 'import.meta.main': 'false',
2451 },
2452 },
2453 // disable treeshake to include files that is not sideeffectful to `moduleIds`
2454 treeshake: false,
2455 // disable tsconfig as it's confusing to respect tsconfig options in the config file
2456 // this also aligns with other config loader behaviors
2457 tsconfig: false,
2458 plugins: [
2459 {
2460 name: 'externalize-deps',
2461 resolveId: {
2462 filter: { id: /^[^.#].*/ },
2463 handler(id, importer, { kind }) {
2464 if (!importer || path.isAbsolute(id) || isNodeBuiltin(id)) {
2465 return
2466 }
2467
2468 // With the `isNodeBuiltin` check above, this check captures if the builtin is a
2469 // non-node built-in, which esbuild doesn't know how to handle. In that case, we
2470 // externalize it so the non-node runtime handles it instead.
2471 if (isNodeLikeBuiltin(id) || id.startsWith('npm:')) {
2472 return { id, external: true }
2473 }
2474
2475 const isImport = isESM || kind === 'dynamic-import'
2476 let idFsPath: string | undefined
2477 try {
2478 idFsPath = nodeResolveWithVite(id, importer, {

Callers 1

bundleAndLoadConfigFileFunction · 0.85

Calls 2

collectAllModulesFunction · 0.85
closeMethod · 0.65

Tested by

no test coverage detected