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