Home / Function/ convertTargets() — vite Function Reference

convertTargets() — vite Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  6648f04f_fbaf_b4c1_7ca5_d07266e9650c["convertTargets()"]
  c3eb47df_971b_0616_6c9f_29b3ded72224["css.ts"]
  6648f04f_fbaf_b4c1_7ca5_d07266e9650c -->|defined in| c3eb47df_971b_0616_6c9f_29b3ded72224
  cde5b538_80f6_3ed1_2a73_36671c5fbdd6["resolveCSSOptions()"]
  cde5b538_80f6_3ed1_2a73_36671c5fbdd6 -->|calls| 6648f04f_fbaf_b4c1_7ca5_d07266e9650c
  297b7917_5996_b011_26d1_5bce9b0e6724["minifyCSS()"]
  297b7917_5996_b011_26d1_5bce9b0e6724 -->|calls| 6648f04f_fbaf_b4c1_7ca5_d07266e9650c
  51afdf58_3045_64b1_cf5b_929b1091e877["get()"]
  6648f04f_fbaf_b4c1_7ca5_d07266e9650c -->|calls| 51afdf58_3045_64b1_cf5b_929b1091e877
  19ce2051_6a74_4b8b_104d_ec006cd7075f["arraify()"]
  6648f04f_fbaf_b4c1_7ca5_d07266e9650c -->|calls| 19ce2051_6a74_4b8b_104d_ec006cd7075f
  style 6648f04f_fbaf_b4c1_7ca5_d07266e9650c fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/vite/src/node/plugins/css.ts lines 3476–3517

export const convertTargets = (
  esbuildTarget: string | string[] | false,
): LightningCSSOptions['targets'] => {
  if (!esbuildTarget) return {}
  const cached = convertTargetsCache.get(esbuildTarget)
  if (cached) return cached
  const targets: LightningCSSOptions['targets'] = {}

  const entriesWithoutES = arraify(esbuildTarget).flatMap((e) => {
    const match = esRE.exec(e)
    if (!match) return e
    const year = Number(match[1])
    if (!esMap[year]) throw new Error(`Unsupported target "${e}"`)
    return esMap[year]
  })

  for (const entry of entriesWithoutES) {
    if (entry === 'esnext') continue
    const index = entry.search(versionRE)
    if (index >= 0) {
      const browser = map[entry.slice(0, index)]
      if (browser === false) continue // No mapping available
      if (browser) {
        const [major, minor = 0] = entry
          .slice(index)
          .split('.')
          .map((v) => parseInt(v, 10))
        if (!isNaN(major) && !isNaN(minor)) {
          const version = (major << 16) | (minor << 8)
          if (!targets[browser] || version < targets[browser]!) {
            targets[browser] = version
          }
          continue
        }
      }
    }
    throw new Error(`Unsupported target "${entry}"`)
  }

  convertTargetsCache.set(esbuildTarget, targets)
  return targets
}

Domain

Subdomains

Frequently Asked Questions

What does convertTargets() do?
convertTargets() is a function in the vite codebase, defined in packages/vite/src/node/plugins/css.ts.
Where is convertTargets() defined?
convertTargets() is defined in packages/vite/src/node/plugins/css.ts at line 3476.
What does convertTargets() call?
convertTargets() calls 2 function(s): arraify, get.
What calls convertTargets()?
convertTargets() is called by 2 function(s): minifyCSS, resolveCSSOptions.

Analyze Your Own Codebase

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

Try Supermodel Free