MCPcopy Index your code
hub / github.com/nuxt/nuxt / getPostcssConfig

Function getPostcssConfig

packages/webpack/src/utils/postcss.ts:14–72  ·  view source on GitHub ↗
(nuxt: Nuxt)

Source from the content-addressed store, hash-verified

12}
13
14export async function getPostcssConfig (nuxt: Nuxt) {
15 if (!nuxt.options.webpack.postcss || !nuxt.options.postcss) {
16 return false
17 }
18
19 const postcssOptions = defu({}, nuxt.options.postcss, {
20 plugins: {
21 /**
22 * https://github.com/postcss/postcss-import
23 */
24 'postcss-import': {
25 resolve: createResolver({
26 alias: { ...nuxt.options.alias },
27 modules: nuxt.options.modulesDir,
28 }),
29 },
30
31 /**
32 * https://github.com/postcss/postcss-url
33 */
34 'postcss-url': {},
35 },
36 sourceMap: nuxt.options.webpack.cssSourceMap,
37 })
38
39 const jiti = createJiti(nuxt.options.rootDir, { alias: nuxt.options.alias })
40
41 // Keep the order of default plugins
42 if (!Array.isArray(postcssOptions.plugins) && isPureObject(postcssOptions.plugins)) {
43 // Map postcss plugins into instances on object mode once
44 const plugins: Plugin[] = []
45 for (const pluginName of sortPlugins(postcssOptions)) {
46 const pluginOptions = postcssOptions.plugins[pluginName]
47 if (!pluginOptions) { continue }
48
49 let pluginFn: ((opts: Record<string, any>) => Plugin) | undefined
50 for (const parentURL of nuxt.options.modulesDir) {
51 pluginFn = await jiti.import(pluginName, { parentURL: parentURL.replace(/\/node_modules\/?$/, ''), try: true, default: true }) as (opts: Record<string, any>) => Plugin
52 if (typeof pluginFn === 'function') {
53 plugins.push(pluginFn(pluginOptions))
54 break
55 }
56 }
57
58 if (typeof pluginFn !== 'function') {
59 console.warn(`[nuxt] could not import postcss plugin \`${pluginName}\`. Please report this as a bug.`)
60 }
61 }
62
63 // @ts-expect-error we are mutating type here from object to array
64 postcssOptions.plugins = plugins
65 }
66
67 return {
68 sourceMap: nuxt.options.webpack.cssSourceMap,
69 ...nuxt.options.webpack.postcss,
70 postcssOptions,
71 }

Callers 1

createPostcssLoadersRuleFunction · 0.90

Calls 3

createResolverFunction · 0.85
isPureObjectFunction · 0.85
sortPluginsFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…