shakapacker 8.4.0 → 9.0.0

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 (166) hide show
  1. checksums.yaml +4 -4
  2. data/.eslintignore +1 -0
  3. data/.eslintrc.fast.js +40 -0
  4. data/.eslintrc.js +48 -0
  5. data/.github/STATUS.md +1 -0
  6. data/.github/workflows/claude-code-review.yml +54 -0
  7. data/.github/workflows/claude.yml +50 -0
  8. data/.github/workflows/dummy.yml +8 -4
  9. data/.github/workflows/generator.yml +17 -14
  10. data/.github/workflows/node.yml +23 -1
  11. data/.github/workflows/ruby.yml +11 -0
  12. data/.github/workflows/test-bundlers.yml +170 -0
  13. data/.gitignore +17 -0
  14. data/.husky/pre-commit +2 -0
  15. data/.npmignore +56 -0
  16. data/.prettierignore +3 -0
  17. data/.rubocop.yml +1 -0
  18. data/.yalcignore +26 -0
  19. data/CHANGELOG.md +156 -18
  20. data/CLAUDE.md +29 -0
  21. data/CONTRIBUTING.md +138 -20
  22. data/Gemfile.lock +3 -3
  23. data/README.md +130 -5
  24. data/Rakefile +39 -4
  25. data/TODO.md +50 -0
  26. data/TODO_v9.md +87 -0
  27. data/conductor-setup.sh +70 -0
  28. data/conductor.json +7 -0
  29. data/docs/cdn_setup.md +379 -0
  30. data/docs/css-modules-export-mode.md +512 -0
  31. data/docs/deployment.md +10 -1
  32. data/docs/optional-peer-dependencies.md +198 -0
  33. data/docs/peer-dependencies.md +60 -0
  34. data/docs/rspack.md +190 -0
  35. data/docs/rspack_migration_guide.md +202 -0
  36. data/docs/transpiler-migration.md +188 -0
  37. data/docs/transpiler-performance.md +179 -0
  38. data/docs/troubleshooting.md +5 -0
  39. data/docs/typescript-migration.md +378 -0
  40. data/docs/typescript.md +99 -0
  41. data/docs/using_esbuild_loader.md +3 -3
  42. data/docs/using_swc_loader.md +5 -3
  43. data/docs/v6_upgrade.md +10 -0
  44. data/docs/v9_upgrade.md +413 -0
  45. data/lib/install/bin/shakapacker +3 -5
  46. data/lib/install/config/rspack/rspack.config.js +6 -0
  47. data/lib/install/config/rspack/rspack.config.ts +7 -0
  48. data/lib/install/config/shakapacker.yml +12 -2
  49. data/lib/install/config/webpack/webpack.config.ts +7 -0
  50. data/lib/install/package.json +38 -0
  51. data/lib/install/template.rb +194 -44
  52. data/lib/shakapacker/configuration.rb +141 -0
  53. data/lib/shakapacker/dev_server_runner.rb +25 -5
  54. data/lib/shakapacker/doctor.rb +844 -0
  55. data/lib/shakapacker/manifest.rb +4 -2
  56. data/lib/shakapacker/rspack_runner.rb +19 -0
  57. data/lib/shakapacker/runner.rb +144 -4
  58. data/lib/shakapacker/swc_migrator.rb +376 -0
  59. data/lib/shakapacker/utils/manager.rb +2 -0
  60. data/lib/shakapacker/version.rb +1 -1
  61. data/lib/shakapacker/version_checker.rb +1 -1
  62. data/lib/shakapacker/webpack_runner.rb +4 -42
  63. data/lib/shakapacker.rb +2 -1
  64. data/lib/tasks/shakapacker/doctor.rake +8 -0
  65. data/lib/tasks/shakapacker/install.rake +12 -2
  66. data/lib/tasks/shakapacker/migrate_to_swc.rake +13 -0
  67. data/lib/tasks/shakapacker.rake +1 -0
  68. data/package/.npmignore +4 -0
  69. data/package/babel/preset.ts +56 -0
  70. data/package/config.ts +175 -0
  71. data/package/{dev_server.js → dev_server.ts} +8 -5
  72. data/package/env.ts +92 -0
  73. data/package/environments/base.ts +138 -0
  74. data/package/environments/development.ts +90 -0
  75. data/package/environments/production.ts +80 -0
  76. data/package/environments/test.ts +53 -0
  77. data/package/environments/types.ts +90 -0
  78. data/package/esbuild/index.ts +42 -0
  79. data/package/index.d.ts +3 -97
  80. data/package/index.ts +52 -0
  81. data/package/loaders.d.ts +28 -0
  82. data/package/optimization/rspack.ts +36 -0
  83. data/package/optimization/webpack.ts +57 -0
  84. data/package/plugins/rspack.ts +103 -0
  85. data/package/plugins/webpack.ts +62 -0
  86. data/package/rspack/index.ts +64 -0
  87. data/package/rules/{babel.js → babel.ts} +2 -2
  88. data/package/rules/{coffee.js → coffee.ts} +1 -1
  89. data/package/rules/css.ts +3 -0
  90. data/package/rules/{erb.js → erb.ts} +1 -1
  91. data/package/rules/esbuild.ts +10 -0
  92. data/package/rules/file.ts +40 -0
  93. data/package/rules/{jscommon.js → jscommon.ts} +4 -4
  94. data/package/rules/{less.js → less.ts} +4 -4
  95. data/package/rules/raw.ts +25 -0
  96. data/package/rules/rspack.ts +176 -0
  97. data/package/rules/{sass.js → sass.ts} +7 -3
  98. data/package/rules/{stylus.js → stylus.ts} +4 -8
  99. data/package/rules/swc.ts +10 -0
  100. data/package/rules/{index.js → webpack.ts} +1 -1
  101. data/package/swc/index.ts +54 -0
  102. data/package/types/README.md +87 -0
  103. data/package/types/index.ts +60 -0
  104. data/package/types.ts +108 -0
  105. data/package/utils/configPath.ts +6 -0
  106. data/package/utils/debug.ts +49 -0
  107. data/package/utils/defaultConfigPath.ts +4 -0
  108. data/package/utils/errorCodes.ts +219 -0
  109. data/package/utils/errorHelpers.ts +143 -0
  110. data/package/utils/getStyleRule.ts +64 -0
  111. data/package/utils/helpers.ts +85 -0
  112. data/package/utils/{inliningCss.js → inliningCss.ts} +3 -3
  113. data/package/utils/pathValidation.ts +139 -0
  114. data/package/utils/requireOrError.ts +15 -0
  115. data/package/utils/snakeToCamelCase.ts +5 -0
  116. data/package/utils/typeGuards.ts +342 -0
  117. data/package/utils/validateDependencies.ts +61 -0
  118. data/package/webpack-types.d.ts +33 -0
  119. data/package/webpackDevServerConfig.ts +117 -0
  120. data/package.json +134 -9
  121. data/scripts/remove-use-strict.js +45 -0
  122. data/scripts/type-check-no-emit.js +27 -0
  123. data/test/package/config.test.js +3 -0
  124. data/test/package/env.test.js +42 -7
  125. data/test/package/environments/base.test.js +5 -1
  126. data/test/package/rules/babel.test.js +16 -0
  127. data/test/package/rules/esbuild.test.js +1 -1
  128. data/test/package/rules/raw.test.js +40 -7
  129. data/test/package/rules/swc.test.js +1 -1
  130. data/test/package/rules/webpack.test.js +35 -0
  131. data/test/package/staging.test.js +4 -3
  132. data/test/package/transpiler-defaults.test.js +127 -0
  133. data/test/peer-dependencies.sh +85 -0
  134. data/test/scripts/remove-use-strict.test.js +125 -0
  135. data/test/typescript/build.test.js +118 -0
  136. data/test/typescript/environments.test.js +107 -0
  137. data/test/typescript/pathValidation.test.js +142 -0
  138. data/test/typescript/securityValidation.test.js +182 -0
  139. data/tools/README.md +124 -0
  140. data/tools/css-modules-v9-codemod.js +179 -0
  141. data/tsconfig.eslint.json +16 -0
  142. data/tsconfig.json +38 -0
  143. data/yarn.lock +2704 -767
  144. metadata +111 -41
  145. data/package/babel/preset.js +0 -48
  146. data/package/config.js +0 -56
  147. data/package/env.js +0 -48
  148. data/package/environments/base.js +0 -171
  149. data/package/environments/development.js +0 -13
  150. data/package/environments/production.js +0 -88
  151. data/package/environments/test.js +0 -3
  152. data/package/esbuild/index.js +0 -40
  153. data/package/index.js +0 -40
  154. data/package/rules/css.js +0 -3
  155. data/package/rules/esbuild.js +0 -10
  156. data/package/rules/file.js +0 -29
  157. data/package/rules/raw.js +0 -5
  158. data/package/rules/swc.js +0 -10
  159. data/package/swc/index.js +0 -50
  160. data/package/utils/configPath.js +0 -4
  161. data/package/utils/defaultConfigPath.js +0 -2
  162. data/package/utils/getStyleRule.js +0 -40
  163. data/package/utils/helpers.js +0 -62
  164. data/package/utils/snakeToCamelCase.js +0 -5
  165. data/package/webpackDevServerConfig.js +0 -71
  166. data/test/package/rules/index.test.js +0 -16
@@ -0,0 +1,198 @@
1
+ # Optional Peer Dependencies in Shakapacker
2
+
3
+ ## Overview
4
+
5
+ As of Shakapacker v9, all peer dependencies are marked as optional via `peerDependenciesMeta`. This design provides maximum flexibility while maintaining clear version constraints.
6
+
7
+ ## Key Benefits
8
+
9
+ 1. **No Installation Warnings** - Package managers (npm, yarn, pnpm) won't warn about missing peer dependencies
10
+ 2. **Install Only What You Need** - Users only install packages for their chosen configuration
11
+ 3. **Clear Version Constraints** - When packages are installed, version compatibility is still enforced
12
+ 4. **Smaller Node Modules** - Reduced disk usage by not installing unnecessary packages
13
+
14
+ ## Implementation Details
15
+
16
+ ### Package.json Structure
17
+
18
+ ```json
19
+ {
20
+ "dependencies": {
21
+ "js-yaml": "^4.1.0",
22
+ "path-complete-extname": "^1.0.0",
23
+ "webpack-merge": "^5.8.0" // Direct dependency - always available
24
+ },
25
+ "peerDependencies": {
26
+ "webpack": "^5.76.0",
27
+ "@rspack/core": "^1.0.0",
28
+ // ... all build tools
29
+ },
30
+ "peerDependenciesMeta": {
31
+ "webpack": { "optional": true },
32
+ "@rspack/core": { "optional": true },
33
+ // ... all marked as optional
34
+ }
35
+ }
36
+ ```
37
+
38
+ ### TypeScript Type-Only Imports
39
+
40
+ To prevent runtime errors when optional packages aren't installed, all webpack imports use type-only syntax:
41
+
42
+ ```typescript
43
+ // @ts-ignore: webpack is an optional peer dependency (using type-only import)
44
+ import type { Configuration } from "webpack"
45
+ ```
46
+
47
+ Type-only imports are erased during compilation and don't trigger module resolution at runtime.
48
+
49
+ ## Configuration Examples
50
+
51
+ ### Webpack + Babel (Traditional)
52
+ ```json
53
+ {
54
+ "dependencies": {
55
+ "shakapacker": "^9.0.0",
56
+ "webpack": "^5.76.0",
57
+ "webpack-cli": "^5.0.0",
58
+ "babel-loader": "^8.2.4",
59
+ "@babel/core": "^7.17.9",
60
+ "@babel/preset-env": "^7.16.11"
61
+ }
62
+ }
63
+ ```
64
+
65
+ ### Webpack + SWC (20x Faster)
66
+ ```json
67
+ {
68
+ "dependencies": {
69
+ "shakapacker": "^9.0.0",
70
+ "webpack": "^5.76.0",
71
+ "webpack-cli": "^5.0.0",
72
+ "@swc/core": "^1.3.0",
73
+ "swc-loader": "^0.2.0"
74
+ }
75
+ }
76
+ ```
77
+
78
+ ### Rspack + SWC (10x Faster Bundling)
79
+ ```json
80
+ {
81
+ "dependencies": {
82
+ "shakapacker": "^9.0.0",
83
+ "@rspack/core": "^1.0.0",
84
+ "@rspack/cli": "^1.0.0",
85
+ "rspack-manifest-plugin": "^5.0.0"
86
+ }
87
+ }
88
+ ```
89
+
90
+ ## Migration Guide
91
+
92
+ ### From v8 to v9
93
+
94
+ If upgrading from Shakapacker v8:
95
+
96
+ 1. **No action required** - Your existing dependencies will continue to work
97
+ 2. **No more warnings** - Peer dependency warnings will disappear after upgrading
98
+ 3. **Option to optimize** - You can now remove unused dependencies (e.g., remove Babel if using SWC)
99
+
100
+ ### New Installations
101
+
102
+ The installer (`rails shakapacker:install`) only adds packages needed for your configuration:
103
+ - Detects your preferred bundler (webpack/rspack)
104
+ - Installs appropriate JavaScript transpiler (babel/swc/esbuild)
105
+ - Adds only required dependencies
106
+
107
+ ## Version Constraints
108
+
109
+ Version ranges are carefully chosen for compatibility:
110
+
111
+ - **Broader ranges for peer deps** - Allows flexibility (e.g., `^5.76.0` for webpack)
112
+ - **Specific versions in devDeps** - Ensures testing against known versions
113
+ - **Forward compatibility** - Ranges include future minor versions (e.g., `^5.0.0 || ^6.0.0`)
114
+
115
+ ## Testing
116
+
117
+ ### Installation Tests
118
+
119
+ Test that no warnings appear during installation:
120
+
121
+ ```bash
122
+ # Test script available at test/peer-dependencies.sh
123
+ ./test/peer-dependencies.sh
124
+ ```
125
+
126
+ ### Runtime Tests
127
+
128
+ Verify Shakapacker loads without optional dependencies:
129
+
130
+ ```javascript
131
+ // This works even without webpack installed (when using rspack)
132
+ const shakapacker = require('shakapacker');
133
+ ```
134
+
135
+ ### CI Integration
136
+
137
+ The test suite includes:
138
+ - `spec/shakapacker/optional_dependencies_spec.rb` - Package.json structure validation
139
+ - `spec/shakapacker/doctor_optional_peer_spec.rb` - Doctor command validation
140
+ - `test/peer-dependencies.sh` - Installation warning tests
141
+
142
+ ## Troubleshooting
143
+
144
+ ### Still seeing peer dependency warnings?
145
+
146
+ 1. Ensure you're using Shakapacker v9.0.0 or later
147
+ 2. Clear your package manager cache:
148
+ - npm: `npm cache clean --force`
149
+ - yarn: `yarn cache clean`
150
+ - pnpm: `pnpm store prune`
151
+ 3. Reinstall dependencies
152
+
153
+ ### Module not found errors?
154
+
155
+ 1. Check you've installed required dependencies for your configuration
156
+ 2. Refer to the configuration examples above
157
+ 3. Run `rails shakapacker:doctor` for diagnostics
158
+
159
+ ### TypeScript errors?
160
+
161
+ The `@ts-ignore` comments are intentional and necessary for optional dependencies.
162
+ They prevent TypeScript errors when optional packages aren't installed.
163
+
164
+ ## Contributing
165
+
166
+ When adding new dependencies:
167
+
168
+ 1. Add to `peerDependencies` with appropriate version range
169
+ 2. Mark as optional in `peerDependenciesMeta`
170
+ 3. Use type-only imports in TypeScript: `import type { ... }`
171
+ 4. Test with all package managers (npm, yarn, pnpm)
172
+ 5. Update this documentation if needed
173
+
174
+ ## Design Rationale
175
+
176
+ This approach balances several concerns:
177
+
178
+ 1. **User Experience** - No confusing warnings during installation
179
+ 2. **Flexibility** - Support multiple configurations without forcing unnecessary installs
180
+ 3. **Compatibility** - Maintain version constraints for safety
181
+ 4. **Performance** - Reduce installation time and disk usage
182
+ 5. **Type Safety** - TypeScript support without runtime dependencies
183
+
184
+ ## Future Improvements
185
+
186
+ Potential enhancements for future versions:
187
+
188
+ 1. **Conditional exports** - Use package.json exports field for better tree-shaking
189
+ 2. **Dynamic imports** - Load bundler-specific code only when needed
190
+ 3. **Doctor updates** - Enhance doctor command to better understand optional dependencies
191
+ 4. **Automated testing** - Add CI jobs testing each configuration combination
192
+
193
+ ## References
194
+
195
+ - [npm: peerDependenciesMeta](https://docs.npmjs.com/cli/v8/configuring-npm/package-json#peerdependenciesmeta)
196
+ - [TypeScript: Type-Only Imports](https://www.typescriptlang.org/docs/handbook/modules.html#type-only-imports-and-exports)
197
+ - [Shakapacker Issue #565](https://github.com/shakacode/shakapacker/issues/565)
198
+ - [Pull Request #615](https://github.com/shakacode/shakapacker/pull/615)
@@ -0,0 +1,60 @@
1
+ # Shakapacker's Peer Dependencies
2
+ ## Last updated for our 9.0.0 version — see lib/install/package.json
3
+
4
+ To simplify peer dependencies while supporting both webpack & rspack, we decided to document the dependencies here instead of creating two separate npm packages.
5
+
6
+ **Important Note**: Starting with v9, Babel dependencies are no longer included as peer dependencies. They will be installed automatically only if you're using Babel as your JavaScript transpiler.
7
+
8
+ ## Essential for Rspack
9
+ ```
10
+ "@rspack/cli": "^1.0.0",
11
+ "@rspack/core": "^1.0.0",
12
+ "rspack-manifest-plugin": "^5.0.0",
13
+ ```
14
+ ## Essential for Webpack
15
+ ```
16
+ "mini-css-extract-plugin": "^2.0.0",
17
+ "terser-webpack-plugin": "^5.3.1",
18
+ "webpack": "^5.76.0",
19
+ "webpack-assets-manifest": "^5.0.6 || ^6.0.0",
20
+ "webpack-cli": "^4.9.2 || ^5.0.0 || ^6.0.0",
21
+ "webpack-dev-server": "^4.15.2 || ^5.2.2",
22
+ "webpack-merge": "^5.8.0 || ^6.0.0",
23
+ "webpack-subresource-integrity": "^5.1.0"
24
+ ```
25
+
26
+ ## Highly recommended
27
+ ```
28
+ "compression-webpack-plugin": "^9.0.0 || ^10.0.0|| ^11.0.0",
29
+ "css-loader": "^6.0.0 || ^7.0.0",
30
+ "sass-loader": "^13.0.0 || ^14.0.0 || ^15.0.0 || ^16.0.0",
31
+ "style-loader": "^3.0.0 || ^4.0.0",
32
+ ```
33
+
34
+ ## Optional JavaScript Transpilers
35
+
36
+ ### Babel (installed automatically when `javascript_transpiler: 'babel'`)
37
+ ```
38
+ "@babel/core": "^7.17.9",
39
+ "@babel/plugin-transform-runtime": "^7.17.0",
40
+ "@babel/preset-env": "^7.16.11",
41
+ "@babel/runtime": "^7.17.9",
42
+ "babel-loader": "^8.2.4 || ^9.0.0 || ^10.0.0",
43
+ ```
44
+ Note: These dependencies are only installed if you're using Babel as your JavaScript transpiler. Consider using SWC or esbuild for better performance.
45
+
46
+ ### SWC (default - 20x faster than Babel)
47
+ ```
48
+ "@swc/core": "latest",
49
+ "swc-loader": "latest"
50
+ ```
51
+ - **For webpack**: Installed automatically when using default configuration
52
+ - **For rspack**: Built-in, no additional installation needed (rspack includes SWC natively)
53
+ - Manual install: `npm install @swc/core swc-loader`
54
+
55
+ ### esbuild
56
+ ```
57
+ "esbuild": "latest",
58
+ "esbuild-loader": "latest"
59
+ ```
60
+ Install manually with: `npm install esbuild esbuild-loader`
data/docs/rspack.md ADDED
@@ -0,0 +1,190 @@
1
+ # Rspack Integration
2
+
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
+
5
+ ## Installation
6
+
7
+ First, install the required Rspack dependencies:
8
+
9
+ ```bash
10
+ npm install @rspack/core @rspack/cli -D
11
+ # or
12
+ yarn add @rspack/core @rspack/cli -D
13
+ # or
14
+ pnpm add @rspack/core @rspack/cli -D
15
+ # or
16
+ bun add @rspack/core @rspack/cli -D
17
+ ```
18
+
19
+ Note: These packages are already listed as optional peer dependencies in Shakapacker, so you may see warnings if they're not installed.
20
+
21
+ ## Configuration
22
+
23
+ To enable Rspack, update your `config/shakapacker.yml`:
24
+
25
+ ```yaml
26
+ default: &default
27
+ # ... other config options
28
+ assets_bundler: 'rspack' # Change from 'webpack' to 'rspack'
29
+ ```
30
+
31
+ ### Configuration Files
32
+
33
+ Rspack uses its own configuration directory to keep things organized. Create your Rspack configuration file at `config/rspack/rspack.config.js`:
34
+
35
+ ```javascript
36
+ const { generateRspackConfig } = require('shakapacker/rspack')
37
+
38
+ module.exports = generateRspackConfig()
39
+ ```
40
+
41
+ ### Custom Configuration
42
+
43
+ If you need to customize your Rspack configuration:
44
+
45
+ ```javascript
46
+ const { generateRspackConfig } = require('shakapacker/rspack')
47
+
48
+ const rspackConfig = generateRspackConfig({
49
+ plugins: [
50
+ new SomeRspackCompatiblePlugin()
51
+ ],
52
+ resolve: {
53
+ extensions: ['.ts', '.tsx', '.js', '.jsx']
54
+ }
55
+ })
56
+
57
+ module.exports = rspackConfig
58
+ ```
59
+
60
+ ### Migration from Webpack Config
61
+
62
+ If you have an existing `config/webpack/webpack.config.js`, you can migrate it to `config/rspack/rspack.config.js`:
63
+
64
+ **Old (webpack.config.js):**
65
+ ```javascript
66
+ const { generateWebpackConfig } = require('shakapacker')
67
+ module.exports = generateWebpackConfig()
68
+ ```
69
+
70
+ **New (rspack.config.js):**
71
+ ```javascript
72
+ const { generateRspackConfig } = require('shakapacker/rspack')
73
+ module.exports = generateRspackConfig()
74
+ ```
75
+
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
+
78
+ ## Key Differences from Webpack
79
+
80
+ ### Built-in Loaders
81
+
82
+ Rspack has built-in loaders that are faster than their webpack counterparts:
83
+
84
+ - **JavaScript/TypeScript**: Uses `builtin:swc-loader` instead of `babel-loader`
85
+ - **CSS Extraction**: Uses `rspack.CssExtractRspackPlugin` instead of `mini-css-extract-plugin`
86
+ - **Asset Handling**: Uses built-in asset modules instead of `file-loader`/`url-loader`
87
+
88
+ ### Plugin Compatibility
89
+
90
+ Most webpack plugins work with Rspack, but some have Rspack-specific alternatives:
91
+
92
+ | Webpack Plugin | Rspack Alternative | Status |
93
+ |---|---|---|
94
+ | `mini-css-extract-plugin` | `rspack.CssExtractRspackPlugin` | Built-in |
95
+ | `copy-webpack-plugin` | `rspack.CopyRspackPlugin` | Built-in |
96
+ | `terser-webpack-plugin` | `rspack.SwcJsMinimizerRspackPlugin` | Built-in |
97
+
98
+ ### Minification
99
+
100
+ Rspack uses SWC for minification by default, which is significantly faster than Terser:
101
+
102
+ ```javascript
103
+ optimization: {
104
+ minimize: true,
105
+ minimizer: [
106
+ new rspack.SwcJsMinimizerRspackPlugin(),
107
+ new rspack.SwcCssMinimizerRspackPlugin()
108
+ ]
109
+ }
110
+ ```
111
+
112
+ ## Limitations
113
+
114
+ - **CoffeeScript**: Not supported with Rspack
115
+ - **Some Webpack Plugins**: May not be compatible; check Rspack documentation
116
+
117
+ ## Commands
118
+
119
+ All existing Shakapacker commands work the same way and automatically use Rspack when configured:
120
+
121
+ ```bash
122
+ # Build (automatically uses rspack when assets_bundler: 'rspack')
123
+ ./bin/shakapacker
124
+
125
+ # Development server (automatically uses rspack when assets_bundler: 'rspack')
126
+ ./bin/shakapacker-dev-server
127
+
128
+ # Watch mode
129
+ ./bin/shakapacker --watch
130
+ ```
131
+
132
+ The same dev server configuration in `shakapacker.yml` applies to both webpack and rspack.
133
+
134
+ ## Performance Benefits
135
+
136
+ Rspack typically provides:
137
+
138
+ - **2-10x faster** cold builds
139
+ - **5-20x faster** incremental builds
140
+ - **Faster HMR** (Hot Module Replacement)
141
+ - **Lower memory usage**
142
+
143
+ ## Migration Checklist
144
+
145
+ 1. **Install Rspack dependencies:**
146
+ ```bash
147
+ npm install @rspack/core @rspack/cli -D
148
+ ```
149
+
150
+ 2. **Update configuration:**
151
+ ```yaml
152
+ # config/shakapacker.yml
153
+ default: &default
154
+ assets_bundler: 'rspack'
155
+ ```
156
+
157
+ 3. **Create Rspack config:**
158
+ ```javascript
159
+ // config/rspack/rspack.config.js
160
+ const { generateRspackConfig } = require('shakapacker/rspack')
161
+ module.exports = generateRspackConfig()
162
+ ```
163
+
164
+ 4. **Remove CoffeeScript files** (if any) - not supported by Rspack
165
+
166
+ 5. **Test your application** - same commands work automatically
167
+
168
+ ## Troubleshooting
169
+
170
+ ### Configuration Issues
171
+
172
+ If you encounter configuration issues:
173
+
174
+ 1. Check that all plugins are Rspack-compatible
175
+ 2. Verify custom loaders work with Rspack
176
+ 3. Review the [Rspack migration guide](https://rspack.rs/guide/migration/webpack)
177
+
178
+ ### Performance Issues
179
+
180
+ If builds are unexpectedly slow:
181
+
182
+ 1. Ensure you're using built-in Rspack loaders
183
+ 2. Check for webpack-specific plugins that should be replaced
184
+ 3. Review your asset optimization settings
185
+
186
+ ## Further Reading
187
+
188
+ - [Rspack Official Documentation](https://rspack.rs)
189
+ - [Rspack Migration Guide](https://rspack.rs/guide/migration/webpack)
190
+ - [Rspack Plugins](https://rspack.rs/plugins/webpack/)
@@ -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)