Home / Function/ injectInlinedCSS() — vite Function Reference

injectInlinedCSS() — vite Function Reference

Architecture documentation for the injectInlinedCSS() function in css.ts from the vite codebase.

Entity Profile

Dependency Diagram

graph TD
  7747f6ec_dd9d_919b_6e8d_7c42638be952["injectInlinedCSS()"]
  c3eb47df_971b_0616_6c9f_29b3ded72224["css.ts"]
  7747f6ec_dd9d_919b_6e8d_7c42638be952 -->|defined in| c3eb47df_971b_0616_6c9f_29b3ded72224
  cd131d16_e223_ab79_1b7c_8ea449ae51a2["cssPostPlugin()"]
  cd131d16_e223_ab79_1b7c_8ea449ae51a2 -->|calls| 7747f6ec_dd9d_919b_6e8d_7c42638be952
  8127cae8_510b_1333_1a76_2d21b503c3a6["error()"]
  7747f6ec_dd9d_919b_6e8d_7c42638be952 -->|calls| 8127cae8_510b_1333_1a76_2d21b503c3a6
  style 7747f6ec_dd9d_919b_6e8d_7c42638be952 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/vite/src/node/plugins/css.ts lines 1139–1168

export function injectInlinedCSS(
  s: MagicString,
  ctx: Pick<MinimalPluginContext, 'error'>,
  code: string,
  format: InternalModuleFormat,
  injectCode: string,
): void {
  let injectionPoint: number
  if (format === 'iife' || format === 'umd') {
    const m = (format === 'iife' ? IIFE_BEGIN_RE : UMD_BEGIN_RE).exec(code)
    if (!m) {
      ctx.error('Injection point for inlined CSS not found')
    }
    injectionPoint = m.index + m[0].length
  } else if (format === 'es') {
    // legacy build
    if (code.startsWith('#!')) {
      let secondLinePos = code.indexOf('\n')
      if (secondLinePos === -1) {
        secondLinePos = 0
      }
      injectionPoint = secondLinePos
    } else {
      injectionPoint = 0
    }
  } else {
    ctx.error('Non supported format')
  }
  s.appendRight(injectionPoint, injectCode)
}

Domain

Subdomains

Calls

Called By

Frequently Asked Questions

What does injectInlinedCSS() do?
injectInlinedCSS() is a function in the vite codebase, defined in packages/vite/src/node/plugins/css.ts.
Where is injectInlinedCSS() defined?
injectInlinedCSS() is defined in packages/vite/src/node/plugins/css.ts at line 1139.
What does injectInlinedCSS() call?
injectInlinedCSS() calls 1 function(s): error.
What calls injectInlinedCSS()?
injectInlinedCSS() is called by 1 function(s): cssPostPlugin.

Analyze Your Own Codebase

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

Try Supermodel Free