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

Function compileCSS

packages/vite/src/node/plugins/css.ts:1432–1507  ·  view source on GitHub ↗
(
  environment: PartialEnvironment,
  id: string,
  code: string,
  workerController: PreprocessorWorkerController,
  urlResolver?: CssUrlResolver,
)

Source from the content-addressed store, hash-verified

1430}
1431
1432async function compileCSS(
1433 environment: PartialEnvironment,
1434 id: string,
1435 code: string,
1436 workerController: PreprocessorWorkerController,
1437 urlResolver?: CssUrlResolver,
1438): Promise<{
1439 code: string
1440 map?: SourceMapInput
1441 modules?: Record<string, string>
1442 deps?: Set<string>
1443}> {
1444 const { config } = environment
1445 const lang = CSS_LANGS_RE.exec(id)?.[1] as CssLang | undefined
1446 const deps = new Set<string>()
1447
1448 // pre-processors: sass etc.
1449 let preprocessorMap: ExistingRawSourceMap | { mappings: '' } | undefined
1450 if (isPreProcessor(lang)) {
1451 const preprocessorResult = await compileCSSPreprocessors(
1452 environment,
1453 id,
1454 lang,
1455 code,
1456 workerController,
1457 )
1458 code = preprocessorResult.code
1459 preprocessorMap = preprocessorResult.map
1460 preprocessorResult.deps?.forEach((dep) => deps.add(dep))
1461 } else if (lang === 'sss' && config.css.transformer === 'lightningcss') {
1462 const sssResult = await transformSugarSS(environment, id, code)
1463 code = sssResult.code
1464 preprocessorMap = sssResult.map
1465 }
1466
1467 const transformResult = await (config.css.transformer === 'lightningcss'
1468 ? compileLightningCSS(
1469 environment,
1470 id,
1471 code,
1472 deps,
1473 workerController,
1474 urlResolver,
1475 )
1476 : compilePostCSS(
1477 environment,
1478 id,
1479 code,
1480 deps,
1481 lang,
1482 workerController,
1483 urlResolver,
1484 ))
1485
1486 if (!transformResult) {
1487 return {
1488 code,
1489 map: config.css.devSourcemap ? preprocessorMap : { mappings: '' },

Callers 2

handlerFunction · 0.85
preprocessCSSFunction · 0.85

Calls 9

cleanUrlFunction · 0.90
isPreProcessorFunction · 0.85
compileCSSPreprocessorsFunction · 0.85
transformSugarSSFunction · 0.85
compileLightningCSSFunction · 0.85
compilePostCSSFunction · 0.85
addMethod · 0.80
parseMethod · 0.80

Tested by

no test coverage detected