Home / Function/ loadConfigWithVite() — astro Function Reference

loadConfigWithVite() — astro Function Reference

Architecture documentation for the loadConfigWithVite() function in vite-load.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  34aeeda0_ebd0_f6fc_0509_a1ce357978e9["loadConfigWithVite()"]
  1edbdccc_2250_215e_de88_373f8d8d7edb["vite-load.ts"]
  34aeeda0_ebd0_f6fc_0509_a1ce357978e9 -->|defined in| 1edbdccc_2250_215e_de88_373f8d8d7edb
  5c70b132_c34c_ccb3_a1f4_9cd0503ea565["createViteServer()"]
  34aeeda0_ebd0_f6fc_0509_a1ce357978e9 -->|calls| 5c70b132_c34c_ccb3_a1f4_9cd0503ea565
  style 34aeeda0_ebd0_f6fc_0509_a1ce357978e9 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/astro/src/core/config/vite-load.ts lines 33–73

export async function loadConfigWithVite({
	configPath,
	fs,
	root,
}: LoadConfigWithViteOptions): Promise<Record<string, any>> {
	if (/\.[cm]?js$/.test(configPath)) {
		try {
			const config = await import(pathToFileURL(configPath).toString() + '?t=' + Date.now());
			return config.default ?? {};
		} catch (e) {
			// Normally we silently ignore loading errors here because we'll try loading it again below using Vite
			// However, if the error is because of addons being disabled we rethrow it immediately,
			// because when this happens in Stackblitz, the Vite error below will be uncatchable
			// and we want to provide a more helpful error message.
			if (e && typeof e === 'object' && 'code' in e && e.code === 'ERR_DLOPEN_DISABLED') {
				throw e;
			}
			// We do not need to throw the error here as we have a Vite fallback below
			debug('Failed to load config with Node', e);
		}
	}

	// Try Loading with Vite
	let server: ViteDevServer | undefined;
	try {
		server = await createViteServer(root, fs);
		if (isRunnableDevEnvironment(server.environments[ASTRO_VITE_ENVIRONMENT_NAMES.ssr])) {
			const environment = server.environments[
				ASTRO_VITE_ENVIRONMENT_NAMES.ssr
			] as RunnableDevEnvironment;
			const mod = await environment.runner.import(configPath);
			return mod.default ?? {};
		} else {
			return {};
		}
	} finally {
		if (server) {
			await server.close();
		}
	}
}

Domain

Subdomains

Frequently Asked Questions

What does loadConfigWithVite() do?
loadConfigWithVite() is a function in the astro codebase, defined in packages/astro/src/core/config/vite-load.ts.
Where is loadConfigWithVite() defined?
loadConfigWithVite() is defined in packages/astro/src/core/config/vite-load.ts at line 33.
What does loadConfigWithVite() call?
loadConfigWithVite() calls 1 function(s): createViteServer.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free