Skip to content

Commit b9b919f

Browse files
justin808claude
andcommitted
Exclude Stimulus controllers from SWC, use Babel instead
The inputSourceMap error was because SWC loader was still processing the controllers directory. Now we explicitly exclude client/app/controllers from the SWC rule and add a separate Babel rule for those files only. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 1ff85ee commit b9b919f

File tree

1 file changed

+34
-25
lines changed

1 file changed

+34
-25
lines changed

config/webpack/commonWebpackConfig.js

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -68,34 +68,43 @@ if (scssConfigIndex === -1) {
6868
baseClientWebpackConfig.module.rules[scssConfigIndex].use.push(sassLoaderConfig);
6969
}
7070

71-
// Add Babel loader for Stimulus controllers (SWC has compatibility issues with Stimulus)
72-
const stimulusRule = {
73-
test: /\.js$/,
74-
include: /client\/app\/controllers/,
75-
exclude: /node_modules/,
76-
use: {
77-
loader: 'babel-loader',
78-
options: {
79-
sourceMaps: false,
80-
inputSourceMap: undefined,
81-
presets: [
82-
['@babel/preset-env', {
83-
useBuiltIns: 'entry',
84-
corejs: 3,
85-
modules: 'auto',
86-
bugfixes: true,
87-
exclude: ['transform-typeof-symbol']
88-
}]
89-
]
90-
}
91-
}
92-
};
93-
9471
// Copy the object using merge b/c the baseClientWebpackConfig and commonOptions are mutable globals
9572
const commonWebpackConfig = () => {
9673
const config = merge({}, baseClientWebpackConfig, commonOptions, ignoreWarningsConfig);
97-
// Add the Stimulus-specific Babel rule at the beginning so it takes precedence
98-
config.module.rules.unshift(stimulusRule);
74+
75+
// Find and modify the SWC rule to exclude Stimulus controllers
76+
const swcRuleIndex = config.module.rules.findIndex(rule =>
77+
rule.test && /\.(ts|tsx|js|jsx|mjs|coffee)/.test(rule.test.toString())
78+
);
79+
80+
if (swcRuleIndex !== -1) {
81+
const originalExclude = config.module.rules[swcRuleIndex].exclude;
82+
config.module.rules[swcRuleIndex].exclude = [
83+
originalExclude,
84+
/client\/app\/controllers/
85+
].filter(Boolean);
86+
87+
// Add Babel loader specifically for Stimulus controllers
88+
config.module.rules.push({
89+
test: /\.js$/,
90+
include: /client\/app\/controllers/,
91+
use: {
92+
loader: 'babel-loader',
93+
options: {
94+
presets: [
95+
['@babel/preset-env', {
96+
useBuiltIns: 'entry',
97+
corejs: 3,
98+
modules: 'auto',
99+
bugfixes: true,
100+
exclude: ['transform-typeof-symbol']
101+
}]
102+
]
103+
}
104+
}
105+
});
106+
}
107+
99108
return config;
100109
};
101110

0 commit comments

Comments
 (0)