MCPcopy
hub / github.com/vitejs/vite / convertTargets

Function convertTargets

packages/vite/src/node/plugins/css.ts:3542–3583  ·  view source on GitHub ↗
(
  esbuildTarget: string | string[] | false,
)

Source from the content-addressed store, hash-verified

3540 LightningCSSOptions['targets']
3541>()
3542export const convertTargets = (
3543 esbuildTarget: string | string[] | false,
3544): LightningCSSOptions['targets'] => {
3545 if (!esbuildTarget) return {}
3546 const cached = convertTargetsCache.get(esbuildTarget)
3547 if (cached) return cached
3548 const targets: LightningCSSOptions['targets'] = {}
3549
3550 const entriesWithoutES = arraify(esbuildTarget).flatMap((e) => {
3551 const match = esRE.exec(e)
3552 if (!match) return e
3553 const year = match[1] === '6' ? 2015 : Number(match[1])
3554 if (!esMap[year]) throw new Error(`Unsupported target "${e}"`)
3555 return esMap[year]
3556 })
3557
3558 for (const entry of entriesWithoutES) {
3559 if (entry === 'esnext') continue
3560 const index = entry.search(versionRE)
3561 if (index >= 0) {
3562 const browser = map[entry.slice(0, index)]
3563 if (browser === false) continue // No mapping available
3564 if (browser) {
3565 const [major, minor = 0] = entry
3566 .slice(index)
3567 .split('.')
3568 .map((v) => parseInt(v, 10))
3569 if (!isNaN(major) && !isNaN(minor)) {
3570 const version = (major << 16) | (minor << 8)
3571 if (!targets[browser] || version < targets[browser]!) {
3572 targets[browser] = version
3573 }
3574 continue
3575 }
3576 }
3577 }
3578 throw new Error(`Unsupported target "${entry}"`)
3579 }
3580
3581 convertTargetsCache.set(esbuildTarget, targets)
3582 return targets
3583}
3584
3585export function resolveLibCssFilename(
3586 libOptions: LibraryOptions,

Callers 3

css.spec.tsFile · 0.90
resolveCSSOptionsFunction · 0.85
minifyCSSFunction · 0.85

Calls 3

arraifyFunction · 0.90
getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected