Home / Function/ getNodeAssetAttributes() — vite Function Reference

getNodeAssetAttributes() — vite Function Reference

Architecture documentation for the getNodeAssetAttributes() function in assetSource.ts from the vite codebase.

Entity Profile

Dependency Diagram

graph TD
  583413b4_122f_c77c_6469_fed71988cf60["getNodeAssetAttributes()"]
  a2a61cd6_2d46_2c12_335a_793c63cb8a19["assetSource.ts"]
  583413b4_122f_c77c_6469_fed71988cf60 -->|defined in| a2a61cd6_2d46_2c12_335a_793c63cb8a19
  39f26be8_b1d9_a756_3043_474687a6bbb7["buildHtmlPlugin()"]
  39f26be8_b1d9_a756_3043_474687a6bbb7 -->|calls| 583413b4_122f_c77c_6469_fed71988cf60
  c7929a5b_9791_180a_9c0b_4f479fb4cf3f["devHtmlHook()"]
  c7929a5b_9791_180a_9c0b_4f479fb4cf3f -->|calls| 583413b4_122f_c77c_6469_fed71988cf60
  d1f8c6d0_0852_b3cc_f063_30685d096497["getAttrKey()"]
  583413b4_122f_c77c_6469_fed71988cf60 -->|calls| d1f8c6d0_0852_b3cc_f063_30685d096497
  style 583413b4_122f_c77c_6469_fed71988cf60 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/vite/src/node/assetSource.ts lines 111–147

export function getNodeAssetAttributes(
  node: DefaultTreeAdapterMap['element'],
): HtmlAssetAttribute[] {
  const matched = DEFAULT_HTML_ASSET_SOURCES[node.nodeName]
  if (!matched) return []

  const attributes: Record<string, string> = {}
  for (const attr of node.attrs) {
    attributes[getAttrKey(attr)] = attr.value
  }

  // If the node has a `vite-ignore` attribute, remove the attribute and early out
  // to skip processing any attributes
  if ('vite-ignore' in attributes) {
    return [
      {
        type: 'remove',
        key: 'vite-ignore',
        value: '',
        attributes,
        location: node.sourceCodeLocation!.attrs!['vite-ignore'],
      },
    ]
  }

  const actions: HtmlAssetAttribute[] = []
  function handleAttributeKey(key: string, type: 'src' | 'srcset') {
    const value = attributes[key]
    if (!value) return
    if (matched.filter && !matched.filter({ key, value, attributes })) return
    const location = node.sourceCodeLocation!.attrs![key]
    actions.push({ type, key, value, attributes, location })
  }
  matched.srcAttributes?.forEach((key) => handleAttributeKey(key, 'src'))
  matched.srcsetAttributes?.forEach((key) => handleAttributeKey(key, 'srcset'))
  return actions
}

Domain

Subdomains

Calls

Frequently Asked Questions

What does getNodeAssetAttributes() do?
getNodeAssetAttributes() is a function in the vite codebase, defined in packages/vite/src/node/assetSource.ts.
Where is getNodeAssetAttributes() defined?
getNodeAssetAttributes() is defined in packages/vite/src/node/assetSource.ts at line 111.
What does getNodeAssetAttributes() call?
getNodeAssetAttributes() calls 1 function(s): getAttrKey.
What calls getNodeAssetAttributes()?
getNodeAssetAttributes() is called by 2 function(s): buildHtmlPlugin, devHtmlHook.

Analyze Your Own Codebase

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

Try Supermodel Free