shakapacker 8.4.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.
- checksums.yaml +4 -4
- data/.github/STATUS.md +1 -0
- data/.github/workflows/claude-code-review.yml +54 -0
- data/.github/workflows/claude.yml +50 -0
- data/.github/workflows/dummy.yml +1 -1
- data/.github/workflows/generator.yml +4 -14
- data/.github/workflows/node.yml +1 -1
- data/.rubocop.yml +1 -0
- data/CHANGELOG.md +8 -2
- data/Gemfile.lock +3 -3
- data/README.md +2 -2
- data/Rakefile +18 -1
- data/docs/css-modules-export-mode.md +288 -0
- data/docs/peer-dependencies.md +40 -0
- data/docs/rspack.md +190 -0
- data/docs/rspack_migration_guide.md +202 -0
- data/docs/troubleshooting.md +5 -0
- data/docs/using_esbuild_loader.md +3 -3
- data/docs/using_swc_loader.md +5 -3
- data/lib/install/bin/shakapacker +3 -5
- data/lib/install/config/rspack/rspack.config.js +6 -0
- data/lib/install/config/shakapacker.yml +6 -2
- data/lib/install/package.json +30 -0
- data/lib/install/template.rb +12 -2
- data/lib/shakapacker/configuration.rb +45 -0
- data/lib/shakapacker/dev_server_runner.rb +25 -5
- data/lib/shakapacker/manifest.rb +4 -2
- data/lib/shakapacker/rspack_runner.rb +19 -0
- data/lib/shakapacker/runner.rb +144 -4
- data/lib/shakapacker/utils/manager.rb +2 -0
- data/lib/shakapacker/version.rb +1 -1
- data/lib/shakapacker/version_checker.rb +1 -1
- data/lib/shakapacker/webpack_runner.rb +4 -42
- data/lib/tasks/shakapacker/install.rake +6 -2
- data/package/config.js +24 -0
- data/package/environments/base.js +20 -65
- data/package/environments/development.js +60 -5
- data/package/environments/production.js +29 -51
- data/package/environments/test.js +17 -1
- data/package/index.d.ts +62 -20
- data/package/index.js +4 -2
- data/package/optimization/rspack.js +29 -0
- data/package/optimization/webpack.js +49 -0
- data/package/plugins/rspack.js +88 -0
- data/package/plugins/webpack.js +62 -0
- data/package/rspack/index.js +57 -0
- data/package/rules/babel.js +2 -2
- data/package/rules/css.js +1 -1
- data/package/rules/esbuild.js +2 -2
- data/package/rules/file.js +11 -5
- data/package/rules/less.js +1 -1
- data/package/rules/raw.js +12 -2
- data/package/rules/rspack.js +162 -0
- data/package/rules/sass.js +6 -2
- data/package/rules/stylus.js +1 -1
- data/package/rules/swc.js +2 -2
- data/package/utils/debug.js +49 -0
- data/package/utils/getStyleRule.js +16 -3
- data/package/utils/requireOrError.js +15 -0
- data/package/utils/validateDependencies.js +61 -0
- data/package/webpackDevServerConfig.js +2 -0
- data/package.json +19 -31
- data/test/package/environments/base.test.js +1 -1
- data/test/package/rules/esbuild.test.js +1 -1
- data/test/package/rules/swc.test.js +1 -1
- data/test/package/rules/{index.test.js → webpack.test.js} +1 -1
- data/yarn.lock +2136 -726
- metadata +26 -11
- /data/package/rules/{index.js → webpack.js} +0 -0
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)
|
data/docs/troubleshooting.md
CHANGED
@@ -17,6 +17,11 @@
|
|
17
17
|
|
18
18
|
4. You can also pass additional options to the command to run the webpack-dev-server and start the webpack-dev-server with the option `--debug-shakapacker`
|
19
19
|
|
20
|
+
5. ChatGPT and other AI tools can consume this output file. Change the NODE_ENV per your needs. Then upload the file to your favorite AI tool.
|
21
|
+
```
|
22
|
+
NODE_ENV=development bin/shakapacker --profile --json > /tmp/webpack-stats.json
|
23
|
+
```
|
24
|
+
|
20
25
|
## Incorrect peer dependencies
|
21
26
|
Shakapacker uses peer dependencies to make it easier to manage what versions are being used for your app, which is especially
|
22
27
|
useful for patching security vulnerabilities. However, not all package managers will actually enforce these versions - notably,
|
@@ -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 `
|
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
|
50
|
-
|
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
|
data/docs/using_swc_loader.md
CHANGED
@@ -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 `
|
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
|
45
|
-
|
46
|
+
# Select JavaScript transpiler to use, available options are 'babel' (default) or 'swc'
|
47
|
+
javascript_transpiler: 'swc'
|
46
48
|
```
|
47
49
|
|
48
50
|
## Usage
|
data/lib/install/bin/shakapacker
CHANGED
@@ -2,12 +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
8
|
require "shakapacker"
|
8
|
-
require "shakapacker/
|
9
|
+
require "shakapacker/runner"
|
9
10
|
|
10
|
-
|
11
|
-
Dir.chdir(APP_ROOT) do
|
12
|
-
Shakapacker::WebpackRunner.run(ARGV)
|
13
|
-
end
|
11
|
+
Shakapacker::Runner.run(ARGV)
|
@@ -36,8 +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
|
40
|
-
|
39
|
+
# Select JavaScript transpiler to use, available options are 'babel' (default), 'swc' or 'esbuild'
|
40
|
+
javascript_transpiler: 'babel'
|
41
|
+
|
42
|
+
# Select assets bundler to use
|
43
|
+
# Available options: 'webpack' (default) or 'rspack'
|
44
|
+
assets_bundler: 'webpack'
|
41
45
|
|
42
46
|
# Raises an error if there is a mismatch in the shakapacker gem and npm package being used
|
43
47
|
ensure_consistent_versioning: true
|
@@ -0,0 +1,30 @@
|
|
1
|
+
{
|
2
|
+
"rspack": {
|
3
|
+
"@rspack/cli": "^1.0.0",
|
4
|
+
"@rspack/core": "^1.0.0",
|
5
|
+
"rspack-manifest-plugin": "^5.0.0"
|
6
|
+
},
|
7
|
+
"webpack": {
|
8
|
+
"mini-css-extract-plugin": "^2.0.0",
|
9
|
+
"terser-webpack-plugin": "^5.3.1",
|
10
|
+
"webpack": "^5.76.0",
|
11
|
+
"webpack-assets-manifest": "^5.0.6 || ^6.0.0",
|
12
|
+
"webpack-cli": "^4.9.2 || ^5.0.0 || ^6.0.0",
|
13
|
+
"webpack-dev-server": "^4.15.2 || ^5.2.2",
|
14
|
+
"webpack-merge": "^5.8.0 || ^6.0.0",
|
15
|
+
"webpack-subresource-integrity": "^5.1.0"
|
16
|
+
},
|
17
|
+
"common": {
|
18
|
+
"compression-webpack-plugin": "^9.0.0 || ^10.0.0|| ^11.0.0",
|
19
|
+
"css-loader": "^6.0.0 || ^7.0.0",
|
20
|
+
"sass-loader": "^13.0.0 || ^14.0.0 || ^15.0.0 || ^16.0.0",
|
21
|
+
"style-loader": "^3.0.0 || ^4.0.0"
|
22
|
+
},
|
23
|
+
"babel": {
|
24
|
+
"@babel/core": "^7.17.9",
|
25
|
+
"@babel/plugin-transform-runtime": "^7.17.0",
|
26
|
+
"@babel/preset-env": "^7.16.11",
|
27
|
+
"@babel/runtime": "^7.17.9",
|
28
|
+
"babel-loader": "^8.2.4 || ^9.0.0 || ^10.0.0"
|
29
|
+
}
|
30
|
+
}
|
data/lib/install/template.rb
CHANGED
@@ -8,7 +8,6 @@ require "package_json"
|
|
8
8
|
force_option = ENV["FORCE"] ? { force: true } : {}
|
9
9
|
|
10
10
|
copy_file "#{__dir__}/config/shakapacker.yml", "config/shakapacker.yml", force_option
|
11
|
-
remove_file "#{__dir__}/package.json" if force_option[:force]
|
12
11
|
|
13
12
|
say "Copying webpack core config"
|
14
13
|
directory "#{__dir__}/config/webpack", "config/webpack", force_option
|
@@ -112,7 +111,15 @@ rescue PackageJson::Error
|
|
112
111
|
end
|
113
112
|
|
114
113
|
def fetch_peer_dependencies
|
115
|
-
PackageJson.read("#{__dir__}
|
114
|
+
PackageJson.read("#{__dir__}").fetch(ENV["SHAKAPACKER_BUNDLER"] || "webpack")
|
115
|
+
end
|
116
|
+
|
117
|
+
def fetch_common_dependencies
|
118
|
+
ENV["SKIP_COMMON_LOADERS"] ? {} : PackageJson.read("#{__dir__}").fetch("common")
|
119
|
+
end
|
120
|
+
|
121
|
+
def fetch_babel_dependencies
|
122
|
+
ENV["USE_BABEL_PACKAGES"] ? PackageJson.read("#{__dir__}").fetch("babel") : {}
|
116
123
|
end
|
117
124
|
|
118
125
|
Dir.chdir(Rails.root) do
|
@@ -130,6 +137,9 @@ Dir.chdir(Rails.root) do
|
|
130
137
|
end
|
131
138
|
|
132
139
|
peers = fetch_peer_dependencies
|
140
|
+
peers = peers.merge(fetch_common_dependencies)
|
141
|
+
peers = peers.merge(fetch_babel_dependencies)
|
142
|
+
|
133
143
|
dev_dependency_packages = ["webpack-dev-server"]
|
134
144
|
|
135
145
|
dependencies_to_add = []
|
@@ -88,6 +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
|
100
|
+
def bundler
|
101
|
+
assets_bundler
|
102
|
+
end
|
103
|
+
|
104
|
+
def rspack?
|
105
|
+
assets_bundler == "rspack"
|
106
|
+
end
|
107
|
+
|
108
|
+
def 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
|
120
|
+
end
|
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
|
+
|
91
136
|
def fetch(key)
|
92
137
|
data.fetch(key, defaults[key])
|
93
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,12 +79,19 @@ module Shakapacker
|
|
75
79
|
env["NODE_OPTIONS"] = "#{env["NODE_OPTIONS"]} --inspect-brk --trace-warnings"
|
76
80
|
end
|
77
81
|
|
82
|
+
# Add config file
|
78
83
|
cmd += ["--config", @webpack_config]
|
79
|
-
cmd += ["--progress", "--color"] if @pretty
|
80
84
|
|
81
|
-
#
|
82
|
-
|
83
|
-
|
85
|
+
# Add assets bundler-specific flags
|
86
|
+
if webpack?
|
87
|
+
cmd += ["--progress", "--color"] if @pretty
|
88
|
+
# Default behavior of webpack-dev-server is @hot = true
|
89
|
+
cmd += ["--hot", "only"] if @hot == "only"
|
90
|
+
cmd += ["--no-hot"] if !@hot
|
91
|
+
elsif rspack?
|
92
|
+
# Rspack supports --hot but not --no-hot or --progress/--color
|
93
|
+
cmd += ["--hot"] if @hot && @hot != false
|
94
|
+
end
|
84
95
|
|
85
96
|
cmd += @argv
|
86
97
|
|
@@ -90,7 +101,16 @@ module Shakapacker
|
|
90
101
|
end
|
91
102
|
|
92
103
|
def build_cmd
|
93
|
-
|
104
|
+
command = @config.rspack? ? "rspack" : "webpack"
|
105
|
+
package_json.manager.native_exec_command(command, ["serve"])
|
106
|
+
end
|
107
|
+
|
108
|
+
def webpack?
|
109
|
+
@config.webpack?
|
110
|
+
end
|
111
|
+
|
112
|
+
def rspack?
|
113
|
+
@config.rspack?
|
94
114
|
end
|
95
115
|
end
|
96
116
|
end
|
data/lib/shakapacker/manifest.rb
CHANGED
@@ -108,15 +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.
|
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
|
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}).
|
120
122
|
|
121
123
|
Your manifest contains:
|
122
124
|
#{JSON.pretty_generate(@data)}
|