( environment: PartialEnvironment, id: string, code: string, deps: Set<string>, lang: CssLang | undefined, workerController: PreprocessorWorkerController, urlResolver?: CssUrlResolver, )
| 1507 | } |
| 1508 | |
| 1509 | async function compilePostCSS( |
| 1510 | environment: PartialEnvironment, |
| 1511 | id: string, |
| 1512 | code: string, |
| 1513 | deps: Set<string>, |
| 1514 | lang: CssLang | undefined, |
| 1515 | workerController: PreprocessorWorkerController, |
| 1516 | urlResolver?: CssUrlResolver, |
| 1517 | ): Promise< |
| 1518 | | { |
| 1519 | code: string |
| 1520 | map?: Exclude<SourceMapInput, string> |
| 1521 | modules?: Record<string, string> |
| 1522 | } |
| 1523 | | undefined |
| 1524 | > { |
| 1525 | const { config } = environment |
| 1526 | const { modules: modulesOptions, devSourcemap } = config.css |
| 1527 | const isModule = modulesOptions !== false && cssModuleRE.test(id) |
| 1528 | // although at serve time it can work without processing, we do need to |
| 1529 | // crawl them in order to register watch dependencies. |
| 1530 | const needInlineImport = code.includes('@import') |
| 1531 | const hasUrl = cssUrlRE.test(code) || cssImageSetRE.test(code) |
| 1532 | const postcssConfig = await resolvePostcssConfig( |
| 1533 | environment.getTopLevelConfig(), |
| 1534 | ) |
| 1535 | |
| 1536 | // postcss processing is not needed |
| 1537 | if ( |
| 1538 | lang !== 'sss' && |
| 1539 | !postcssConfig && |
| 1540 | !isModule && |
| 1541 | !needInlineImport && |
| 1542 | !hasUrl |
| 1543 | ) { |
| 1544 | return |
| 1545 | } |
| 1546 | |
| 1547 | // postcss |
| 1548 | const atImportResolvers = getAtImportResolvers( |
| 1549 | environment.getTopLevelConfig(), |
| 1550 | ) |
| 1551 | const postcssPlugins = postcssConfig?.plugins.slice() ?? [] |
| 1552 | |
| 1553 | if (needInlineImport) { |
| 1554 | postcssPlugins.unshift( |
| 1555 | (await importPostcssImport()).default({ |
| 1556 | async resolve(id, basedir, _importOptions, atRule) { |
| 1557 | const publicFile = checkPublicFile( |
| 1558 | id, |
| 1559 | environment.getTopLevelConfig(), |
| 1560 | ) |
| 1561 | if (publicFile) { |
| 1562 | return publicFile |
| 1563 | } |
| 1564 | |
| 1565 | const resolved = await atImportResolvers.css( |
| 1566 | environment, |
no test coverage detected