Home / Function/ applyHtmlTransforms() — vite Function Reference

applyHtmlTransforms() — vite Function Reference

Architecture documentation for the applyHtmlTransforms() function in html.ts from the vite codebase.

Entity Profile

Dependency Diagram

graph TD
  979ed295_1d80_37c1_156b_2bbf25fc21e4["applyHtmlTransforms()"]
  f8fe0737_718a_5509_b722_473f207d5906["html.ts"]
  979ed295_1d80_37c1_156b_2bbf25fc21e4 -->|defined in| f8fe0737_718a_5509_b722_473f207d5906
  39f26be8_b1d9_a756_3043_474687a6bbb7["buildHtmlPlugin()"]
  39f26be8_b1d9_a756_3043_474687a6bbb7 -->|calls| 979ed295_1d80_37c1_156b_2bbf25fc21e4
  7a53712a_b13b_4bc2_85fc_b4de5cb705fb["createDevHtmlTransformFn()"]
  7a53712a_b13b_4bc2_85fc_b4de5cb705fb -->|calls| 979ed295_1d80_37c1_156b_2bbf25fc21e4
  08c41a93_79ac_548f_29e5_24bc0973e731["headTagInsertCheck()"]
  979ed295_1d80_37c1_156b_2bbf25fc21e4 -->|calls| 08c41a93_79ac_548f_29e5_24bc0973e731
  fb5a3d66_7c54_2dc1_57bd_7bba8ad8fdbf["injectToHead()"]
  979ed295_1d80_37c1_156b_2bbf25fc21e4 -->|calls| fb5a3d66_7c54_2dc1_57bd_7bba8ad8fdbf
  24734732_0f40_e935_b5d1_ae08e9d1dca3["injectToBody()"]
  979ed295_1d80_37c1_156b_2bbf25fc21e4 -->|calls| 24734732_0f40_e935_b5d1_ae08e9d1dca3
  style 979ed295_1d80_37c1_156b_2bbf25fc21e4 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/vite/src/node/plugins/html.ts lines 1370–1421

export async function applyHtmlTransforms(
  html: string,
  hooks: IndexHtmlTransformHook[],
  pluginContext: MinimalPluginContextWithoutEnvironment,
  ctx: IndexHtmlTransformContext,
): Promise<string> {
  for (const hook of hooks) {
    const res = await hook.call(pluginContext, html, ctx)
    if (!res) {
      continue
    }
    if (typeof res === 'string') {
      html = res
    } else {
      let tags: HtmlTagDescriptor[]
      if (Array.isArray(res)) {
        tags = res
      } else {
        html = res.html || html
        tags = res.tags
      }

      let headTags: HtmlTagDescriptor[] | undefined
      let headPrependTags: HtmlTagDescriptor[] | undefined
      let bodyTags: HtmlTagDescriptor[] | undefined
      let bodyPrependTags: HtmlTagDescriptor[] | undefined

      for (const tag of tags) {
        switch (tag.injectTo) {
          case 'body':
            ;(bodyTags ??= []).push(tag)
            break
          case 'body-prepend':
            ;(bodyPrependTags ??= []).push(tag)
            break
          case 'head':
            ;(headTags ??= []).push(tag)
            break
          default:
            ;(headPrependTags ??= []).push(tag)
        }
      }
      headTagInsertCheck([...(headTags || []), ...(headPrependTags || [])], ctx)
      if (headPrependTags) html = injectToHead(html, headPrependTags, true)
      if (headTags) html = injectToHead(html, headTags)
      if (bodyPrependTags) html = injectToBody(html, bodyPrependTags, true)
      if (bodyTags) html = injectToBody(html, bodyTags)
    }
  }

  return html
}

Domain

Subdomains

Frequently Asked Questions

What does applyHtmlTransforms() do?
applyHtmlTransforms() is a function in the vite codebase, defined in packages/vite/src/node/plugins/html.ts.
Where is applyHtmlTransforms() defined?
applyHtmlTransforms() is defined in packages/vite/src/node/plugins/html.ts at line 1370.
What does applyHtmlTransforms() call?
applyHtmlTransforms() calls 3 function(s): headTagInsertCheck, injectToBody, injectToHead.
What calls applyHtmlTransforms()?
applyHtmlTransforms() is called by 2 function(s): buildHtmlPlugin, createDevHtmlTransformFn.

Analyze Your Own Codebase

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

Try Supermodel Free