Skip to content

Commit 8c839c8

Browse files
committed
Add proper CSS modules webpack configuration
- Import MiniCssExtractPlugin for production CSS extraction - Configure css-loader with modules option for .module.css files - Use style-loader for development, MiniCssExtractPlugin.loader for production - Set localIdentName pattern for CSS modules class names - This should resolve webpack compilation errors for CSS module imports Fixes Generator test failures with 'css-loader' module not found errors
1 parent 9d07413 commit 8c839c8

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
// Common configuration applying to client and server configuration
44
const { generateWebpackConfig, merge } = require('shakapacker');
5+
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
56

67
const baseClientWebpackConfig = generateWebpackConfig();
78

@@ -14,20 +15,17 @@ const commonOptions = {
1415
{
1516
test: /\.module\.css$/i,
1617
use: [
17-
'style-loader',
18+
process.env.NODE_ENV === 'development' ? 'style-loader' : MiniCssExtractPlugin.loader,
1819
{
1920
loader: 'css-loader',
2021
options: {
21-
modules: true,
22+
modules: {
23+
localIdentName: '[name]__[local]__[hash:base64:5]',
24+
},
2225
},
2326
},
2427
],
2528
},
26-
{
27-
test: /\.css$/i,
28-
exclude: /\.module\.css$/i,
29-
use: ['style-loader', 'css-loader'],
30-
},
3129
],
3230
},
3331
};

0 commit comments

Comments
 (0)