Skip to content

Commit 0444f60

Browse files
justin808claude
andcommitted
Insert Babel rule before SWC rule for proper precedence
Use splice() to insert the Babel rule BEFORE the SWC rule in the rules array. This ensures Babel handles .js files first, while SWC's more general regex still matches .ts and .tsx files. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 21e9a2c commit 0444f60

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

config/webpack/commonWebpackConfig.js

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

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)
76+
// Find the SWC rule and get its include/exclude
7877
const swcRuleIndex = config.module.rules.findIndex(rule =>
7978
rule.test && /\.(ts|tsx|js|jsx|mjs|coffee)/.test(rule.test.toString())
8079
);
8180

8281
if (swcRuleIndex !== -1) {
8382
const swcRule = config.module.rules[swcRuleIndex];
8483

85-
// Change SWC rule to only handle TypeScript files
86-
swcRule.test = /\.(ts|tsx)(\.erb)?$/;
87-
88-
// Add Babel loader for all JavaScript files, using the same include/exclude as SWC
89-
config.module.rules.push({
84+
// Insert Babel rule BEFORE SWC rule so it matches .js files first
85+
// This allows Babel to handle all JavaScript while SWC continues to match TypeScript
86+
config.module.rules.splice(swcRuleIndex, 0, {
9087
test: /\.(js|jsx|mjs)(\.erb)?$/,
9188
include: swcRule.include,
9289
exclude: swcRule.exclude,

0 commit comments

Comments
 (0)