Home / Function/ cssPostPlugin() — vite Function Reference

cssPostPlugin() — vite Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  cd131d16_e223_ab79_1b7c_8ea449ae51a2["cssPostPlugin()"]
  c3eb47df_971b_0616_6c9f_29b3ded72224["css.ts"]
  cd131d16_e223_ab79_1b7c_8ea449ae51a2 -->|defined in| c3eb47df_971b_0616_6c9f_29b3ded72224
  b1b40b5b_3e43_2197_dea0_d36389d312a1["resolvePlugins()"]
  b1b40b5b_3e43_2197_dea0_d36389d312a1 -->|calls| cd131d16_e223_ab79_1b7c_8ea449ae51a2
  7f968f26_079b_e4e6_bf70_99a14c481596["getCombinedSourcemap()"]
  cd131d16_e223_ab79_1b7c_8ea449ae51a2 -->|calls| 7f968f26_079b_e4e6_bf70_99a14c481596
  1adea094_39cf_72a2_c028_30a7e4665b35["getFileName()"]
  cd131d16_e223_ab79_1b7c_8ea449ae51a2 -->|calls| 1adea094_39cf_72a2_c028_30a7e4665b35
  2413bb83_2f00_e69b_72f7_3b56a2779134["emitFile()"]
  cd131d16_e223_ab79_1b7c_8ea449ae51a2 -->|calls| 2413bb83_2f00_e69b_72f7_3b56a2779134
  51afdf58_3045_64b1_cf5b_929b1091e877["get()"]
  cd131d16_e223_ab79_1b7c_8ea449ae51a2 -->|calls| 51afdf58_3045_64b1_cf5b_929b1091e877
  e4b69431_16f5_26e1_f535_a4b0b9b0b4a7["resolveLibCssFilename()"]
  cd131d16_e223_ab79_1b7c_8ea449ae51a2 -->|calls| e4b69431_16f5_26e1_f535_a4b0b9b0b4a7
  bbded320_f805_2b6e_3109_088d194024a2["build()"]
  cd131d16_e223_ab79_1b7c_8ea449ae51a2 -->|calls| bbded320_f805_2b6e_3109_088d194024a2
  921da9ad_e621_93c8_8241_909c590edfd7["createSerialPromiseQueue()"]
  cd131d16_e223_ab79_1b7c_8ea449ae51a2 -->|calls| 921da9ad_e621_93c8_8241_909c590edfd7
  cd901a4b_1290_4e3f_0c59_f8621634cb5a["stripBomTag()"]
  cd131d16_e223_ab79_1b7c_8ea449ae51a2 -->|calls| cd901a4b_1290_4e3f_0c59_f8621634cb5a
  97736a44_7baf_9ff8_83ff_d39e51721360["addToHTMLProxyTransformResult()"]
  cd131d16_e223_ab79_1b7c_8ea449ae51a2 -->|calls| 97736a44_7baf_9ff8_83ff_d39e51721360
  9d025481_71dc_8fbb_c07e_b6e74a08a45a["getHash()"]
  cd131d16_e223_ab79_1b7c_8ea449ae51a2 -->|calls| 9d025481_71dc_8fbb_c07e_b6e74a08a45a
  10b9dea8_362c_1af2_93be_afa4dd9aed9e["cleanUrl()"]
  cd131d16_e223_ab79_1b7c_8ea449ae51a2 -->|calls| 10b9dea8_362c_1af2_93be_afa4dd9aed9e
  2deecd7d_9b22_ab75_0899_d940d29c9876["injectSourcesContent()"]
  cd131d16_e223_ab79_1b7c_8ea449ae51a2 -->|calls| 2deecd7d_9b22_ab75_0899_d940d29c9876
  style cd131d16_e223_ab79_1b7c_8ea449ae51a2 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/vite/src/node/plugins/css.ts lines 458–1137

export function cssPostPlugin(config: ResolvedConfig): Plugin {
  // styles initialization in buildStart causes a styling loss in watch
  const styles = new Map<string, string>()
  // queue to emit css serially to guarantee the files are emitted in a deterministic order
  let codeSplitEmitQueue = createSerialPromiseQueue<string>()
  const urlEmitQueue = createSerialPromiseQueue<unknown>()
  let pureCssChunks: Set<RenderedChunk>

  // when there are multiple rollup outputs and extracting CSS, only emit once,
  // since output formats have no effect on the generated CSS.
  let hasEmitted = false
  let chunkCSSMap: Map<string, string>

  const rollupOptionsOutput = config.build.rollupOptions.output
  const assetFileNames = (
    Array.isArray(rollupOptionsOutput)
      ? rollupOptionsOutput[0]
      : rollupOptionsOutput
  )?.assetFileNames
  const getCssAssetDirname = (
    cssAssetName: string,
    originalFileName?: string,
  ) => {
    const cssAssetNameDir = path.dirname(cssAssetName)
    if (!assetFileNames) {
      return path.join(config.build.assetsDir, cssAssetNameDir)
    } else if (typeof assetFileNames === 'string') {
      return path.join(path.dirname(assetFileNames), cssAssetNameDir)
    } else {
      return path.dirname(
        assetFileNames({
          type: 'asset',
          names: [cssAssetName],
          originalFileNames: originalFileName ? [originalFileName] : [],
          source: '/* vite internal call, ignore */',
        }),
      )
    }
  }

  function getCssBundleName() {
    const cached = cssBundleNameCache.get(config)
    if (cached) return cached

    const cssBundleName = config.build.lib
      ? resolveLibCssFilename(
          config.build.lib,
          config.root,
          config.packageCache,
        )
      : defaultCssBundleName
    cssBundleNameCache.set(config, cssBundleName)
    return cssBundleName
  }

  return {
    name: 'vite:css-post',

    renderStart() {
      // Ensure new caches for every build (i.e. rebuilding in watch mode)
      pureCssChunks = new Set<RenderedChunk>()
      hasEmitted = false
      chunkCSSMap = new Map()
      codeSplitEmitQueue = createSerialPromiseQueue()
    },

    transform: {
      filter: {
        id: {
          include: CSS_LANGS_RE,
          exclude: [commonjsProxyRE, SPECIAL_QUERY_RE],
        },
      },
      async handler(css, id) {
        css = stripBomTag(css)

        // cache css compile result to map
        // and then use the cache replace inline-style-flag
        // when `generateBundle` in vite:build-html plugin and devHtmlHook
        const inlineCSS = inlineCSSRE.test(id)
        const isHTMLProxy = htmlProxyRE.test(id)

Domain

Subdomains

Called By

Frequently Asked Questions

What does cssPostPlugin() do?
cssPostPlugin() is a function in the vite codebase, defined in packages/vite/src/node/plugins/css.ts.
Where is cssPostPlugin() defined?
cssPostPlugin() is defined in packages/vite/src/node/plugins/css.ts at line 458.
What does cssPostPlugin() call?
cssPostPlugin() calls 31 function(s): addToHTMLProxyTransformResult, build, cleanUrl, createSerialPromiseQueue, createToImportMetaURLBasedRelativeRuntime, emitFile, encodePublicUrlsInCSS, encodeURIPath, and 23 more.
What calls cssPostPlugin()?
cssPostPlugin() is called by 1 function(s): resolvePlugins.

Analyze Your Own Codebase

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

Try Supermodel Free