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

Function preprocessCSS

packages/vite/src/node/plugins/css.ts:1840–1866  ·  view source on GitHub ↗
(
  code: string,
  filename: string,
  config: ResolvedConfig,
)

Source from the content-addressed store, hash-verified

1838 * @experimental
1839 */
1840export async function preprocessCSS(
1841 code: string,
1842 filename: string,
1843 config: ResolvedConfig,
1844): Promise<PreprocessCSSResult> {
1845 let workerController = preprocessorWorkerControllerCache.get(config)
1846
1847 if (!workerController) {
1848 // if workerController doesn't exist, create a workerController that always uses fake workers
1849 // because fake workers doesn't require calling `.close` unlike real workers
1850 alwaysFakeWorkerWorkerControllerCache ||=
1851 createPreprocessorWorkerController(0)
1852 workerController = alwaysFakeWorkerWorkerControllerCache
1853 }
1854
1855 // `preprocessCSS` is hardcoded to use the client environment.
1856 // Since CSS is usually only consumed by the client, and the server builds need to match
1857 // the client asset chunk name to deduplicate the link reference, this may be fine in most
1858 // cases. We should revisit in the future if there's a case to preprocess CSS based on a
1859 // different environment instance.
1860 const environment: PartialEnvironment = new PartialEnvironment(
1861 'client',
1862 config,
1863 )
1864
1865 return await compileCSS(environment, filename, code, workerController)
1866}
1867
1868export async function formatPostcssSourceMap(
1869 rawMap: ExistingRawSourceMap,

Callers 1

css.spec.tsFile · 0.90

Calls 3

compileCSSFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected