shakapacker 8.3.0 → 9.0.0.beta.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.
- checksums.yaml +4 -4
- data/.github/STATUS.md +1 -0
- data/.github/workflows/dummy.yml +1 -1
- data/.github/workflows/generator.yml +4 -14
- data/.github/workflows/node.yml +1 -1
- data/CHANGELOG.md +17 -1
- data/Gemfile.lock +3 -3
- data/README.md +3 -3
- data/docs/css-modules-export-mode.md +288 -0
- data/docs/peer-dependencies.md +40 -0
- data/docs/react.md +2 -10
- data/docs/rspack.md +190 -0
- data/docs/subresource_integrity.md +54 -0
- data/docs/troubleshooting.md +5 -0
- data/lib/install/bin/shakapacker +14 -2
- data/lib/install/bin/shakapacker-rspack +13 -0
- data/lib/install/config/rspack/rspack.config.js +6 -0
- data/lib/install/config/shakapacker.yml +16 -3
- data/lib/install/package.json +30 -0
- data/lib/install/template.rb +13 -3
- data/lib/shakapacker/configuration.rb +16 -0
- data/lib/shakapacker/dev_server_runner.rb +17 -7
- data/lib/shakapacker/helper.rb +40 -4
- data/lib/shakapacker/manifest.rb +9 -3
- data/lib/shakapacker/rspack_runner.rb +57 -0
- data/lib/shakapacker/runner.rb +48 -2
- data/lib/shakapacker/version.rb +1 -1
- data/package/config.js +2 -0
- data/package/environments/base.js +16 -48
- data/package/environments/development.js +18 -3
- data/package/environments/production.js +24 -51
- data/package/environments/test.js +15 -1
- data/package/index.d.ts +14 -0
- data/package/index.js +4 -2
- data/package/optimization/rspack.js +25 -0
- data/package/optimization/webpack.js +49 -0
- data/package/plugins/rspack.js +104 -0
- data/package/plugins/webpack.js +62 -0
- data/package/rules/css.js +1 -1
- data/package/rules/file.js +11 -5
- data/package/rules/less.js +1 -1
- data/package/rules/raw.js +11 -1
- data/package/rules/rspack.js +96 -0
- data/package/rules/sass.js +6 -2
- data/package/rules/stylus.js +1 -1
- data/package/utils/getStyleRule.js +16 -3
- data/package/utils/requireOrError.js +15 -0
- data/package.json +19 -26
- data/test/package/config.test.js +40 -0
- data/test/package/environments/base.test.js +1 -1
- data/test/package/rules/{index.test.js → webpack.test.js} +1 -1
- data/yarn.lock +2146 -724
- metadata +22 -11
- /data/package/rules/{index.js → webpack.js} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d5eb8596c44c47d26f7d8954138ccff49880d0cfbbda9dd1669dd6d07e7c32f
|
4
|
+
data.tar.gz: 84aabd814e5ff1e723ff796ac4c02b37073c66f91695579dbdfe6850a44cfc6d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4158d767e170a0e18dcb1b9ad96558d2e13cd3ceed162c6e231d94cb1f99e8e62fe2da64be70fceeebf11ea1616af9c1da07c77469a9764e22ccaacb6c8da8d
|
7
|
+
data.tar.gz: aec89994b6c27b2109377959dd3ad1be1ca557bacadff21bf37df5c91760ac8f1e1e60eaf47f1be54997966c5b58090b70dd1154cba8431136836529bb8232ae
|
data/.github/STATUS.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# CI Status Update
|
data/.github/workflows/dummy.yml
CHANGED
@@ -20,8 +20,6 @@ jobs:
|
|
20
20
|
os: [ubuntu-latest]
|
21
21
|
ruby: ['2.7', '3.0', '3.1', '3.2', '3.3', '3.4']
|
22
22
|
gemfile:
|
23
|
-
- gemfiles/Gemfile-rails.6.0.x
|
24
|
-
- gemfiles/Gemfile-rails.6.1.x
|
25
23
|
- gemfiles/Gemfile-rails.7.0.x
|
26
24
|
- gemfiles/Gemfile-rails.7.1.x
|
27
25
|
- gemfiles/Gemfile-rails.7.2.x
|
@@ -38,20 +36,8 @@ jobs:
|
|
38
36
|
gemfile: gemfiles/Gemfile-rails.7.2.x
|
39
37
|
- ruby: '3.0'
|
40
38
|
gemfile: gemfiles/Gemfile-rails.8.0.x
|
41
|
-
- ruby: '3.1'
|
42
|
-
gemfile: gemfiles/Gemfile-rails.6.0.x
|
43
39
|
- ruby: '3.1'
|
44
40
|
gemfile: gemfiles/Gemfile-rails.8.0.x
|
45
|
-
- ruby: '3.2'
|
46
|
-
gemfile: gemfiles/Gemfile-rails.6.0.x
|
47
|
-
- ruby: '3.3'
|
48
|
-
gemfile: gemfiles/Gemfile-rails.6.0.x
|
49
|
-
- ruby: '3.3'
|
50
|
-
gemfile: gemfiles/Gemfile-rails.6.1.x
|
51
|
-
- ruby: '3.4'
|
52
|
-
gemfile: gemfiles/Gemfile-rails.6.0.x
|
53
|
-
- ruby: '3.4'
|
54
|
-
gemfile: gemfiles/Gemfile-rails.6.1.x
|
55
41
|
- ruby: '3.4'
|
56
42
|
gemfile: gemfiles/Gemfile-rails.7.0.x
|
57
43
|
|
@@ -67,4 +53,8 @@ jobs:
|
|
67
53
|
ruby-version: ${{ matrix.ruby }}
|
68
54
|
rubygems: latest
|
69
55
|
bundler-cache: true
|
56
|
+
- uses: actions/setup-node@v4
|
57
|
+
with:
|
58
|
+
node-version: 20.x
|
59
|
+
cache: yarn
|
70
60
|
- run: bundle exec rake run_spec:generator
|
data/.github/workflows/node.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -8,6 +8,21 @@
|
|
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.
|
13
|
+
|
14
|
+
## [v8.4.0] - September 8, 2025
|
15
|
+
### Added
|
16
|
+
|
17
|
+
* Support for subresource integrity. [PR 570](https://github.com/shakacode/shakapacker/pull/570) by [panagiotisplytas](https://github.com/panagiotisplytas)
|
18
|
+
|
19
|
+
### Fixed
|
20
|
+
|
21
|
+
- Install the latest major version of peer dependencies [PR 576](https://github.com/shakacode/shakapacker/pull/576) by [G-Rath](https://github.com/g-rath).
|
22
|
+
- Remove duplicate word in comment from generated `shakapacker.yml` config [PR 572](https://github.com/shakacode/shakapacker/pull/572) by [G-Rath](https://github.com/g-rath).
|
23
|
+
- fix: update webpack-dev-server to secure versions (^4.15.2 || ^5.2.2) [PR 585](https://github.com/shakacode/shakapacker/pull/585) by [justin808](https://github.com/justin808)
|
24
|
+
|
25
|
+
|
11
26
|
## [v8.3.0] - April 25, 2025
|
12
27
|
### Added
|
13
28
|
|
@@ -419,7 +434,8 @@ Note: [Rubygem is 6.3.0.pre.rc.1](https://rubygems.org/gems/shakapacker/versions
|
|
419
434
|
## v5.4.3 and prior changes from rails/webpacker
|
420
435
|
See [CHANGELOG.md in rails/webpacker (up to v5.4.3)](https://github.com/rails/webpacker/blob/master/CHANGELOG.md)
|
421
436
|
|
422
|
-
[Unreleased]: https://github.com/shakacode/shakapacker/compare/v8.
|
437
|
+
[Unreleased]: https://github.com/shakacode/shakapacker/compare/v8.4.0...main
|
438
|
+
[v8.4.0]: https://github.com/shakacode/shakapacker/compare/v8.3.0...v8.4.0
|
423
439
|
[v8.3.0]: https://github.com/shakacode/shakapacker/compare/v8.2.0...v8.3.0
|
424
440
|
[v8.2.0]: https://github.com/shakacode/shakapacker/compare/v8.1.0...v8.2.0
|
425
441
|
[v8.1.0]: https://github.com/shakacode/shakapacker/compare/v8.0.2...v8.1.0
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
shakapacker (
|
4
|
+
shakapacker (9.0.0.beta.0)
|
5
5
|
activesupport (>= 5.2)
|
6
6
|
package_json
|
7
7
|
rack-proxy (>= 0.6.1)
|
@@ -217,7 +217,7 @@ GEM
|
|
217
217
|
rubocop-ast (>= 1.31.1, < 2.0)
|
218
218
|
ruby-progressbar (1.13.0)
|
219
219
|
securerandom (0.3.1)
|
220
|
-
semantic_range (3.
|
220
|
+
semantic_range (3.1.0)
|
221
221
|
stringio (3.1.1)
|
222
222
|
thor (1.3.2)
|
223
223
|
timeout (0.4.1)
|
@@ -248,4 +248,4 @@ DEPENDENCIES
|
|
248
248
|
shakapacker!
|
249
249
|
|
250
250
|
BUNDLED WITH
|
251
|
-
2.5.
|
251
|
+
2.5.23
|
data/README.md
CHANGED
@@ -625,7 +625,7 @@ By default, you will find the Shakapacker preset in your `package.json`. Note, y
|
|
625
625
|
]
|
626
626
|
},
|
627
627
|
```
|
628
|
-
Optionally, you can change your Babel configuration by removing these lines in your `package.json` and adding [a Babel
|
628
|
+
Optionally, you can change your Babel configuration by removing these lines in your `package.json` and adding [a Babel configuration file](https://babeljs.io/docs/en/config-files) to your project. For an example of customization based on the original, see [Customizing Babel Config](./docs/customizing_babel_config.md).
|
629
629
|
|
630
630
|
|
631
631
|
### SWC configuration
|
@@ -1018,8 +1018,8 @@ The following companies support our Open Source projects, and ShakaCode uses the
|
|
1018
1018
|
<br />
|
1019
1019
|
<br />
|
1020
1020
|
|
1021
|
-
<a href="https://
|
1022
|
-
<img src="https://
|
1021
|
+
<a href="https://jb.gg/OpenSource" style="margin-right: 20px;">
|
1022
|
+
<img src="https://resources.jetbrains.com/storage/products/company/brand/logos/jetbrains.png" alt="JetBrains" height="120px">
|
1023
1023
|
</a>
|
1024
1024
|
<a href="https://scoutapp.com">
|
1025
1025
|
<picture>
|
@@ -0,0 +1,288 @@
|
|
1
|
+
# CSS Modules Export Mode
|
2
|
+
|
3
|
+
Most React guides and tutorials expect to import CSS Modules using a **default export object**:
|
4
|
+
|
5
|
+
```js
|
6
|
+
import styles from './Foo.module.css';
|
7
|
+
<button className={styles.bright} />
|
8
|
+
```
|
9
|
+
|
10
|
+
However, depending on configuration, `css-loader` may instead emit **named exports**:
|
11
|
+
|
12
|
+
```js
|
13
|
+
import { bright } from './Foo.module.css';
|
14
|
+
<button className={bright} />
|
15
|
+
```
|
16
|
+
|
17
|
+
By default, Shakapacker currently leaves `css-loader`'s `modules.namedExport` option unset, which leads to **named exports** being used in many cases. This can surprise developers expecting the `import styles ...` pattern.
|
18
|
+
|
19
|
+
---
|
20
|
+
|
21
|
+
## How to Configure Shakapacker for Default Exports
|
22
|
+
|
23
|
+
To force the more familiar `import styles ...` behavior (i.e. `namedExport: false`), update your webpack configuration as follows.
|
24
|
+
|
25
|
+
### Option 1: Update `config/webpack/commonWebpackConfig.js` (Recommended)
|
26
|
+
|
27
|
+
This approach modifies the common webpack configuration that applies to all environments:
|
28
|
+
|
29
|
+
```js
|
30
|
+
// config/webpack/commonWebpackConfig.js
|
31
|
+
const { generateWebpackConfig, merge } = require('shakapacker');
|
32
|
+
|
33
|
+
const baseClientWebpackConfig = generateWebpackConfig();
|
34
|
+
|
35
|
+
// Override CSS Modules configuration to use default exports instead of named exports
|
36
|
+
const overrideCssModulesConfig = (config) => {
|
37
|
+
// Find the CSS rule in the module rules
|
38
|
+
const cssRule = config.module.rules.find(rule =>
|
39
|
+
rule.test && rule.test.toString().includes('css')
|
40
|
+
);
|
41
|
+
|
42
|
+
if (cssRule && cssRule.use) {
|
43
|
+
const cssLoaderUse = cssRule.use.find(use =>
|
44
|
+
use.loader && use.loader.includes('css-loader')
|
45
|
+
);
|
46
|
+
|
47
|
+
if (cssLoaderUse && cssLoaderUse.options && cssLoaderUse.options.modules) {
|
48
|
+
// Set namedExport to false for default export behavior
|
49
|
+
cssLoaderUse.options.modules.namedExport = false;
|
50
|
+
cssLoaderUse.options.modules.exportLocalsConvention = 'asIs';
|
51
|
+
}
|
52
|
+
}
|
53
|
+
|
54
|
+
return config;
|
55
|
+
};
|
56
|
+
|
57
|
+
const commonOptions = {
|
58
|
+
resolve: {
|
59
|
+
extensions: ['.css', '.ts', '.tsx'],
|
60
|
+
},
|
61
|
+
};
|
62
|
+
|
63
|
+
const commonWebpackConfig = () => {
|
64
|
+
const config = merge({}, baseClientWebpackConfig, commonOptions);
|
65
|
+
return overrideCssModulesConfig(config);
|
66
|
+
};
|
67
|
+
|
68
|
+
module.exports = commonWebpackConfig;
|
69
|
+
```
|
70
|
+
|
71
|
+
### Option 2: Create `config/webpack/environment.js` (Alternative)
|
72
|
+
|
73
|
+
If you prefer using a separate environment file:
|
74
|
+
|
75
|
+
```js
|
76
|
+
// config/webpack/environment.js
|
77
|
+
const { environment } = require('@shakacode/shakapacker');
|
78
|
+
const getStyleRule = require('@shakacode/shakapacker/package/utils/getStyleRule');
|
79
|
+
|
80
|
+
// CSS Modules rule for *.module.css with default export enabled
|
81
|
+
const cssModulesRule = getStyleRule(/\.module\.css$/i, [], {
|
82
|
+
sourceMap: true,
|
83
|
+
importLoaders: 2,
|
84
|
+
modules: {
|
85
|
+
auto: true,
|
86
|
+
namedExport: false, // <-- key: enable default export object
|
87
|
+
exportLocalsConvention: 'asIs' // keep your class names as-is
|
88
|
+
}
|
89
|
+
});
|
90
|
+
|
91
|
+
// Ensure this rule wins for *.module.css
|
92
|
+
if (cssModulesRule) {
|
93
|
+
environment.loaders.prepend('css-modules', cssModulesRule);
|
94
|
+
}
|
95
|
+
|
96
|
+
// Plain CSS rule for non-modules
|
97
|
+
const plainCssRule = getStyleRule(/(?<!\.module)\.css$/i, [], {
|
98
|
+
sourceMap: true,
|
99
|
+
importLoaders: 2,
|
100
|
+
modules: false
|
101
|
+
});
|
102
|
+
|
103
|
+
if (plainCssRule) {
|
104
|
+
environment.loaders.append('css', plainCssRule);
|
105
|
+
}
|
106
|
+
|
107
|
+
module.exports = environment;
|
108
|
+
```
|
109
|
+
|
110
|
+
Then reference this in your environment-specific configs (development.js, production.js, etc.).
|
111
|
+
|
112
|
+
### Option 3: (Optional) Sass Modules
|
113
|
+
|
114
|
+
If you also use Sass modules, add similar configuration for SCSS files:
|
115
|
+
|
116
|
+
```js
|
117
|
+
// For Option 1 approach, extend the overrideCssModulesConfig function:
|
118
|
+
const overrideCssModulesConfig = (config) => {
|
119
|
+
// Handle both CSS and SCSS rules
|
120
|
+
const styleRules = config.module.rules.filter(rule =>
|
121
|
+
rule.test && (rule.test.toString().includes('css') || rule.test.toString().includes('scss'))
|
122
|
+
);
|
123
|
+
|
124
|
+
styleRules.forEach(rule => {
|
125
|
+
if (rule.use) {
|
126
|
+
const cssLoaderUse = rule.use.find(use =>
|
127
|
+
use.loader && use.loader.includes('css-loader')
|
128
|
+
);
|
129
|
+
|
130
|
+
if (cssLoaderUse && cssLoaderUse.options && cssLoaderUse.options.modules) {
|
131
|
+
cssLoaderUse.options.modules.namedExport = false;
|
132
|
+
cssLoaderUse.options.modules.exportLocalsConvention = 'asIs';
|
133
|
+
}
|
134
|
+
}
|
135
|
+
});
|
136
|
+
|
137
|
+
return config;
|
138
|
+
};
|
139
|
+
```
|
140
|
+
|
141
|
+
---
|
142
|
+
|
143
|
+
## Verifying the Configuration
|
144
|
+
|
145
|
+
### 1. Rebuild Your Packs
|
146
|
+
|
147
|
+
After making the configuration changes, rebuild your webpack bundles:
|
148
|
+
|
149
|
+
```bash
|
150
|
+
# For development
|
151
|
+
NODE_ENV=development bin/shakapacker
|
152
|
+
|
153
|
+
# Or with the dev server
|
154
|
+
bin/shakapacker-dev-server
|
155
|
+
```
|
156
|
+
|
157
|
+
### 2. Test in Your React Component
|
158
|
+
|
159
|
+
Update your component to use default imports:
|
160
|
+
|
161
|
+
```js
|
162
|
+
// Before (named exports)
|
163
|
+
import { bright } from './Foo.module.css';
|
164
|
+
|
165
|
+
// After (default export)
|
166
|
+
import styles from './Foo.module.css';
|
167
|
+
console.log(styles); // { bright: 'Foo_bright__hash' }
|
168
|
+
```
|
169
|
+
|
170
|
+
### 3. Debug Webpack Configuration (Optional)
|
171
|
+
|
172
|
+
To inspect the final webpack configuration:
|
173
|
+
|
174
|
+
```bash
|
175
|
+
NODE_ENV=development bin/shakapacker --profile --json > /tmp/webpack-stats.json
|
176
|
+
```
|
177
|
+
|
178
|
+
Then search for `css-loader` options in the generated JSON file.
|
179
|
+
|
180
|
+
---
|
181
|
+
|
182
|
+
## Benefits of Default Export Approach
|
183
|
+
|
184
|
+
1. **Better Developer Experience**: Matches most React tutorials and documentation
|
185
|
+
2. **IDE Support**: Better autocomplete and IntelliSense for CSS class names
|
186
|
+
3. **Type Safety**: Easier to add TypeScript definitions for CSS modules
|
187
|
+
4. **Consistency**: Aligns with common React ecosystem practices
|
188
|
+
|
189
|
+
---
|
190
|
+
|
191
|
+
## Migration Guide
|
192
|
+
|
193
|
+
If you're migrating from named exports to default exports:
|
194
|
+
|
195
|
+
### 1. Update Import Statements
|
196
|
+
|
197
|
+
```js
|
198
|
+
// Old (named exports)
|
199
|
+
import { bright, container, button } from './Component.module.css';
|
200
|
+
|
201
|
+
// New (default export)
|
202
|
+
import styles from './Component.module.css';
|
203
|
+
```
|
204
|
+
|
205
|
+
### 2. Update Class References
|
206
|
+
|
207
|
+
```js
|
208
|
+
// Old
|
209
|
+
<div className={container}>
|
210
|
+
<button className={button}>Click me</button>
|
211
|
+
<span className={bright}>Highlighted text</span>
|
212
|
+
</div>
|
213
|
+
|
214
|
+
// New
|
215
|
+
<div className={styles.container}>
|
216
|
+
<button className={styles.button}>Click me</button>
|
217
|
+
<span className={styles.bright}>Highlighted text</span>
|
218
|
+
</div>
|
219
|
+
```
|
220
|
+
|
221
|
+
### 3. Consider Using a Codemod
|
222
|
+
|
223
|
+
For large codebases, consider writing a codemod to automate the migration:
|
224
|
+
|
225
|
+
```bash
|
226
|
+
# Example using jscodeshift (pseudocode)
|
227
|
+
npx jscodeshift -t css-modules-migration.js src/
|
228
|
+
```
|
229
|
+
|
230
|
+
---
|
231
|
+
|
232
|
+
## Future Shakapacker Configuration
|
233
|
+
|
234
|
+
In future versions of Shakapacker, this configuration may be exposed via `config/shakapacker.yml`:
|
235
|
+
|
236
|
+
```yml
|
237
|
+
# Future configuration (not yet implemented)
|
238
|
+
css_modules:
|
239
|
+
# true -> named exports (import { bright } ...)
|
240
|
+
# false -> default export (import styles ...)
|
241
|
+
named_export: false
|
242
|
+
```
|
243
|
+
|
244
|
+
- **Current behavior:** Uses named exports when unset
|
245
|
+
- **Future behavior:** New app templates will default to `false`
|
246
|
+
- **Next major release:** The default will change to `false` when unset
|
247
|
+
|
248
|
+
---
|
249
|
+
|
250
|
+
## Troubleshooting
|
251
|
+
|
252
|
+
### CSS Classes Not Applying
|
253
|
+
|
254
|
+
If your CSS classes aren't applying after the change:
|
255
|
+
|
256
|
+
1. **Check import syntax**: Ensure you're using `import styles from ...`
|
257
|
+
2. **Verify class names**: Use `console.log(styles)` to see available classes
|
258
|
+
3. **Rebuild webpack**: Clear cache and rebuild: `rm -rf tmp/cache && bin/shakapacker`
|
259
|
+
|
260
|
+
### TypeScript Support
|
261
|
+
|
262
|
+
For TypeScript projects, create type definitions for your CSS modules:
|
263
|
+
|
264
|
+
```typescript
|
265
|
+
// src/types/css-modules.d.ts
|
266
|
+
declare module '*.module.css' {
|
267
|
+
const classes: { [key: string]: string };
|
268
|
+
export default classes;
|
269
|
+
}
|
270
|
+
```
|
271
|
+
|
272
|
+
### Build Performance
|
273
|
+
|
274
|
+
The configuration changes should not impact build performance significantly. If you experience issues:
|
275
|
+
|
276
|
+
1. Check webpack stats: `bin/shakapacker --profile`
|
277
|
+
2. Verify only necessary rules are being modified
|
278
|
+
3. Consider using webpack bundle analyzer for deeper insights
|
279
|
+
|
280
|
+
---
|
281
|
+
|
282
|
+
## Summary
|
283
|
+
|
284
|
+
- **Current default**: Named exports (`import { bright } ...`)
|
285
|
+
- **Recommended for DX**: Default export (`import styles ...`)
|
286
|
+
- **Implementation**: Override CSS loader configuration in `commonWebpackConfig.js`
|
287
|
+
- **Migration**: Update imports and class references systematically
|
288
|
+
- **Future**: Shakapacker will provide native configuration options
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# Shakapacker's Peer Dependencies
|
2
|
+
#### last updated for our 8.4.0 version
|
3
|
+
#### see lib/install/peerDependencies.json
|
4
|
+
|
5
|
+
To simplify peer dependencies while supporting both webpack & rspack, we decided to document the dependencies here instead of creating two separate npm packages.
|
6
|
+
|
7
|
+
## Essential for Rspack
|
8
|
+
```
|
9
|
+
"@rspack/cli": "^1.0.0",
|
10
|
+
"@rspack/core": "^1.0.0",
|
11
|
+
"rspack-manifest-plugin": "^5.0.0",
|
12
|
+
```
|
13
|
+
## Essential for Webpack
|
14
|
+
```
|
15
|
+
"mini-css-extract-plugin": "^2.0.0",
|
16
|
+
"terser-webpack-plugin": "^5.3.1",
|
17
|
+
"webpack": "^5.76.0",
|
18
|
+
"webpack-assets-manifest": "^5.0.6 || ^6.0.0",
|
19
|
+
"webpack-cli": "^4.9.2 || ^5.0.0 || ^6.0.0",
|
20
|
+
"webpack-dev-server": "^4.15.2 || ^5.2.2",
|
21
|
+
"webpack-merge": "^5.8.0 || ^6.0.0",
|
22
|
+
"webpack-subresource-integrity": "^5.1.0"
|
23
|
+
```
|
24
|
+
|
25
|
+
## Highly recommended
|
26
|
+
```
|
27
|
+
"compression-webpack-plugin": "^9.0.0 || ^10.0.0|| ^11.0.0",
|
28
|
+
"css-loader": "^6.0.0 || ^7.0.0",
|
29
|
+
"sass-loader": "^13.0.0 || ^14.0.0 || ^15.0.0 || ^16.0.0",
|
30
|
+
"style-loader": "^3.0.0 || ^4.0.0",
|
31
|
+
```
|
32
|
+
|
33
|
+
## Babel (avoid if at all possible)
|
34
|
+
```
|
35
|
+
"@babel/core": "^7.17.9",
|
36
|
+
"@babel/plugin-transform-runtime": "^7.17.0",
|
37
|
+
"@babel/preset-env": "^7.16.11",
|
38
|
+
"@babel/runtime": "^7.17.9",
|
39
|
+
"babel-loader": "^8.2.4 || ^9.0.0 || ^10.0.0",
|
40
|
+
```
|
data/docs/react.md
CHANGED
@@ -61,11 +61,7 @@ const webpackConfig = generateWebpackConfig();
|
|
61
61
|
|
62
62
|
if (isDevelopment && inliningCss) {
|
63
63
|
webpackConfig.plugins.push(
|
64
|
-
new ReactRefreshWebpackPlugin(
|
65
|
-
overlay: {
|
66
|
-
sockPort: webpackConfig.devServer.port,
|
67
|
-
},
|
68
|
-
})
|
64
|
+
new ReactRefreshWebpackPlugin()
|
69
65
|
);
|
70
66
|
}
|
71
67
|
|
@@ -201,11 +197,7 @@ const webpackConfig = generateWebpackConfig();
|
|
201
197
|
|
202
198
|
if (isDevelopment && inliningCss) {
|
203
199
|
webpackConfig.plugins.push(
|
204
|
-
new ReactRefreshWebpackPlugin(
|
205
|
-
overlay: {
|
206
|
-
sockPort: webpackConfig.devServer.port,
|
207
|
-
},
|
208
|
-
})
|
200
|
+
new ReactRefreshWebpackPlugin()
|
209
201
|
);
|
210
202
|
}
|
211
203
|
|
data/docs/rspack.md
ADDED
@@ -0,0 +1,190 @@
|
|
1
|
+
# Rspack Integration
|
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.
|
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
|
+
bundler: 'rspack' # Change from 'webpack' to 'rspack'
|
29
|
+
```
|
30
|
+
|
31
|
+
## Configuration
|
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 `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 bundler: 'rspack')
|
123
|
+
./bin/shakapacker
|
124
|
+
|
125
|
+
# Development server (automatically uses rspack when 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
|
+
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/)
|