MCPcopy Create free account
hub / github.com/rolldown/tsdown / processWithPostCSS

Function processWithPostCSS

packages/css/src/plugin.ts:449–501  ·  view source on GitHub ↗
(
  code: string,
  id: string,
  cleanId: string,
  deps: string[],
  config: CssPluginConfig,
  isModule: boolean,
)

Source from the content-addressed store, hash-verified

447}
448
449async function processWithPostCSS(
450 code: string,
451 id: string,
452 cleanId: string,
453 deps: string[],
454 config: CssPluginConfig,
455 isModule: boolean,
456): Promise<ProcessResult> {
457 const lang = getPreprocessorLangFromId(id)
458
459 if (lang) {
460 const preResult = await compilePreprocessor(
461 lang,
462 code,
463 cleanId,
464 config.css.preprocessorOptions,
465 )
466 code = preResult.code
467 deps.push(...preResult.deps)
468 }
469
470 const modulesConfig =
471 typeof config.css.modules === 'object' ? config.css.modules : undefined
472
473 const needInlineImport = code.includes('@import')
474 const postcssResult = await runPostCSS(
475 code,
476 cleanId,
477 config.css.postcss,
478 config.cwd,
479 needInlineImport,
480 isModule ? { isModule: true, config: modulesConfig } : undefined,
481 config.sourceMap,
482 )
483 code = postcssResult.code
484 deps.push(...postcssResult.deps)
485
486 const transformResult = await transformWithLightningCSS(code, cleanId, {
487 target: config.css.target,
488 lightningcss: config.css.lightningcss,
489 minify: config.css.minify,
490 sourceMap: config.sourceMap,
491 inputSourceMap: postcssResult.map,
492 })
493
494 // When LightningCSS skips its transform (no targets/minify), it returns no
495 // map; fall back to the PostCSS map so the chain still has one.
496 return {
497 code: transformResult.code,
498 map: transformResult.map ?? postcssResult.map,
499 modules: postcssResult.modules,
500 }
501}
502
503function isEmptyChunkCode(code: string): boolean {
504 return !code

Callers 1

handlerFunction · 0.90

Calls 3

compilePreprocessorFunction · 0.90

Tested by

no test coverage detected