Skip to content

Commit da0c7f5

Browse files
justin808claude
andcommitted
Simplify CSS loader configuration using optional chaining
Replace verbose defensive coding with cleaner optional chaining and simpler array find pattern. The fix only applies if namedExport is enabled, which is not currently the case but may be in future Shakapacker versions. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent d6fa4d4 commit da0c7f5

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

config/webpack/commonWebpackConfig.js

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,23 +51,15 @@ if (sassLoaderIndex !== -1) {
5151
}
5252
}
5353

54-
// Fix css-loader configuration for CSS modules
54+
// Fix css-loader configuration for CSS modules if namedExport is enabled
5555
// When namedExport is true, exportLocalsConvention must be camelCaseOnly or dashesOnly
56-
const cssLoaderIndex = scssRule.use.findIndex((loader) => {
57-
if (typeof loader === 'string') {
58-
return loader.includes('css-loader');
59-
}
60-
return loader.loader && loader.loader.includes('css-loader');
56+
const cssLoader = scssRule.use.find(loader => {
57+
const loaderName = typeof loader === 'string' ? loader : loader?.loader;
58+
return loaderName?.includes('css-loader');
6159
});
6260

63-
if (cssLoaderIndex !== -1) {
64-
const cssLoader = scssRule.use[cssLoaderIndex];
65-
if (typeof cssLoader === 'object' && cssLoader.options && cssLoader.options.modules) {
66-
// If namedExport is enabled, ensure exportLocalsConvention is properly set
67-
if (cssLoader.options.modules.namedExport) {
68-
cssLoader.options.modules.exportLocalsConvention = 'camelCaseOnly';
69-
}
70-
}
61+
if (cssLoader?.options?.modules?.namedExport) {
62+
cssLoader.options.modules.exportLocalsConvention = 'camelCaseOnly';
7163
}
7264

7365
baseClientWebpackConfig.module.rules[scssConfigIndex].use.push(sassLoaderConfig);

0 commit comments

Comments
 (0)