Skip to content

Commit 8b80714

Browse files
authored
Switch from Babel to SWC for faster JavaScript transpilation (#677)
This commit migrates the project from Babel to SWC (Speedy Web Compiler) following the Shakapacker documentation. * Add loose: false to SWC config for Stimulus compatibility Override Shakapacker's default loose: true setting with loose: false to ensure spec-compliant class transforms that work with Stimulus. Without this, Stimulus controllers fail silently even with keepClassNames: true.
1 parent ef11653 commit 8b80714

File tree

4 files changed

+1607
-1391
lines changed

4 files changed

+1607
-1391
lines changed

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: babel
11+
javascript_transpiler: swc
1212

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

config/swc.config.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const { env } = require('shakapacker');
2+
3+
const customConfig = {
4+
options: {
5+
jsc: {
6+
// Preserve class names for Stimulus controller discovery
7+
keepClassNames: true,
8+
// Use spec-compliant transforms (override Shakapacker's loose: true default)
9+
// This is required for Stimulus controllers to work correctly
10+
loose: false,
11+
transform: {
12+
react: {
13+
// Use automatic runtime (React 17+) - no need to import React
14+
runtime: 'automatic',
15+
// Enable React Fast Refresh in development
16+
refresh: env.isDevelopment && env.runningWebpackDevServer,
17+
},
18+
},
19+
},
20+
},
21+
};
22+
23+
module.exports = customConfig;

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
"@rails/actioncable": "7.0.5",
4646
"@rescript/core": "^0.5.0",
4747
"@rescript/react": "^0.11.0",
48+
"@swc/core": "^1.13.5",
49+
"ajv": "^8.17.1",
4850
"autoprefixer": "^10.4.14",
4951
"axios": "^0.21.1",
5052
"babel-loader": "^9.1.2",
@@ -96,6 +98,7 @@
9698
"shakapacker": "9.0.0-beta.8",
9799
"stimulus": "^3.0.1",
98100
"style-loader": "^3.3.1",
101+
"swc-loader": "^0.2.6",
99102
"tailwindcss": "^3.3.3",
100103
"terser-webpack-plugin": "5",
101104
"turbolinks": "^5.2.0",

0 commit comments

Comments
 (0)