injectToBody() — vite Function Reference
Architecture documentation for the injectToBody() function in html.ts from the vite codebase.
Entity Profile
Dependency Diagram
graph TD 24734732_0f40_e935_b5d1_ae08e9d1dca3["injectToBody()"] f8fe0737_718a_5509_b722_473f207d5906["html.ts"] 24734732_0f40_e935_b5d1_ae08e9d1dca3 -->|defined in| f8fe0737_718a_5509_b722_473f207d5906 979ed295_1d80_37c1_156b_2bbf25fc21e4["applyHtmlTransforms()"] 979ed295_1d80_37c1_156b_2bbf25fc21e4 -->|calls| 24734732_0f40_e935_b5d1_ae08e9d1dca3 bb1d8b71_73c3_31ff_7d80_88303fc49280["serializeTags()"] 24734732_0f40_e935_b5d1_ae08e9d1dca3 -->|calls| bb1d8b71_73c3_31ff_7d80_88303fc49280 be79b558_1081_1230_d1d0_4753d396fd49["incrementIndent()"] 24734732_0f40_e935_b5d1_ae08e9d1dca3 -->|calls| be79b558_1081_1230_d1d0_4753d396fd49 3df96a2a_db85_aa8f_52e1_204c48938b88["prependInjectFallback()"] 24734732_0f40_e935_b5d1_ae08e9d1dca3 -->|calls| 3df96a2a_db85_aa8f_52e1_204c48938b88 style 24734732_0f40_e935_b5d1_ae08e9d1dca3 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/vite/src/node/plugins/html.ts lines 1489–1526
function injectToBody(
html: string,
tags: HtmlTagDescriptor[],
prepend = false,
) {
if (tags.length === 0) return html
if (prepend) {
// inject after body open
if (bodyPrependInjectRE.test(html)) {
return html.replace(
bodyPrependInjectRE,
(match, p1) => `${match}\n${serializeTags(tags, incrementIndent(p1))}`,
)
}
// if no there is no body tag, inject after head or fallback to prepend in html
if (headInjectRE.test(html)) {
return html.replace(
headInjectRE,
(match, p1) => `${match}\n${serializeTags(tags, p1)}`,
)
}
return prependInjectFallback(html, tags)
} else {
// inject before body close
if (bodyInjectRE.test(html)) {
return html.replace(
bodyInjectRE,
(match, p1) => `${serializeTags(tags, incrementIndent(p1))}${match}`,
)
}
// if no body tag is present, append to the html tag, or at the end of the file
if (htmlInjectRE.test(html)) {
return html.replace(htmlInjectRE, `${serializeTags(tags)}\n$&`)
}
return html + `\n` + serializeTags(tags)
}
}
Domain
Subdomains
Defined In
Called By
Source
Frequently Asked Questions
What does injectToBody() do?
injectToBody() is a function in the vite codebase, defined in packages/vite/src/node/plugins/html.ts.
Where is injectToBody() defined?
injectToBody() is defined in packages/vite/src/node/plugins/html.ts at line 1489.
What does injectToBody() call?
injectToBody() calls 3 function(s): incrementIndent, prependInjectFallback, serializeTags.
What calls injectToBody()?
injectToBody() is called by 1 function(s): applyHtmlTransforms.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free