vite-load.ts — astro Source File
Architecture documentation for vite-load.ts, a typescript file in the astro codebase. 6 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 1edbdccc_2250_215e_de88_373f8d8d7edb["vite-load.ts"] 49e88894_94bc_c827_7778_9fb0354de244["../vite-plugin-load-fallback/index.js"] 1edbdccc_2250_215e_de88_373f8d8d7edb --> 49e88894_94bc_c827_7778_9fb0354de244 d3861967_b647_84d2_ff48_15013353bd56["../core/logger/core.js"] 1edbdccc_2250_215e_de88_373f8d8d7edb --> d3861967_b647_84d2_ff48_15013353bd56 7216d952_4e4a_2d18_a85b_74b4ace79e2b["../core/constants.js"] 1edbdccc_2250_215e_de88_373f8d8d7edb --> 7216d952_4e4a_2d18_a85b_74b4ace79e2b e16a223b_37f3_6b25_1ee1_2b7bcb9d9415["node:fs"] 1edbdccc_2250_215e_de88_373f8d8d7edb --> e16a223b_37f3_6b25_1ee1_2b7bcb9d9415 d9a92db9_c95e_9165_13ac_24b3d859d946["node:url"] 1edbdccc_2250_215e_de88_373f8d8d7edb --> d9a92db9_c95e_9165_13ac_24b3d859d946 263e522e_1aa5_ebc3_e7d6_45ebc51671f7["vite"] 1edbdccc_2250_215e_de88_373f8d8d7edb --> 263e522e_1aa5_ebc3_e7d6_45ebc51671f7 style 1edbdccc_2250_215e_de88_373f8d8d7edb fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import type fsType from 'node:fs';
import { pathToFileURL } from 'node:url';
import {
createServer,
isRunnableDevEnvironment,
type RunnableDevEnvironment,
type ViteDevServer,
} from 'vite';
import loadFallbackPlugin from '../../vite-plugin-load-fallback/index.js';
import { debug } from '../logger/core.js';
import { ASTRO_VITE_ENVIRONMENT_NAMES } from '../constants.js';
async function createViteServer(root: string, fs: typeof fsType): Promise<ViteDevServer> {
const viteServer = await createServer({
configFile: false,
server: { middlewareMode: true, hmr: false, watch: null, ws: false },
optimizeDeps: { noDiscovery: true },
clearScreen: false,
appType: 'custom',
ssr: { external: true },
plugins: [loadFallbackPlugin({ fs, root: pathToFileURL(root) })],
});
return viteServer;
}
interface LoadConfigWithViteOptions {
root: string;
configPath: string;
fs: typeof fsType;
}
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
Functions
Dependencies
- ../core/constants.js
- ../core/logger/core.js
- ../vite-plugin-load-fallback/index.js
- node:fs
- node:url
- vite
Source
Frequently Asked Questions
What does vite-load.ts do?
vite-load.ts is a source file in the astro codebase, written in typescript. It belongs to the CoreAstro domain, RenderingEngine subdomain.
What functions are defined in vite-load.ts?
vite-load.ts defines 2 function(s): createViteServer, loadConfigWithVite.
What does vite-load.ts depend on?
vite-load.ts imports 6 module(s): ../core/constants.js, ../core/logger/core.js, ../vite-plugin-load-fallback/index.js, node:fs, node:url, vite.
Where is vite-load.ts in the architecture?
vite-load.ts is located at packages/astro/src/core/config/vite-load.ts (domain: CoreAstro, subdomain: RenderingEngine, directory: packages/astro/src/core/config).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free