Skip to content

Commit 8d7e76b

Browse files
justin808claude
andcommitted
Use absolute path for controllers directory in webpack config
Webpack needs absolute paths for include/exclude rules to work properly. This ensures the Babel loader correctly picks up Stimulus controller files. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent b9b919f commit 8d7e76b

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

config/webpack/commonWebpackConfig.js

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

44
// Common configuration applying to client and server configuration
55
const { generateWebpackConfig, merge } = require('shakapacker');
6+
const path = require('path');
67

78
const baseClientWebpackConfig = generateWebpackConfig();
89
const commonOptions = {
@@ -72,6 +73,8 @@ if (scssConfigIndex === -1) {
7273
const commonWebpackConfig = () => {
7374
const config = merge({}, baseClientWebpackConfig, commonOptions, ignoreWarningsConfig);
7475

76+
const controllersPath = path.resolve(__dirname, '../../client/app/controllers');
77+
7578
// Find and modify the SWC rule to exclude Stimulus controllers
7679
const swcRuleIndex = config.module.rules.findIndex(rule =>
7780
rule.test && /\.(ts|tsx|js|jsx|mjs|coffee)/.test(rule.test.toString())
@@ -81,13 +84,13 @@ const commonWebpackConfig = () => {
8184
const originalExclude = config.module.rules[swcRuleIndex].exclude;
8285
config.module.rules[swcRuleIndex].exclude = [
8386
originalExclude,
84-
/client\/app\/controllers/
87+
controllersPath
8588
].filter(Boolean);
8689

8790
// Add Babel loader specifically for Stimulus controllers
8891
config.module.rules.push({
8992
test: /\.js$/,
90-
include: /client\/app\/controllers/,
93+
include: controllersPath,
9194
use: {
9295
loader: 'babel-loader',
9396
options: {

0 commit comments

Comments
 (0)