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