Home / Function/ preprocessCSS() — vite Function Reference

preprocessCSS() — vite Function Reference

Architecture documentation for the preprocessCSS() function in css.ts from the vite codebase.

Entity Profile

Dependency Diagram

graph TD
  4c8f6d74_d3d3_58db_32d0_15e3a669dc14["preprocessCSS()"]
  c3eb47df_971b_0616_6c9f_29b3ded72224["css.ts"]
  4c8f6d74_d3d3_58db_32d0_15e3a669dc14 -->|defined in| c3eb47df_971b_0616_6c9f_29b3ded72224
  51afdf58_3045_64b1_cf5b_929b1091e877["get()"]
  4c8f6d74_d3d3_58db_32d0_15e3a669dc14 -->|calls| 51afdf58_3045_64b1_cf5b_929b1091e877
  1da538be_8fb3_3d85_2856_d9bfecfb04f5["createPreprocessorWorkerController()"]
  4c8f6d74_d3d3_58db_32d0_15e3a669dc14 -->|calls| 1da538be_8fb3_3d85_2856_d9bfecfb04f5
  c641d137_b4cd_833f_0387_7d29ec90fde1["compileCSS()"]
  4c8f6d74_d3d3_58db_32d0_15e3a669dc14 -->|calls| c641d137_b4cd_833f_0387_7d29ec90fde1
  style 4c8f6d74_d3d3_58db_32d0_15e3a669dc14 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/vite/src/node/plugins/css.ts lines 1822–1848

export async function preprocessCSS(
  code: string,
  filename: string,
  config: ResolvedConfig,
): Promise<PreprocessCSSResult> {
  let workerController = preprocessorWorkerControllerCache.get(config)

  if (!workerController) {
    // if workerController doesn't exist, create a workerController that always uses fake workers
    // because fake workers doesn't require calling `.close` unlike real workers
    alwaysFakeWorkerWorkerControllerCache ||=
      createPreprocessorWorkerController(0)
    workerController = alwaysFakeWorkerWorkerControllerCache
  }

  // `preprocessCSS` is hardcoded to use the client environment.
  // Since CSS is usually only consumed by the client, and the server builds need to match
  // the client asset chunk name to deduplicate the link reference, this may be fine in most
  // cases. We should revisit in the future if there's a case to preprocess CSS based on a
  // different environment instance.
  const environment: PartialEnvironment = new PartialEnvironment(
    'client',
    config,
  )

  return await compileCSS(environment, filename, code, workerController)
}

Domain

Subdomains

Frequently Asked Questions

What does preprocessCSS() do?
preprocessCSS() is a function in the vite codebase, defined in packages/vite/src/node/plugins/css.ts.
Where is preprocessCSS() defined?
preprocessCSS() is defined in packages/vite/src/node/plugins/css.ts at line 1822.
What does preprocessCSS() call?
preprocessCSS() calls 3 function(s): compileCSS, createPreprocessorWorkerController, get.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free