shakapacker 9.0.0.beta.0 → 9.0.0.beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/claude-code-review.yml +54 -0
  3. data/.github/workflows/claude.yml +50 -0
  4. data/.rubocop.yml +1 -0
  5. data/CHANGELOG.md +6 -2
  6. data/Gemfile.lock +1 -1
  7. data/Rakefile +18 -1
  8. data/docs/rspack.md +7 -7
  9. data/docs/rspack_migration_guide.md +202 -0
  10. data/docs/using_esbuild_loader.md +3 -3
  11. data/docs/using_swc_loader.md +5 -3
  12. data/lib/install/bin/shakapacker +3 -17
  13. data/lib/install/config/shakapacker.yml +5 -4
  14. data/lib/shakapacker/configuration.rb +36 -3
  15. data/lib/shakapacker/dev_server_runner.rb +19 -9
  16. data/lib/shakapacker/manifest.rb +4 -3
  17. data/lib/shakapacker/rspack_runner.rb +4 -42
  18. data/lib/shakapacker/runner.rb +105 -11
  19. data/lib/shakapacker/utils/manager.rb +2 -0
  20. data/lib/shakapacker/version.rb +1 -1
  21. data/lib/shakapacker/version_checker.rb +1 -1
  22. data/lib/shakapacker/webpack_runner.rb +4 -42
  23. data/lib/tasks/shakapacker/install.rake +6 -2
  24. data/package/config.js +24 -0
  25. data/package/environments/base.js +12 -2
  26. data/package/environments/development.js +52 -12
  27. data/package/environments/production.js +8 -3
  28. data/package/environments/test.js +5 -3
  29. data/package/index.d.ts +57 -29
  30. data/package/index.js +1 -1
  31. data/package/optimization/rspack.js +9 -5
  32. data/package/plugins/rspack.js +12 -28
  33. data/package/rspack/index.js +57 -0
  34. data/package/rules/babel.js +2 -2
  35. data/package/rules/esbuild.js +2 -2
  36. data/package/rules/raw.js +5 -5
  37. data/package/rules/rspack.js +73 -7
  38. data/package/rules/swc.js +2 -2
  39. data/package/utils/debug.js +49 -0
  40. data/package/utils/getStyleRule.js +3 -3
  41. data/package/utils/requireOrError.js +1 -1
  42. data/package/utils/validateDependencies.js +61 -0
  43. data/package/webpackDevServerConfig.js +2 -0
  44. data/package.json +1 -1
  45. data/test/package/rules/esbuild.test.js +1 -1
  46. data/test/package/rules/swc.test.js +1 -1
  47. metadata +8 -3
  48. data/lib/install/bin/shakapacker-rspack +0 -13
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1d5eb8596c44c47d26f7d8954138ccff49880d0cfbbda9dd1669dd6d07e7c32f
4
- data.tar.gz: 84aabd814e5ff1e723ff796ac4c02b37073c66f91695579dbdfe6850a44cfc6d
3
+ metadata.gz: 02da73fe458c789d3774f993cdc5d4ec082aec418d746bd96d279a6e636fb9dc
4
+ data.tar.gz: b0342e33b80c52751b7a63102492d9dbd3bcc88c485bd1b831ab902263d45404
5
5
  SHA512:
6
- metadata.gz: c4158d767e170a0e18dcb1b9ad96558d2e13cd3ceed162c6e231d94cb1f99e8e62fe2da64be70fceeebf11ea1616af9c1da07c77469a9764e22ccaacb6c8da8d
7
- data.tar.gz: aec89994b6c27b2109377959dd3ad1be1ca557bacadff21bf37df5c91760ac8f1e1e60eaf47f1be54997966c5b58090b70dd1154cba8431136836529bb8232ae
6
+ metadata.gz: 9950e533356e907aa0e68202dfe40af8ed5d96f633ba4a0aeff28ddf214daaf1b9cd02bbb7b74ba0fa8d4bcea00c2c7b1cd6fdd7d14a8e0d333932c3ece79a7a
7
+ data.tar.gz: aeb7b646e6d07e7ed7dd056113b98521701161c7d2909ec18a4d0771b473e970d7006ccfec4b7a4da1e789da56be0d6ecb8d95db651d0fae8c7ef7cf70be951f
@@ -0,0 +1,54 @@
1
+ name: Claude Code Review
2
+
3
+ on:
4
+ pull_request:
5
+ types: [opened, synchronize]
6
+ # Optional: Only run on specific file changes
7
+ # paths:
8
+ # - "src/**/*.ts"
9
+ # - "src/**/*.tsx"
10
+ # - "src/**/*.js"
11
+ # - "src/**/*.jsx"
12
+
13
+ jobs:
14
+ claude-review:
15
+ # Optional: Filter by PR author
16
+ # if: |
17
+ # github.event.pull_request.user.login == 'external-contributor' ||
18
+ # github.event.pull_request.user.login == 'new-developer' ||
19
+ # github.event.pull_request.author_association == 'FIRST_TIME_CONTRIBUTOR'
20
+
21
+ runs-on: ubuntu-latest
22
+ permissions:
23
+ contents: read
24
+ pull-requests: read
25
+ issues: read
26
+ id-token: write
27
+
28
+ steps:
29
+ - name: Checkout repository
30
+ uses: actions/checkout@v4
31
+ with:
32
+ fetch-depth: 1
33
+
34
+ - name: Run Claude Code Review
35
+ id: claude-review
36
+ uses: anthropics/claude-code-action@v1
37
+ with:
38
+ claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
39
+ prompt: |
40
+ Please review this pull request and provide feedback on:
41
+ - Code quality and best practices
42
+ - Potential bugs or issues
43
+ - Performance considerations
44
+ - Security concerns
45
+ - Test coverage
46
+
47
+ Use the repository's CLAUDE.md for guidance on style and conventions. Be constructive and helpful in your feedback.
48
+
49
+ Use `gh pr comment` with your Bash tool to leave your review as a comment on the PR.
50
+
51
+ # See https://github.com/anthropics/claude-code-action/blob/main/docs/usage.md
52
+ # or https://docs.claude.com/en/docs/claude-code/sdk#command-line for available options
53
+ claude_args: '--allowed-tools "Bash(gh issue view:*),Bash(gh search:*),Bash(gh issue list:*),Bash(gh pr comment:*),Bash(gh pr diff:*),Bash(gh pr view:*),Bash(gh pr list:*)"'
54
+
@@ -0,0 +1,50 @@
1
+ name: Claude Code
2
+
3
+ on:
4
+ issue_comment:
5
+ types: [created]
6
+ pull_request_review_comment:
7
+ types: [created]
8
+ issues:
9
+ types: [opened, assigned]
10
+ pull_request_review:
11
+ types: [submitted]
12
+
13
+ jobs:
14
+ claude:
15
+ if: |
16
+ (github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude')) ||
17
+ (github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude')) ||
18
+ (github.event_name == 'pull_request_review' && contains(github.event.review.body, '@claude')) ||
19
+ (github.event_name == 'issues' && (contains(github.event.issue.body, '@claude') || contains(github.event.issue.title, '@claude')))
20
+ runs-on: ubuntu-latest
21
+ permissions:
22
+ contents: read
23
+ pull-requests: read
24
+ issues: read
25
+ id-token: write
26
+ actions: read # Required for Claude to read CI results on PRs
27
+ steps:
28
+ - name: Checkout repository
29
+ uses: actions/checkout@v4
30
+ with:
31
+ fetch-depth: 1
32
+
33
+ - name: Run Claude Code
34
+ id: claude
35
+ uses: anthropics/claude-code-action@v1
36
+ with:
37
+ claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
38
+
39
+ # This is an optional setting that allows Claude to read CI results on PRs
40
+ additional_permissions: |
41
+ actions: read
42
+
43
+ # Optional: Give a custom prompt to Claude. If this is not specified, Claude will perform the instructions specified in the comment that tagged it.
44
+ # prompt: 'Update the pull request description to include a summary of changes.'
45
+
46
+ # Optional: Add claude_args to customize behavior and configuration
47
+ # See https://github.com/anthropics/claude-code-action/blob/main/docs/usage.md
48
+ # or https://docs.claude.com/en/docs/claude-code/sdk#command-line for available options
49
+ # claude_args: '--model claude-opus-4-1-20250805 --allowed-tools Bash(gh pr:*)'
50
+
data/.rubocop.yml CHANGED
@@ -9,6 +9,7 @@ AllCops:
9
9
  - "vendor/**/*"
10
10
  - "node_modules/**/*"
11
11
  - "_actions/**/*"
12
+ - "spec/dummy-rspack/**/*"
12
13
 
13
14
  # Prefer &&/|| over and/or.
14
15
  Style/AndOr:
data/CHANGELOG.md CHANGED
@@ -8,8 +8,12 @@
8
8
  ## [Unreleased]
9
9
  Changes since the last non-beta release.
10
10
 
11
- - Rspack support as an alternative bundler to webpack. Configure `bundler: 'rspack'` in `shakapacker.yml` to use Rspack's faster Rust-based bundling with webpack-compatible
12
- APIs, built-in SWC loader, and CSS extraction. Automatic bundler detection in `bin/shakapacker` with fallback support for webpack configurations.
11
+ ### Added
12
+ - Rspack support as an alternative assets bundler to webpack. Configure `assets_bundler: 'rspack'` in `shakapacker.yml` to use Rspack's faster Rust-based bundling with webpack-compatible APIs, built-in SWC loader, and CSS extraction. Automatic assets bundler detection in `bin/shakapacker` with fallback support for webpack configurations.
13
+
14
+ ### Changed
15
+ - Configuration option renamed from `bundler` to `assets_bundler` to avoid confusion with Ruby's Bundler gem manager. The old `bundler` option is deprecated but still supported with a warning (not a breaking change).
16
+ - BREAKING CHANGE: Configuration option renamed from `webpack_loader` to `javascript_transpiler` to better reflect its purpose of configuring JavaScript transpilation regardless of the bundler used. The old `webpack_loader` option is deprecated but still supported with a warning.
13
17
 
14
18
  ## [v8.4.0] - September 8, 2025
15
19
  ### Added
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- shakapacker (9.0.0.beta.0)
4
+ shakapacker (9.0.0.beta.2)
5
5
  activesupport (>= 5.2)
6
6
  package_json
7
7
  rack-proxy (>= 0.6.1)
data/Rakefile CHANGED
@@ -24,6 +24,23 @@ namespace :run_spec do
24
24
  "bundle install",
25
25
  "yalc link shakapacker",
26
26
  "yarn install",
27
+ "NODE_ENV=test RAILS_ENV=test yarn run webpack --config config/webpack/webpack.config.js",
28
+ "bundle exec rspec"
29
+ ])
30
+ end
31
+ end
32
+
33
+ desc "Run specs in the dummy-rspack app"
34
+ task :dummy_rspack do
35
+ puts "Running dummy-rspack app specs"
36
+ spec_dummy_dir = Pathname.new(File.join("spec", "dummy-rspack")).realpath
37
+ Bundler.with_unbundled_env do
38
+ sh_in_dir(".", "yalc publish")
39
+ sh_in_dir(spec_dummy_dir, [
40
+ "bundle install",
41
+ "yalc link shakapacker",
42
+ "yarn install",
43
+ "NODE_ENV=test RAILS_ENV=test yarn run rspack build --config config/webpack/webpack.config.js",
27
44
  "bundle exec rspec"
28
45
  ])
29
46
  end
@@ -35,7 +52,7 @@ namespace :run_spec do
35
52
  end
36
53
 
37
54
  desc "Run all specs"
38
- task all_specs: %i[gem dummy generator] do
55
+ task all_specs: %i[gem dummy dummy_rspack generator] do
39
56
  puts "Completed all RSpec tests"
40
57
  end
41
58
  end
data/docs/rspack.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Rspack Integration
2
2
 
3
- Shakapacker supports [Rspack](https://rspack.rs) as an alternative bundler to Webpack. Rspack is a fast Rust-based web bundler with webpack-compatible API that can significantly speed up your build times.
3
+ Shakapacker supports [Rspack](https://rspack.rs) as an alternative assets bundler to Webpack. Rspack is a fast Rust-based web bundler with webpack-compatible API that can significantly speed up your build times.
4
4
 
5
5
  ## Installation
6
6
 
@@ -25,10 +25,10 @@ To enable Rspack, update your `config/shakapacker.yml`:
25
25
  ```yaml
26
26
  default: &default
27
27
  # ... other config options
28
- bundler: 'rspack' # Change from 'webpack' to 'rspack'
28
+ assets_bundler: 'rspack' # Change from 'webpack' to 'rspack'
29
29
  ```
30
30
 
31
- ## Configuration
31
+ ### Configuration Files
32
32
 
33
33
  Rspack uses its own configuration directory to keep things organized. Create your Rspack configuration file at `config/rspack/rspack.config.js`:
34
34
 
@@ -73,7 +73,7 @@ const { generateRspackConfig } = require('shakapacker/rspack')
73
73
  module.exports = generateRspackConfig()
74
74
  ```
75
75
 
76
- > **Note:** Shakapacker will show a deprecation warning if you use `config/webpack/webpack.config.js` with `bundler: 'rspack'`. Please migrate to `config/rspack/rspack.config.js`.
76
+ > **Note:** Shakapacker will show a deprecation warning if you use `config/webpack/webpack.config.js` with `assets_bundler: 'rspack'`. Please migrate to `config/rspack/rspack.config.js`.
77
77
 
78
78
  ## Key Differences from Webpack
79
79
 
@@ -119,10 +119,10 @@ optimization: {
119
119
  All existing Shakapacker commands work the same way and automatically use Rspack when configured:
120
120
 
121
121
  ```bash
122
- # Build (automatically uses rspack when bundler: 'rspack')
122
+ # Build (automatically uses rspack when assets_bundler: 'rspack')
123
123
  ./bin/shakapacker
124
124
 
125
- # Development server (automatically uses rspack when bundler: 'rspack')
125
+ # Development server (automatically uses rspack when assets_bundler: 'rspack')
126
126
  ./bin/shakapacker-dev-server
127
127
 
128
128
  # Watch mode
@@ -151,7 +151,7 @@ Rspack typically provides:
151
151
  ```yaml
152
152
  # config/shakapacker.yml
153
153
  default: &default
154
- bundler: 'rspack'
154
+ assets_bundler: 'rspack'
155
155
  ```
156
156
 
157
157
  3. **Create Rspack config:**
@@ -0,0 +1,202 @@
1
+ # Rspack Migration Guide for Shakapacker
2
+
3
+ ## Overview
4
+ This guide documents the differences between webpack and Rspack configurations in Shakapacker, and provides migration guidance for users switching to Rspack.
5
+
6
+ ## Key Differences from Webpack
7
+
8
+ ### 1. Built-in Loaders
9
+ Rspack provides built-in loaders for better performance:
10
+
11
+ **JavaScript/TypeScript:**
12
+ - Use `builtin:swc-loader` instead of `babel-loader` or `ts-loader`
13
+ - 20x faster than Babel on single thread, 70x on multiple cores
14
+ - Configuration example:
15
+ ```javascript
16
+ {
17
+ test: /\.(js|jsx|ts|tsx)$/,
18
+ loader: 'builtin:swc-loader',
19
+ options: {
20
+ jsc: {
21
+ parser: {
22
+ syntax: 'typescript', // or 'ecmascript'
23
+ tsx: true, // for TSX files
24
+ jsx: true // for JSX files
25
+ },
26
+ transform: {
27
+ react: {
28
+ runtime: 'automatic'
29
+ }
30
+ }
31
+ }
32
+ }
33
+ }
34
+ ```
35
+
36
+ ### 2. Plugin Replacements
37
+
38
+ #### Built-in Rspack Alternatives
39
+ | Webpack Plugin | Rspack Alternative | Status |
40
+ |---------------|-------------------|---------|
41
+ | `copy-webpack-plugin` | `rspack.CopyRspackPlugin` | ✅ Built-in |
42
+ | `mini-css-extract-plugin` | `rspack.CssExtractRspackPlugin` | ✅ Built-in |
43
+ | `terser-webpack-plugin` | `rspack.SwcJsMinimizerRspackPlugin` | ✅ Built-in |
44
+ | `css-minimizer-webpack-plugin` | `rspack.LightningCssMinimizerRspackPlugin` | ✅ Built-in |
45
+
46
+ #### Community Alternatives
47
+ | Webpack Plugin | Rspack Alternative | Package |
48
+ |---------------|-------------------|----------|
49
+ | `fork-ts-checker-webpack-plugin` | `ts-checker-rspack-plugin` | `npm i -D ts-checker-rspack-plugin` |
50
+ | `@pmmmwh/react-refresh-webpack-plugin` | `@rspack/plugin-react-refresh` | `npm i -D @rspack/plugin-react-refresh` |
51
+ | `eslint-webpack-plugin` | `eslint-rspack-plugin` | `npm i -D eslint-rspack-plugin` |
52
+
53
+ #### Incompatible Plugins
54
+ The following webpack plugins are NOT compatible with Rspack:
55
+ - `webpack.optimize.LimitChunkCountPlugin` - Use `optimization.splitChunks` configuration instead
56
+ - `webpack-manifest-plugin` - Use `rspack-manifest-plugin` instead
57
+ - Git revision plugins - Use alternative approaches
58
+
59
+ ### 3. Asset Module Types
60
+ Replace file loaders with asset modules:
61
+ - `file-loader` → `type: 'asset/resource'`
62
+ - `url-loader` → `type: 'asset/inline'`
63
+ - `raw-loader` → `type: 'asset/source'`
64
+
65
+ ### 4. Configuration Differences
66
+
67
+ #### TypeScript Configuration
68
+ **Required:** Add `isolatedModules: true` to your `tsconfig.json`:
69
+ ```json
70
+ {
71
+ "compilerOptions": {
72
+ "isolatedModules": true
73
+ }
74
+ }
75
+ ```
76
+
77
+ #### React Fast Refresh
78
+ ```javascript
79
+ // Development configuration
80
+ const ReactRefreshPlugin = require('@rspack/plugin-react-refresh');
81
+
82
+ module.exports = {
83
+ plugins: [
84
+ new ReactRefreshPlugin(),
85
+ new rspack.HotModuleReplacementPlugin()
86
+ ]
87
+ };
88
+ ```
89
+
90
+ ### 5. Optimization Differences
91
+
92
+ #### Code Splitting
93
+ Rspack's `splitChunks` configuration is similar to webpack but with some differences:
94
+ ```javascript
95
+ optimization: {
96
+ splitChunks: {
97
+ chunks: 'all',
98
+ cacheGroups: {
99
+ vendor: {
100
+ test: /[\\/]node_modules[\\/]/,
101
+ priority: -10,
102
+ reuseExistingChunk: true
103
+ }
104
+ }
105
+ }
106
+ }
107
+ ```
108
+
109
+ #### Minimization
110
+ ```javascript
111
+ optimization: {
112
+ minimize: true,
113
+ minimizer: [
114
+ new rspack.SwcJsMinimizerRspackPlugin(),
115
+ new rspack.LightningCssMinimizerRspackPlugin()
116
+ ]
117
+ }
118
+ ```
119
+
120
+ ### 6. Development Server
121
+ Rspack uses its own dev server with some configuration differences:
122
+ ```javascript
123
+ devServer: {
124
+ // Rspack-specific: Force writing assets to disk
125
+ devMiddleware: {
126
+ writeToDisk: true
127
+ }
128
+ }
129
+ ```
130
+
131
+ ## Migration Checklist
132
+
133
+ ### Step 1: Update Dependencies
134
+ ```bash
135
+ # Remove webpack dependencies
136
+ npm uninstall webpack webpack-cli webpack-dev-server
137
+
138
+ # Install Rspack
139
+ npm install --save-dev @rspack/core @rspack/cli
140
+ ```
141
+
142
+ ### Step 2: Update Configuration Files
143
+ 1. Create `config/rspack/rspack.config.js` based on your webpack config
144
+ 2. Update `config/shakapacker.yml`:
145
+ ```yaml
146
+ assets_bundler: 'rspack'
147
+ ```
148
+
149
+ ### Step 3: Replace Loaders
150
+ - Replace `babel-loader` with `builtin:swc-loader`
151
+ - Remove `file-loader`, `url-loader`, `raw-loader` - use asset modules
152
+ - Update CSS loaders to use Rspack's built-in support
153
+
154
+ ### Step 4: Update Plugins
155
+ - Replace plugins with Rspack alternatives (see table above)
156
+ - Remove incompatible plugins
157
+ - Add Rspack-specific plugins as needed
158
+
159
+ ### Step 5: TypeScript Setup
160
+ 1. Add `isolatedModules: true` to `tsconfig.json`
161
+ 2. Optional: Add `ts-checker-rspack-plugin` for type checking
162
+
163
+ ### Step 6: Test Your Build
164
+ ```bash
165
+ # Development build
166
+ bin/shakapacker
167
+
168
+ # Production build
169
+ bin/shakapacker --mode production
170
+ ```
171
+
172
+ ## Common Issues and Solutions
173
+
174
+ ### Issue: LimitChunkCountPlugin Error
175
+ **Error:** `Cannot read properties of undefined (reading 'tap')`
176
+ **Solution:** Remove `webpack.optimize.LimitChunkCountPlugin` and use `splitChunks` configuration instead.
177
+
178
+ ### Issue: Missing Loaders
179
+ **Error:** Module parse errors
180
+ **Solution:** Check console logs for skipped loaders and install missing dependencies.
181
+
182
+ ### Issue: CSS Extraction
183
+ **Error:** CSS not being extracted properly
184
+ **Solution:** Use `rspack.CssExtractRspackPlugin` instead of `mini-css-extract-plugin`.
185
+
186
+ ### Issue: TypeScript Errors
187
+ **Error:** TypeScript compilation errors
188
+ **Solution:** Ensure `isolatedModules: true` is set in `tsconfig.json`.
189
+
190
+ ## Performance Tips
191
+
192
+ 1. **Use Built-in Loaders:** Always prefer Rspack's built-in loaders for better performance
193
+ 2. **Minimize Plugins:** Use only necessary plugins as each adds overhead
194
+ 3. **Enable Caching:** Rspack has built-in persistent caching
195
+ 4. **Use SWC:** The built-in SWC loader is significantly faster than Babel
196
+
197
+ ## Resources
198
+
199
+ - [Rspack Documentation](https://rspack.rs)
200
+ - [Rspack Examples](https://github.com/rspack-contrib/rspack-examples)
201
+ - [Awesome Rspack](https://github.com/rspack-contrib/awesome-rspack)
202
+ - [Migration Guide](https://rspack.rs/guide/migration/webpack)
@@ -27,7 +27,7 @@ To use esbuild as your transpiler today. You need to do two things:
27
27
  npm install esbuild esbuild-loader
28
28
  ```
29
29
 
30
- 2. Add or change `webpack_loader` value in your default `shakapacker.yml` config to `esbuild`
30
+ 2. Add or change `javascript_transpiler` value in your default `shakapacker.yml` config to `esbuild`
31
31
  The default configuration of babel is done by using `package.json` to use the file within the `shakapacker` package.
32
32
 
33
33
  ```yml
@@ -46,8 +46,8 @@ default: &default
46
46
  # Reload manifest.json on all requests so we reload latest compiled packs
47
47
  cache_manifest: false
48
48
 
49
- # Select loader to use, available options are 'babel' (default), 'swc' or 'esbuild'
50
- webpack_loader: 'esbuild'
49
+ # Select JavaScript transpiler to use, available options are 'babel' (default), 'swc' or 'esbuild'
50
+ javascript_transpiler: 'esbuild'
51
51
  ```
52
52
 
53
53
  ### (Optional) Replace minification with esbuild
@@ -12,6 +12,8 @@ It supports all ECMAScript features and it's designed to be a drop-in replacemen
12
12
 
13
13
  For comparison between SWC and Babel, see the docs at https://swc.rs/docs/migrating-from-babel.
14
14
 
15
+ > **Note:** SWC is also natively built into RSpack bundler, providing even faster compilation speeds. When using RSpack (`assets_bundler: 'rspack'`), SWC is used automatically regardless of the `javascript_transpiler` setting.
16
+
15
17
  ## Switching your Shakapacker project to SWC
16
18
 
17
19
  In order to use SWC as your compiler today. You need to do two things:
@@ -22,7 +24,7 @@ In order to use SWC as your compiler today. You need to do two things:
22
24
  npm install @swc/core swc-loader
23
25
  ```
24
26
 
25
- 2. Add or change `webpack_loader` value in your default `shakapacker.yml` config to `swc`
27
+ 2. Add or change `javascript_transpiler` value in your default `shakapacker.yml` config to `swc`
26
28
  The default configuration of babel is done by using `package.json` to use the file within the `shakapacker` package.
27
29
 
28
30
  ```yml
@@ -41,8 +43,8 @@ default: &default
41
43
  # Reload manifest.json on all requests so we reload latest compiled packs
42
44
  cache_manifest: false
43
45
 
44
- # Select loader to use, available options are 'babel' (default) or 'swc'
45
- webpack_loader: 'swc'
46
+ # Select JavaScript transpiler to use, available options are 'babel' (default) or 'swc'
47
+ javascript_transpiler: 'swc'
46
48
  ```
47
49
 
48
50
  ## Usage
@@ -2,24 +2,10 @@
2
2
 
3
3
  ENV["RAILS_ENV"] ||= "development"
4
4
  ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", __FILE__)
5
+ ENV["APP_ROOT"] ||= File.expand_path("..", __dir__)
5
6
 
6
7
  require "bundler/setup"
7
- require "pathname"
8
8
  require "shakapacker"
9
+ require "shakapacker/runner"
9
10
 
10
- APP_ROOT = File.expand_path("..", __dir__)
11
- Dir.chdir(APP_ROOT) do
12
- config = Shakapacker::Configuration.new(
13
- root_path: Pathname.new(APP_ROOT),
14
- config_path: Pathname.new(File.join(APP_ROOT, "config/shakapacker.yml")),
15
- env: ENV["RAILS_ENV"] || ENV["NODE_ENV"] || "development"
16
- )
17
-
18
- if config.rspack?
19
- require "shakapacker/rspack_runner"
20
- Shakapacker::RspackRunner.run(ARGV)
21
- else
22
- require "shakapacker/webpack_runner"
23
- Shakapacker::WebpackRunner.run(ARGV)
24
- end
25
- end
11
+ Shakapacker::Runner.run(ARGV)
@@ -36,11 +36,12 @@ default: &default
36
36
  # Reload manifest.json on all requests so we reload latest compiled packs
37
37
  cache_manifest: false
38
38
 
39
- # Select loader to use, available options are 'babel' (default), 'swc' or 'esbuild'
40
- webpack_loader: 'babel'
39
+ # Select JavaScript transpiler to use, available options are 'babel' (default), 'swc' or 'esbuild'
40
+ javascript_transpiler: 'babel'
41
41
 
42
- # Select bundler to use, available options are 'webpack' (default) or 'rspack'
43
- bundler: 'webpack'
42
+ # Select assets bundler to use
43
+ # Available options: 'webpack' (default) or 'rspack'
44
+ assets_bundler: 'webpack'
44
45
 
45
46
  # Raises an error if there is a mismatch in the shakapacker gem and npm package being used
46
47
  ensure_consistent_versioning: true
@@ -88,18 +88,51 @@ class Shakapacker::Configuration
88
88
  fetch(:compiler_strategy)
89
89
  end
90
90
 
91
+ def assets_bundler
92
+ # Show deprecation warning if using old 'bundler' key
93
+ if data.has_key?(:bundler) && !data.has_key?(:assets_bundler)
94
+ $stderr.puts "⚠️ DEPRECATION WARNING: The 'bundler' configuration option is deprecated. Please use 'assets_bundler' instead to avoid confusion with Ruby's Bundler gem manager."
95
+ end
96
+ ENV["SHAKAPACKER_ASSETS_BUNDLER"] || fetch(:assets_bundler) || fetch(:bundler) || "webpack"
97
+ end
98
+
99
+ # Deprecated: Use assets_bundler instead
91
100
  def bundler
92
- fetch(:bundler) || "webpack"
101
+ assets_bundler
93
102
  end
94
103
 
95
104
  def rspack?
96
- bundler == "rspack"
105
+ assets_bundler == "rspack"
97
106
  end
98
107
 
99
108
  def webpack?
100
- bundler == "webpack"
109
+ assets_bundler == "webpack"
110
+ end
111
+
112
+ def javascript_transpiler
113
+ # Show deprecation warning if using old 'webpack_loader' key
114
+ if data.has_key?(:webpack_loader) && !data.has_key?(:javascript_transpiler)
115
+ $stderr.puts "⚠️ DEPRECATION WARNING: The 'webpack_loader' configuration option is deprecated. Please use 'javascript_transpiler' instead as it better reflects its purpose of configuring JavaScript transpilation regardless of the bundler used."
116
+ end
117
+
118
+ # Use explicit config if set, otherwise default based on bundler
119
+ fetch(:javascript_transpiler) || fetch(:webpack_loader) || default_javascript_transpiler
101
120
  end
102
121
 
122
+ # Deprecated: Use javascript_transpiler instead
123
+ def webpack_loader
124
+ javascript_transpiler
125
+ end
126
+
127
+ private
128
+
129
+ def default_javascript_transpiler
130
+ # RSpack has built-in SWC support, use it by default
131
+ rspack? ? "swc" : "babel"
132
+ end
133
+
134
+ public
135
+
103
136
  def fetch(key)
104
137
  data.fetch(key, defaults[key])
105
138
  end
@@ -7,6 +7,10 @@ require_relative "runner"
7
7
 
8
8
  module Shakapacker
9
9
  class DevServerRunner < Shakapacker::Runner
10
+ def self.run(argv)
11
+ new(argv).run
12
+ end
13
+
10
14
  def run
11
15
  load_config
12
16
  detect_unsupported_switches!
@@ -75,17 +79,16 @@ module Shakapacker
75
79
  env["NODE_OPTIONS"] = "#{env["NODE_OPTIONS"]} --inspect-brk --trace-warnings"
76
80
  end
77
81
 
78
- # Add bundler-specific flags and config
79
- bundler = get_bundler_type
80
- if bundler == "webpack"
81
- cmd += ["--config", @webpack_config]
82
+ # Add config file
83
+ cmd += ["--config", @webpack_config]
84
+
85
+ # Add assets bundler-specific flags
86
+ if webpack?
82
87
  cmd += ["--progress", "--color"] if @pretty
83
88
  # Default behavior of webpack-dev-server is @hot = true
84
89
  cmd += ["--hot", "only"] if @hot == "only"
85
90
  cmd += ["--no-hot"] if !@hot
86
- elsif bundler == "rspack"
87
- # Only add config for rspack if it's not a rspack-specific command
88
- cmd += ["--config", @webpack_config]
91
+ elsif rspack?
89
92
  # Rspack supports --hot but not --no-hot or --progress/--color
90
93
  cmd += ["--hot"] if @hot && @hot != false
91
94
  end
@@ -98,9 +101,16 @@ module Shakapacker
98
101
  end
99
102
 
100
103
  def build_cmd
101
- bundler = get_bundler_type
102
- command = bundler == "rspack" ? "rspack" : "webpack"
104
+ command = @config.rspack? ? "rspack" : "webpack"
103
105
  package_json.manager.native_exec_command(command, ["serve"])
104
106
  end
107
+
108
+ def webpack?
109
+ @config.webpack?
110
+ end
111
+
112
+ def rspack?
113
+ @config.rspack?
114
+ end
105
115
  end
106
116
  end
@@ -108,16 +108,17 @@ class Shakapacker::Manifest
108
108
  end
109
109
 
110
110
  def missing_file_from_manifest_error(bundle_name)
111
+ bundler_name = config.assets_bundler
111
112
  <<-MSG
112
113
  Shakapacker can't find #{bundle_name} in #{config.manifest_path}. Possible causes:
113
114
  1. You forgot to install javascript packages or are running an incompatible javascript runtime version
114
115
  2. Your app has code with a non-standard extension (like a `.jsx` file) but the extension is not in the `extensions` config in `config/shakapacker.yml`
115
116
  3. You have set compile: false (see `config/shakapacker.yml`) for this environment
116
117
  (unless you are using the `bin/shakapacker -w` or the `bin/shakapacker-dev-server`, in which case maybe you aren't running the dev server in the background?)
117
- 4. Your bundler (webpack/rspack) has not yet FINISHED running to reflect updates.
118
+ 4. Your #{bundler_name} has not yet FINISHED running to reflect updates.
118
119
  5. You have misconfigured Shakapacker's `config/shakapacker.yml` file.
119
- 6. Your bundler configuration is not creating a manifest with the expected structure.
120
- 7. There's a mismatch between your bundler choice (webpack vs rspack) and the manifest format.
120
+ 6. Your #{bundler_name} configuration is not creating a manifest with the expected structure.
121
+ 7. Ensure the 'assets_bundler' in config/shakapacker.yml is set correctly (currently: #{bundler_name}).
121
122
 
122
123
  Your manifest contains:
123
124
  #{JSON.pretty_generate(@data)}