Skip to content

Commit 7a70ec1

Browse files
committed
Simplify CSS loader configuration in webpack common config
- Use straightforward module rules approach instead of complex merge logic - Ensure CSS files are properly processed by webpack - Add basic style-loader and css-loader configuration
1 parent 9c8449e commit 7a70ec1

File tree

1 file changed

+9
-25
lines changed

1 file changed

+9
-25
lines changed

lib/generators/react_on_rails/templates/base/base/config/webpack/commonWebpackConfig.js.tt

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,17 @@ const commonOptions = {
99
resolve: {
1010
extensions: ['.css', '.ts', '.tsx'],
1111
},
12+
module: {
13+
rules: [
14+
{
15+
test: /\.css$/i,
16+
use: ['style-loader', 'css-loader'],
17+
},
18+
],
19+
},
1220
};
1321

1422
// Copy the object using merge b/c the baseClientWebpackConfig and commonOptions are mutable globals
15-
const commonWebpackConfig = () => {
16-
const config = merge({}, baseClientWebpackConfig, commonOptions);
17-
18-
// Ensure CSS loader is properly configured
19-
if (!config.module) {
20-
config.module = {};
21-
}
22-
if (!config.module.rules) {
23-
config.module.rules = [];
24-
}
25-
26-
// Add CSS loader rule if not already present
27-
const hasCssRule = config.module.rules.some(rule =>
28-
rule.test && rule.test.toString().includes('css')
29-
);
30-
31-
if (!hasCssRule) {
32-
config.module.rules.push({
33-
test: /\.css$/i,
34-
use: ['style-loader', 'css-loader'],
35-
});
36-
}
37-
38-
return config;
39-
};
23+
const commonWebpackConfig = () => merge({}, baseClientWebpackConfig, commonOptions);
4024

4125
module.exports = commonWebpackConfig;

0 commit comments

Comments
 (0)