fix(webpack): omit postcss plugins for css modules (#14616)

This commit is contained in:
Dan Roujinsky 2023-01-26 15:37:01 +02:00 committed by GitHub
parent 7af4c3faa3
commit 5e2f3154b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -457,7 +457,10 @@ function getCommonLoadersForCssModules(
loader: require.resolve('postcss-loader'),
options: {
implementation: require('postcss'),
postcssOptions: postcssOptionsCreator(options, includePaths),
postcssOptions: postcssOptionsCreator(options, {
includePaths,
forCssModules: true,
}),
},
},
];
@ -478,7 +481,7 @@ function getCommonLoadersForGlobalCss(
loader: require.resolve('postcss-loader'),
options: {
implementation: require('postcss'),
postcssOptions: postcssOptionsCreator(options, includePaths),
postcssOptions: postcssOptionsCreator(options, { includePaths }),
},
},
];
@ -498,7 +501,7 @@ function getCommonLoadersForGlobalStyle(
loader: require.resolve('postcss-loader'),
options: {
implementation: require('postcss'),
postcssOptions: postcssOptionsCreator(options, includePaths),
postcssOptions: postcssOptionsCreator(options, { includePaths }),
},
},
];
@ -506,7 +509,10 @@ function getCommonLoadersForGlobalStyle(
function postcssOptionsCreator(
options: NormalizedWebpackExecutorOptions,
includePaths: string[]
{
includePaths,
forCssModules = false,
}: { includePaths: string[]; forCssModules?: boolean }
) {
const hashFormat = getOutputHashFormat(options.outputHashing as string);
// PostCSS options depend on the webpack loader, but we need to set the `config` path as a string due to this check:
@ -523,13 +529,17 @@ function postcssOptionsCreator(
addModulesDirectories: includePaths,
resolve: (url: string) => (url.startsWith('~') ? url.slice(1) : url),
}),
PostcssCliResources({
baseHref: options.baseHref,
deployUrl: options.deployUrl,
loader,
filename: `[name]${hashFormat.file}.[ext]`,
}),
autoprefixer(),
...(forCssModules
? []
: [
PostcssCliResources({
baseHref: options.baseHref,
deployUrl: options.deployUrl,
loader,
filename: `[name]${hashFormat.file}.[ext]`,
}),
autoprefixer(),
]),
],
});