@@ -137,6 +137,94 @@ This is a monorepo containing both the open-source package and the Pro package:
137137- ** Examples** : Generated via rake tasks for different webpack configurations
138138- ** Rake tasks** : Defined in ` rakelib/ ` for various development operations
139139
140+ ## Debugging Webpack Configuration Issues
141+
142+ When encountering issues with Webpack/Shakapacker configuration (e.g., components not rendering, CSS modules failing), use this debugging approach:
143+
144+ ### 1. Create Debug Scripts
145+
146+ Create temporary debug scripts in the dummy app root to inspect the actual webpack configuration:
147+
148+ ``` javascript
149+ // debug-webpack-rules.js - Inspect all webpack rules
150+ const { generateWebpackConfig } = require (' shakapacker' );
151+
152+ const config = generateWebpackConfig ();
153+
154+ console .log (' === Webpack Rules ===' );
155+ console .log (` Total rules: ${ config .module .rules .length } \n ` );
156+
157+ config .module .rules .forEach ((rule , index ) => {
158+ console .log (` \n Rule ${ index} :` );
159+ console .log (' test:' , rule .test );
160+ console .log (' use:' , Array .isArray (rule .use ) ? rule .use .map (u => typeof u === ' string' ? u : u .loader ) : rule .use );
161+
162+ if (rule .test ) {
163+ console .log (' Matches .scss:' , rule .test .test && rule .test .test (' example.scss' ));
164+ console .log (' Matches .module.scss:' , rule .test .test && rule .test .test (' example.module.scss' ));
165+ }
166+ });
167+ ```
168+
169+ ``` javascript
170+ // debug-webpack-with-config.js - Inspect config AFTER modifications
171+ const commonWebpackConfig = require (' ./config/webpack/commonWebpackConfig' );
172+
173+ const config = commonWebpackConfig ();
174+
175+ console .log (' === Webpack Rules AFTER commonWebpackConfig ===' );
176+ config .module .rules .forEach ((rule , index ) => {
177+ if (rule .test && rule .test .test (' example.module.scss' )) {
178+ console .log (` \n Rule ${ index} (CSS Modules):` );
179+ if (Array .isArray (rule .use )) {
180+ rule .use .forEach ((loader , i ) => {
181+ if (loader .loader && loader .loader .includes (' css-loader' )) {
182+ console .log (` css-loader options:` , loader .options );
183+ }
184+ });
185+ }
186+ }
187+ });
188+ ```
189+
190+ ### 2. Run Debug Scripts
191+
192+ ``` bash
193+ cd spec/dummy # or react_on_rails_pro/spec/dummy
194+ NODE_ENV=test RAILS_ENV=test node debug-webpack-rules.js
195+ NODE_ENV=test RAILS_ENV=test node debug-webpack-with-config.js
196+ ```
197+
198+ ### 3. Analyze Output
199+
200+ - Verify the rules array structure matches expectations
201+ - Check that loader options are correctly set
202+ - Confirm rules only match intended file patterns
203+ - Ensure modifications don't break existing loaders
204+
205+ ### 4. Common Issues & Solutions
206+
207+ ** CSS Modules breaking after Shakapacker upgrade:**
208+ - Shakapacker 9.0+ defaults to ` namedExport: true ` for CSS Modules
209+ - Existing code using ` import styles from './file.module.css' ` will fail
210+ - Override in webpack config:
211+ ``` javascript
212+ loader .options .modules .namedExport = false ;
213+ loader .options .modules .exportLocalsConvention = ' camelCase' ;
214+ ```
215+
216+ ** Rules not matching expected files:**
217+ - Use ` .test.test('example.file') ` to check regex matching
218+ - Shakapacker may combine multiple file extensions in single rules
219+ - Test with actual filenames from your codebase
220+
221+ ### 5. Clean Up
222+
223+ Always remove debug scripts before committing:
224+ ``` bash
225+ rm debug-* .js
226+ ```
227+
140228## Important Notes
141229
142230- Use ` yalc ` for local development when testing with external apps
0 commit comments