Skip to content

Commit 0be82af

Browse files
justin808claude
andcommitted
Use SWC only for TypeScript, Babel for all JavaScript
Simplified approach: SWC handles only .ts and .tsx files, while Babel handles all .js, .jsx, and .mjs files. This avoids the Stimulus compatibility issues entirely while still using SWC for TypeScript. This is a more maintainable solution than trying to selectively exclude specific directories from SWC processing. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 8d7e76b commit 0be82af

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

config/webpack/commonWebpackConfig.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,24 +73,20 @@ if (scssConfigIndex === -1) {
7373
const commonWebpackConfig = () => {
7474
const config = merge({}, baseClientWebpackConfig, commonOptions, ignoreWarningsConfig);
7575

76-
const controllersPath = path.resolve(__dirname, '../../client/app/controllers');
77-
78-
// Find and modify the SWC rule to exclude Stimulus controllers
76+
// Find the SWC rule and restrict it to only TypeScript files
77+
// Use Babel for all JavaScript files (SWC has compatibility issues with Stimulus)
7978
const swcRuleIndex = config.module.rules.findIndex(rule =>
8079
rule.test && /\.(ts|tsx|js|jsx|mjs|coffee)/.test(rule.test.toString())
8180
);
8281

8382
if (swcRuleIndex !== -1) {
84-
const originalExclude = config.module.rules[swcRuleIndex].exclude;
85-
config.module.rules[swcRuleIndex].exclude = [
86-
originalExclude,
87-
controllersPath
88-
].filter(Boolean);
83+
// Change SWC rule to only handle TypeScript files
84+
config.module.rules[swcRuleIndex].test = /\.(ts|tsx)(\.erb)?$/;
8985

90-
// Add Babel loader specifically for Stimulus controllers
86+
// Add Babel loader for all JavaScript files
9187
config.module.rules.push({
92-
test: /\.js$/,
93-
include: controllersPath,
88+
test: /\.(js|jsx|mjs)(\.erb)?$/,
89+
exclude: /node_modules/,
9490
use: {
9591
loader: 'babel-loader',
9692
options: {
@@ -101,6 +97,11 @@ const commonWebpackConfig = () => {
10197
modules: 'auto',
10298
bugfixes: true,
10399
exclude: ['transform-typeof-symbol']
100+
}],
101+
['@babel/preset-react', {
102+
runtime: 'automatic',
103+
development: process.env.NODE_ENV !== 'production',
104+
useBuiltIns: true
104105
}]
105106
]
106107
}

0 commit comments

Comments
 (0)