Skip to content

Commit e0ad587

Browse files
committed
Revert to Babel transpiler for all files
Using pure Babel configuration (javascript_transpiler: babel) instead of hybrid Babel/SWC approach. This matches the working master configuration and should fix RSpec test failures with Stimulus controllers. We'll investigate SWC compatibility separately after confirming beta.11 works with Babel.
1 parent de1e97c commit e0ad587

File tree

3 files changed

+34
-42
lines changed

3 files changed

+34
-42
lines changed

babel.config.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
module.exports = function (api) {
2+
const defaultConfigFunc = require('shakapacker/package/babel/preset.js');
3+
const resultConfig = defaultConfigFunc(api);
4+
const isProductionEnv = api.env('production');
5+
6+
const changesOnDefault = {
7+
presets: [
8+
[
9+
'@babel/preset-react',
10+
{
11+
runtime: 'automatic',
12+
development: !isProductionEnv,
13+
useBuiltIns: true,
14+
},
15+
],
16+
].filter(Boolean),
17+
plugins: [
18+
process.env.WEBPACK_SERVE && 'react-refresh/babel',
19+
isProductionEnv && [
20+
'babel-plugin-transform-react-remove-prop-types',
21+
{
22+
removeImport: true,
23+
},
24+
],
25+
].filter(Boolean),
26+
};
27+
28+
resultConfig.presets = [...resultConfig.presets, ...changesOnDefault.presets];
29+
resultConfig.plugins = [...resultConfig.plugins, ...changesOnDefault.plugins];
30+
31+
return resultConfig;
32+
};

config/shakapacker.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ default: &default
88
cache_path: tmp/shakapacker
99
webpack_compile_output: true
1010
nested_entries: true
11-
javascript_transpiler: swc
11+
javascript_transpiler: babel
1212

1313
# Additional paths webpack should lookup modules
1414
# ['app/assets', 'engine/foo/app/assets']

config/webpack/commonWebpackConfig.js

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -69,47 +69,7 @@ if (scssConfigIndex === -1) {
6969
}
7070

7171
// Copy the object using merge b/c the baseClientWebpackConfig and commonOptions are mutable globals
72-
const commonWebpackConfig = () => {
73-
const config = merge({}, baseClientWebpackConfig, commonOptions, ignoreWarningsConfig);
74-
75-
// Find the SWC rule and get its include/exclude
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 swcRule = config.module.rules[swcRuleIndex];
82-
83-
// Insert Babel rule BEFORE SWC rule so it matches .js files first
84-
// This allows Babel to handle all JavaScript while SWC continues to match TypeScript
85-
config.module.rules.splice(swcRuleIndex, 0, {
86-
test: /\.(js|jsx|mjs)(\.erb)?$/,
87-
include: swcRule.include,
88-
exclude: swcRule.exclude,
89-
use: {
90-
loader: 'babel-loader',
91-
options: {
92-
presets: [
93-
['@babel/preset-env', {
94-
useBuiltIns: 'entry',
95-
corejs: 3,
96-
modules: 'auto',
97-
bugfixes: true,
98-
exclude: ['transform-typeof-symbol']
99-
}],
100-
['@babel/preset-react', {
101-
runtime: 'automatic',
102-
development: process.env.NODE_ENV !== 'production',
103-
useBuiltIns: true
104-
}]
105-
]
106-
}
107-
}
108-
});
109-
}
110-
111-
return config;
112-
};
72+
const commonWebpackConfig = () => merge({}, baseClientWebpackConfig, commonOptions, ignoreWarningsConfig);
11373

11474
module.exports = commonWebpackConfig;
11575

0 commit comments

Comments
 (0)