( code: string, id: string, cleanId: string, deps: string[], config: CssPluginConfig, isModule: boolean, )
| 447 | } |
| 448 | |
| 449 | async 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 | |
| 503 | function isEmptyChunkCode(code: string): boolean { |
| 504 | return !code |
no test coverage detected