Home / Function/ virtualModulePlugin() — astro Function Reference

virtualModulePlugin() — astro Function Reference

Architecture documentation for the virtualModulePlugin() function in virtual-module.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  f9914014_4121_8b57_762e_2f57ab2c3858["virtualModulePlugin()"]
  85e53bb9_8e7d_d72e_753a_aada8d95b40a["virtual-module.ts"]
  f9914014_4121_8b57_762e_2f57ab2c3858 -->|defined in| 85e53bb9_8e7d_d72e_753a_aada8d95b40a
  style f9914014_4121_8b57_762e_2f57ab2c3858 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/astro/src/manifest/virtual-module.ts lines 11–118

export default function virtualModulePlugin(): Plugin {
	return {
		name: 'astro-manifest-plugin',
		resolveId: {
			filter: {
				id: new RegExp(`^(${VIRTUAL_SERVER_ID}|${VIRTUAL_CLIENT_ID})$`),
			},
			handler(id) {
				if (id === VIRTUAL_SERVER_ID) {
					return RESOLVED_VIRTUAL_SERVER_ID;
				}
				if (id === VIRTUAL_CLIENT_ID) {
					return RESOLVED_VIRTUAL_CLIENT_ID;
				}
			},
		},
		load: {
			filter: {
				id: new RegExp(`^(${RESOLVED_VIRTUAL_SERVER_ID}|${RESOLVED_VIRTUAL_CLIENT_ID})$`),
			},
			handler(id) {
				if (id === RESOLVED_VIRTUAL_CLIENT_ID) {
					// There's nothing wrong about using `/client` on the server
					const code = `
import { manifest } from '${SERIALIZED_MANIFEST_ID}'
import { fromRoutingStrategy } from 'astro/app';

let i18n = undefined;
if (manifest.i18n) {
i18n = {
  defaultLocale: manifest.i18n.defaultLocale,
  locales: manifest.i18n.locales,
  routing: fromRoutingStrategy(manifest.i18n.strategy, manifest.i18n.fallbackType),
  fallback: manifest.i18n.fallback
  };
}

const base = manifest.base;
const trailingSlash = manifest.trailingSlash;
const site = manifest.site;
const compressHTML = manifest.compressHTML;
const build = {
  format: manifest.buildFormat,
};

export { base, i18n, trailingSlash, site, compressHTML, build };
				`;
					return { code };
				}
				if (id == RESOLVED_VIRTUAL_SERVER_ID) {
					if (this.environment.name === ASTRO_VITE_ENVIRONMENT_NAMES.client) {
						throw new AstroError({
							...AstroErrorData.ServerOnlyModule,
							message: AstroErrorData.ServerOnlyModule.message(VIRTUAL_SERVER_ID),
						});
					}
					const code = `
import { manifest } from '${SERIALIZED_MANIFEST_ID}'
import { fromRoutingStrategy } from "astro/app";

let i18n = undefined;
if (manifest.i18n) {
 i18n = {
   defaultLocale: manifest.i18n.defaultLocale,
   locales: manifest.i18n.locales,
   routing: fromRoutingStrategy(manifest.i18n.strategy, manifest.i18n.fallbackType),
   fallback: manifest.i18n.fallback,
   domains: manifest.i18n.domains,
 };
}

const base = manifest.base;
const build = {
  server: new URL(manifest.buildServerDir),
  client: new URL(manifest.buildClientDir),
  format: manifest.buildFormat,
};

const cacheDir = new URL(manifest.cacheDir);
const outDir = new URL(manifest.outDir);
const publicDir = new URL(manifest.publicDir);

Domain

Subdomains

Frequently Asked Questions

What does virtualModulePlugin() do?
virtualModulePlugin() is a function in the astro codebase, defined in packages/astro/src/manifest/virtual-module.ts.
Where is virtualModulePlugin() defined?
virtualModulePlugin() is defined in packages/astro/src/manifest/virtual-module.ts at line 11.

Analyze Your Own Codebase

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

Try Supermodel Free