Home / Function/ preImportMapHook() — vite Function Reference

preImportMapHook() — vite Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  f2e3401e_edbf_08a2_0460_cc85afbcd839["preImportMapHook()"]
  f8fe0737_718a_5509_b722_473f207d5906["html.ts"]
  f2e3401e_edbf_08a2_0460_cc85afbcd839 -->|defined in| f8fe0737_718a_5509_b722_473f207d5906
  39f26be8_b1d9_a756_3043_474687a6bbb7["buildHtmlPlugin()"]
  39f26be8_b1d9_a756_3043_474687a6bbb7 -->|calls| f2e3401e_edbf_08a2_0460_cc85afbcd839
  7a53712a_b13b_4bc2_85fc_b4de5cb705fb["createDevHtmlTransformFn()"]
  7a53712a_b13b_4bc2_85fc_b4de5cb705fb -->|calls| f2e3401e_edbf_08a2_0460_cc85afbcd839
  a4adb1a7_cf54_091f_eb63_8217e684a8e1["normalizePath()"]
  f2e3401e_edbf_08a2_0460_cc85afbcd839 -->|calls| a4adb1a7_cf54_091f_eb63_8217e684a8e1
  style f2e3401e_edbf_08a2_0460_cc85afbcd839 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/vite/src/node/plugins/html.ts lines 1139–1162

export function preImportMapHook(
  config: ResolvedConfig,
): IndexHtmlTransformHook {
  return (html, ctx) => {
    const importMapIndex = html.search(importMapRE)
    if (importMapIndex < 0) return

    const importMapAppendIndex = html.search(importMapAppendRE)
    if (importMapAppendIndex < 0) return

    if (importMapAppendIndex < importMapIndex) {
      const relativeHtml = normalizePath(
        path.relative(config.root, ctx.filename),
      )
      config.logger.warnOnce(
        colors.yellow(
          colors.bold(
            `(!) <script type="importmap"> should come before <script type="module"> and <link rel="modulepreload"> in /${relativeHtml}`,
          ),
        ),
      )
    }
  }
}

Domain

Subdomains

Frequently Asked Questions

What does preImportMapHook() do?
preImportMapHook() is a function in the vite codebase, defined in packages/vite/src/node/plugins/html.ts.
Where is preImportMapHook() defined?
preImportMapHook() is defined in packages/vite/src/node/plugins/html.ts at line 1139.
What does preImportMapHook() call?
preImportMapHook() calls 1 function(s): normalizePath.
What calls preImportMapHook()?
preImportMapHook() 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