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

Function resolvePostcssConfig

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

Source from the content-addressed store, hash-verified

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