Skip to content

Commit b4a1673

Browse files
justin808claude
andcommitted
Use Babel for Stimulus controllers, SWC for everything else
SWC has compatibility issues with Stimulus controllers' static class properties and inheritance from @hotwired/stimulus Controller class. This hybrid approach uses: - Babel for files in client/app/controllers/ (Stimulus) - SWC for all other JavaScript/React code The Babel rule is added via commonWebpackConfig.js and uses the same preset-env settings that Babel previously used for the entire codebase. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent d27fd67 commit b4a1673

File tree

4 files changed

+20083
-1382
lines changed

4 files changed

+20083
-1382
lines changed

config/webpack/commonWebpackConfig.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,34 @@ 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+
presets: [
80+
['@babel/preset-env', {
81+
useBuiltIns: 'entry',
82+
corejs: 3,
83+
modules: 'auto',
84+
bugfixes: true,
85+
exclude: ['transform-typeof-symbol']
86+
}]
87+
]
88+
}
89+
}
90+
};
91+
7192
// Copy the object using merge b/c the baseClientWebpackConfig and commonOptions are mutable globals
72-
const commonWebpackConfig = () => merge({}, baseClientWebpackConfig, commonOptions, ignoreWarningsConfig);
93+
const commonWebpackConfig = () => {
94+
const config = merge({}, baseClientWebpackConfig, commonOptions, ignoreWarningsConfig);
95+
// Add the Stimulus-specific Babel rule at the beginning so it takes precedence
96+
config.module.rules.unshift(stimulusRule);
97+
return config;
98+
};
7399

74100
module.exports = commonWebpackConfig;
75101

0 commit comments

Comments
 (0)