Skip to content

Commit

Permalink
fix(webpack): omit postcss plugins for css modules (#14616)
Browse files Browse the repository at this point in the history
  • Loading branch information
danr-za committed Jan 26, 2023
1 parent 7af4c3f commit 5e2f315
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions packages/webpack/src/utils/with-web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}),
},
},
];
Expand All @@ -478,7 +481,7 @@ function getCommonLoadersForGlobalCss(
loader: require.resolve('postcss-loader'),
options: {
implementation: require('postcss'),
postcssOptions: postcssOptionsCreator(options, includePaths),
postcssOptions: postcssOptionsCreator(options, { includePaths }),
},
},
];
Expand All @@ -498,15 +501,18 @@ function getCommonLoadersForGlobalStyle(
loader: require.resolve('postcss-loader'),
options: {
implementation: require('postcss'),
postcssOptions: postcssOptionsCreator(options, includePaths),
postcssOptions: postcssOptionsCreator(options, { includePaths }),
},
},
];
}

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:
Expand All @@ -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(),
]),
],
});

Expand Down

0 comments on commit 5e2f315

Please sign in to comment.