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

Function compileCSS

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

Source from the content-addressed store, hash-verified

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