Skip to content

Commit 262e589

Browse files
authored
feat: support Shakapacker v9 (#627)
Shakapacker v9 brings support for Rspack as an alternative to webpack, and changes the default transpiler from Babel to SWC. While it would be interesting to explore these new options, for now I've had us stick with webpack and babel. See [here for the upgrade notes](https://github.com/shakacode/shakapacker/blob/main/docs/v9_upgrade.md)
1 parent e64b648 commit 262e589

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

variants/frontend-base-typescript/types.d.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,14 @@ declare module '*.jpg' {
1212
const content: string;
1313
export default content;
1414
}
15+
16+
// todo: even though shakapacker ships with its own types, it currently types
17+
// itself as "any" which will hopefully change in a future version
18+
declare module 'shakapacker' {
19+
import { Configuration } from 'webpack';
20+
21+
export function generateWebpackConfig(
22+
extraConfig?: Configuration
23+
): Configuration;
24+
export * from 'webpack-merge';
25+
}

variants/frontend-base/template.rb

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,24 @@
1818

1919
run "rails shakapacker:install"
2020

21-
# ensure the latest major versions of Shakapacker's peer dependencies are installed
22-
#
23-
# TODO: remove this once https://github.com/shakacode/shakapacker/pull/576 is landed
21+
# install dependencies for babel and webpack
2422
add_js_dependencies [
25-
"babel-loader@10",
26-
"compression-webpack-plugin@11",
27-
"webpack-assets-manifest@6",
28-
"webpack-cli@6",
29-
"webpack-merge@6"
23+
"@babel/core",
24+
"@babel/plugin-transform-runtime",
25+
"@babel/preset-env",
26+
"@babel/runtime",
27+
"babel-loader",
28+
"compression-webpack-plugin",
29+
"css-loader",
30+
"mini-css-extract-plugin",
31+
"sass-loader",
32+
"style-loader",
33+
"terser-webpack-plugin",
34+
"webpack-assets-manifest",
35+
"webpack-cli",
36+
"webpack-merge"
3037
]
31-
add_js_dependencies ["webpack-dev-server@5"], type: :dev
38+
add_js_dependencies ["webpack-dev-server"], type: :dev
3239

3340
# this is added by shakapacker:install, but we've already got one (with some extra tags)
3441
# in our template, so remove theirs otherwise the app will error when rendering this
@@ -48,6 +55,7 @@
4855
copy_file "config/webpack/webpack.config.js", force: true
4956

5057
gsub_file! "config/shakapacker.yml", "cache_path: tmp/shakapacker", "cache_path: tmp/cache/shakapacker"
58+
gsub_file! "config/shakapacker.yml", "javascript_transpiler: 'swc'", "javascript_transpiler: 'babel'"
5159
gsub_file! "config/shakapacker.yml", "source_path: app/javascript", "source_path: app/frontend"
5260

5361
old_shakapacker_test_compile_snippet = <<~EO_OLD

0 commit comments

Comments
 (0)