Home / Function/ resolvePostcssConfig() — vite Function Reference

resolvePostcssConfig() — vite Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  cef0333b_923a_6cea_cbaf_2d72f8dd2e53["resolvePostcssConfig()"]
  c3eb47df_971b_0616_6c9f_29b3ded72224["css.ts"]
  cef0333b_923a_6cea_cbaf_2d72f8dd2e53 -->|defined in| c3eb47df_971b_0616_6c9f_29b3ded72224
  157cb972_609e_022e_1ec5_3ed6f7e4f45c["cssPlugin()"]
  157cb972_609e_022e_1ec5_3ed6f7e4f45c -->|calls| cef0333b_923a_6cea_cbaf_2d72f8dd2e53
  6aa50cd4_4412_2a02_b76b_495614715811["compilePostCSS()"]
  6aa50cd4_4412_2a02_b76b_495614715811 -->|calls| cef0333b_923a_6cea_cbaf_2d72f8dd2e53
  51afdf58_3045_64b1_cf5b_929b1091e877["get()"]
  cef0333b_923a_6cea_cbaf_2d72f8dd2e53 -->|calls| 51afdf58_3045_64b1_cf5b_929b1091e877
  2aff86e8_0c9d_22cb_6536_c1321e1aaa1d["isObject()"]
  cef0333b_923a_6cea_cbaf_2d72f8dd2e53 -->|calls| 2aff86e8_0c9d_22cb_6536_c1321e1aaa1d
  f00607d5_f936_a7c7_9f17_a6349edeac83["searchForWorkspaceRoot()"]
  cef0333b_923a_6cea_cbaf_2d72f8dd2e53 -->|calls| f00607d5_f936_a7c7_9f17_a6349edeac83
  b7b274e8_6dc1_afd8_f0e1_e727300ca8ee["config()"]
  cef0333b_923a_6cea_cbaf_2d72f8dd2e53 -->|calls| b7b274e8_6dc1_afd8_f0e1_e727300ca8ee
  style cef0333b_923a_6cea_cbaf_2d72f8dd2e53 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/vite/src/node/plugins/css.ts lines 1926–1975

async function resolvePostcssConfig(
  config: ResolvedConfig,
): Promise<PostCSSConfigResult | null> {
  let result = postcssConfigCache.get(config)
  if (result !== undefined) {
    return await result
  }

  // inline postcss config via vite config
  const inlineOptions = config.css.postcss
  if (isObject(inlineOptions)) {
    const options = { ...inlineOptions }

    delete options.plugins
    result = {
      options,
      plugins: inlineOptions.plugins || [],
    }
  } else {
    const searchPath =
      typeof inlineOptions === 'string' ? inlineOptions : config.root
    const stopDir = searchForWorkspaceRoot(config.root)
    result = postcssrc({}, searchPath, { stopDir }).catch((e) => {
      if (!e.message.includes('No PostCSS Config found')) {
        if (e instanceof Error) {
          const { name, message, stack } = e
          e.name = 'Failed to load PostCSS config'
          e.message = `Failed to load PostCSS config (searchPath: ${searchPath}): [${name}] ${message}\n${stack}`
          e.stack = '' // add stack to message to retain stack
          throw e
        } else {
          throw new Error(`Failed to load PostCSS config: ${e}`)
        }
      }
      return null
    })
    // replace cached promise to result object when finished
    result.then(
      (resolved) => {
        postcssConfigCache.set(config, resolved)
      },
      () => {
        /* keep as rejected promise, will be handled later */
      },
    )
  }

  postcssConfigCache.set(config, result)
  return result
}

Domain

Subdomains

Frequently Asked Questions

What does resolvePostcssConfig() do?
resolvePostcssConfig() is a function in the vite codebase, defined in packages/vite/src/node/plugins/css.ts.
Where is resolvePostcssConfig() defined?
resolvePostcssConfig() is defined in packages/vite/src/node/plugins/css.ts at line 1926.
What does resolvePostcssConfig() call?
resolvePostcssConfig() calls 4 function(s): config, get, isObject, searchForWorkspaceRoot.
What calls resolvePostcssConfig()?
resolvePostcssConfig() is called by 2 function(s): compilePostCSS, cssPlugin.

Analyze Your Own Codebase

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

Try Supermodel Free