astroHeadBuildPlugin() — astro Function Reference
Architecture documentation for the astroHeadBuildPlugin() function in index.ts from the astro codebase.
Entity Profile
Dependency Diagram
graph TD 62f8b26a_0aeb_6311_c36a_82d2d99343a2["astroHeadBuildPlugin()"] bf5798b6_a592_be5c_0413_36786059a0dc["index.ts"] 62f8b26a_0aeb_6311_c36a_82d2d99343a2 -->|defined in| bf5798b6_a592_be5c_0413_36786059a0dc style 62f8b26a_0aeb_6311_c36a_82d2d99343a2 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/astro/src/vite-plugin-head/index.ts lines 89–144
export function astroHeadBuildPlugin(internals: BuildInternals): vite.Plugin {
return {
name: 'astro:head-metadata-build',
applyToEnvironment(environment) {
return (
environment.name === ASTRO_VITE_ENVIRONMENT_NAMES.ssr ||
environment.name === ASTRO_VITE_ENVIRONMENT_NAMES.prerender
);
},
generateBundle(_opts, bundle) {
const map: SSRResult['componentMetadata'] = internals.componentMetadata;
function getOrCreateMetadata(id: string): SSRComponentMetadata {
if (map.has(id)) return map.get(id)!;
const metadata: SSRComponentMetadata = {
propagation: 'none',
containsHead: false,
};
map.set(id, metadata);
return metadata;
}
for (const [, output] of Object.entries(bundle)) {
if (output.type !== 'chunk') continue;
for (const [id, mod] of Object.entries(output.modules)) {
const modinfo = this.getModuleInfo(id);
// <head> tag in the tree
if (modinfo) {
const meta = getAstroMetadata(modinfo);
if (meta?.containsHead) {
for (const pageInfo of getTopLevelPageModuleInfos(id, this)) {
let metadata = getOrCreateMetadata(pageInfo.id);
metadata.containsHead = true;
}
}
if (meta?.propagation === 'self') {
for (const info of getParentModuleInfos(id, this)) {
let metadata = getOrCreateMetadata(info.id);
if (metadata.propagation !== 'self') {
metadata.propagation = 'in-tree';
}
}
}
}
// Head propagation (aka bubbling)
if (mod.code && injectExp.test(mod.code)) {
for (const info of getParentModuleInfos(id, this)) {
getOrCreateMetadata(info.id).propagation = 'in-tree';
}
}
}
}
},
};
}
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does astroHeadBuildPlugin() do?
astroHeadBuildPlugin() is a function in the astro codebase, defined in packages/astro/src/vite-plugin-head/index.ts.
Where is astroHeadBuildPlugin() defined?
astroHeadBuildPlugin() is defined in packages/astro/src/vite-plugin-head/index.ts at line 89.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free