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

Function resolvePostcssConfig

packages/vite/src/node/plugins/css.ts:1947–1996  ·  view source on GitHub ↗
(
  config: ResolvedConfig,
)

Source from the content-addressed store, hash-verified

1945}
1946
1947async function resolvePostcssConfig(
1948 config: ResolvedConfig,
1949): Promise<PostCSSConfigResult | null> {
1950 let result = postcssConfigCache.get(config)
1951 if (result !== undefined) {
1952 return await result
1953 }
1954
1955 // inline postcss config via vite config
1956 const inlineOptions = config.css.postcss
1957 if (isObject(inlineOptions)) {
1958 const options = { ...inlineOptions }
1959
1960 delete options.plugins
1961 result = {
1962 options,
1963 plugins: inlineOptions.plugins || [],
1964 }
1965 } else {
1966 const searchPath =
1967 typeof inlineOptions === 'string' ? inlineOptions : config.root
1968 const stopDir = searchForWorkspaceRoot(config.root)
1969 result = postcssrc({}, searchPath, { stopDir }).catch((e) => {
1970 if (!e.message.includes('No PostCSS Config found')) {
1971 if (e instanceof Error) {
1972 const { name, message, stack } = e
1973 e.name = 'Failed to load PostCSS config'
1974 e.message = `Failed to load PostCSS config (searchPath: ${searchPath}): [${name}] ${message}\n${stack}`
1975 e.stack = '' // add stack to message to retain stack
1976 throw e
1977 } else {
1978 throw new Error(`Failed to load PostCSS config: ${e}`)
1979 }
1980 }
1981 return null
1982 })
1983 // replace cached promise to result object when finished
1984 result.then(
1985 (resolved) => {
1986 postcssConfigCache.set(config, resolved)
1987 },
1988 () => {
1989 /* keep as rejected promise, will be handled later */
1990 },
1991 )
1992 }
1993
1994 postcssConfigCache.set(config, result)
1995 return result
1996}
1997
1998type CssUrlResolver = (
1999 url: string,

Callers 2

cssPluginFunction · 0.85
compilePostCSSFunction · 0.85

Calls 4

isObjectFunction · 0.90
searchForWorkspaceRootFunction · 0.90
getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected