MCPcopy
hub / github.com/dilanx/craco / extendsPostcss

Function extendsPostcss

packages/craco/src/lib/features/webpack/style/postcss.ts:48–94  ·  view source on GitHub ↗
(
  match: CompleteLoader,
  { postcss: postcssOptions }: CracoStyleConfig
)

Source from the content-addressed store, hash-verified

46}
47
48function extendsPostcss(
49 match: CompleteLoader,
50 { postcss: postcssOptions }: CracoStyleConfig
51) {
52 const { plugins, env } = postcssOptions ?? {};
53 if (isArray(plugins) || env) {
54 let postcssPlugins: any[];
55
56 if (env) {
57 const mergedPreset = deepMergeWithArray({}, CRA_PRESET_ENV, env);
58 postcssPlugins = CRA_PLUGINS(mergedPreset);
59
60 log('Merged PostCSS env preset.');
61 } else {
62 let craPlugins: any[] = [];
63
64 if (!isString(match.loader.options)) {
65 const options = match.loader.options?.postcssOptions;
66 if (isFunction(options)) {
67 craPlugins = options().plugins;
68 } else {
69 craPlugins = options?.plugins;
70 }
71 }
72
73 postcssPlugins = craPlugins || [];
74 }
75
76 if (plugins) {
77 postcssPlugins = isFunction(plugins)
78 ? plugins(postcssPlugins)
79 : postcssPlugins.concat(plugins);
80
81 log('Added PostCSS plugins.');
82 }
83
84 if (match.loader.options && !isString(match.loader.options)) {
85 if (match.loader.options.postcssOptions) {
86 match.loader.options.postcssOptions.plugins = () => postcssPlugins;
87 } else {
88 match.loader.options.postcssOptions = {
89 plugins: () => postcssPlugins,
90 };
91 }
92 }
93 }
94}
95
96function applyLoaderOptions(
97 match: CompleteLoader,

Callers 1

overrideLoaderFunction · 0.85

Calls 6

isArrayFunction · 0.90
deepMergeWithArrayFunction · 0.90
logFunction · 0.90
isFunctionFunction · 0.90
CRA_PLUGINSFunction · 0.85
isStringFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…