shakapacker 9.2.0 → 9.3.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/ISSUE_TEMPLATE/bug_report.md +6 -9
- data/.github/ISSUE_TEMPLATE/feature_request.md +6 -8
- data/.github/workflows/claude-code-review.yml +4 -5
- data/.github/workflows/claude.yml +1 -2
- data/.github/workflows/dummy.yml +4 -4
- data/.github/workflows/generator.yml +9 -9
- data/.github/workflows/node.yml +11 -2
- data/.github/workflows/ruby.yml +16 -16
- data/.github/workflows/test-bundlers.yml +9 -9
- data/.gitignore +4 -0
- data/CHANGELOG.md +19 -4
- data/CLAUDE.md +6 -1
- data/CONTRIBUTING.md +0 -1
- data/Gemfile.lock +1 -1
- data/README.md +14 -14
- data/TODO.md +10 -2
- data/TODO_v9.md +13 -3
- data/bin/export-bundler-config +1 -1
- data/conductor-setup.sh +1 -1
- data/conductor.json +1 -1
- data/docs/cdn_setup.md +13 -8
- data/docs/common-upgrades.md +2 -1
- data/docs/configuration.md +630 -0
- data/docs/css-modules-export-mode.md +120 -100
- data/docs/customizing_babel_config.md +16 -16
- data/docs/deployment.md +18 -0
- data/docs/developing_shakapacker.md +6 -0
- data/docs/optional-peer-dependencies.md +9 -4
- data/docs/peer-dependencies.md +17 -6
- data/docs/precompile_hook.md +342 -0
- data/docs/react.md +57 -47
- data/docs/releasing.md +0 -2
- data/docs/rspack.md +25 -21
- data/docs/rspack_migration_guide.md +335 -8
- data/docs/sprockets.md +1 -0
- data/docs/style_loader_vs_mini_css.md +12 -12
- data/docs/subresource_integrity.md +13 -7
- data/docs/transpiler-performance.md +40 -19
- data/docs/troubleshooting.md +0 -2
- data/docs/typescript-migration.md +48 -39
- data/docs/typescript.md +12 -8
- data/docs/using_esbuild_loader.md +10 -10
- data/docs/v6_upgrade.md +33 -20
- data/docs/v7_upgrade.md +8 -6
- data/docs/v8_upgrade.md +13 -12
- data/docs/v9_upgrade.md +2 -1
- data/eslint.config.fast.js +134 -0
- data/eslint.config.js +140 -0
- data/knip.ts +54 -0
- data/lib/install/bin/export-bundler-config +1 -1
- data/lib/install/config/shakapacker.yml +16 -5
- data/lib/shakapacker/compiler.rb +80 -0
- data/lib/shakapacker/configuration.rb +33 -5
- data/lib/shakapacker/dev_server_runner.rb +140 -1
- data/lib/shakapacker/doctor.rb +294 -65
- data/lib/shakapacker/instance.rb +8 -3
- data/lib/shakapacker/runner.rb +244 -8
- data/lib/shakapacker/version.rb +1 -1
- data/lib/tasks/shakapacker/doctor.rake +42 -2
- data/package/babel/preset.ts +7 -4
- data/package/config.ts +42 -30
- data/package/configExporter/cli.ts +799 -208
- data/package/configExporter/configFile.ts +520 -0
- data/package/configExporter/fileWriter.ts +12 -8
- data/package/configExporter/index.ts +9 -1
- data/package/configExporter/types.ts +36 -2
- data/package/configExporter/yamlSerializer.ts +22 -8
- data/package/dev_server.ts +1 -1
- data/package/environments/__type-tests__/rspack-plugin-compatibility.ts +11 -5
- data/package/environments/base.ts +18 -13
- data/package/environments/development.ts +1 -1
- data/package/environments/production.ts +4 -1
- data/package/index.d.ts +50 -3
- data/package/index.d.ts.template +50 -0
- data/package/index.ts +7 -7
- data/package/loaders.d.ts +2 -2
- data/package/optimization/rspack.ts +1 -1
- data/package/plugins/rspack.ts +15 -4
- data/package/plugins/webpack.ts +7 -3
- data/package/rspack/index.ts +10 -2
- data/package/rules/raw.ts +3 -2
- data/package/rules/sass.ts +1 -1
- data/package/types/README.md +15 -13
- data/package/types/index.ts +5 -5
- data/package/types.ts +0 -1
- data/package/utils/defaultConfigPath.ts +4 -1
- data/package/utils/errorCodes.ts +129 -100
- data/package/utils/errorHelpers.ts +34 -29
- data/package/utils/getStyleRule.ts +5 -2
- data/package/utils/helpers.ts +21 -11
- data/package/utils/pathValidation.ts +43 -35
- data/package/utils/requireOrError.ts +1 -1
- data/package/utils/snakeToCamelCase.ts +1 -1
- data/package/utils/typeGuards.ts +132 -83
- data/package/utils/validateDependencies.ts +1 -1
- data/package/webpack-types.d.ts +3 -3
- data/package/webpackDevServerConfig.ts +22 -10
- data/package-lock.json +2 -2
- data/package.json +36 -28
- data/scripts/type-check-no-emit.js +1 -1
- data/test/configExporter/configFile.test.js +392 -0
- data/test/configExporter/integration.test.js +275 -0
- data/test/helpers.js +1 -1
- data/test/package/configExporter.test.js +154 -0
- data/test/package/helpers.test.js +2 -2
- data/test/package/rules/sass-version-parsing.test.js +71 -0
- data/test/package/rules/sass.test.js +2 -4
- data/test/package/rules/sass1.test.js +1 -3
- data/test/package/rules/sass16.test.js +23 -0
- data/tools/README.md +15 -5
- data/tsconfig.eslint.json +2 -9
- data/yarn.lock +1894 -1492
- metadata +19 -3
- data/.eslintignore +0 -5
@@ -4,15 +4,16 @@ This document provides performance benchmarks comparing different JavaScript tra
|
|
4
4
|
|
5
5
|
## Executive Summary
|
6
6
|
|
7
|
-
| Transpiler
|
8
|
-
|
9
|
-
| **SWC**
|
10
|
-
| **esbuild** | **15x faster** | Minimal config
|
11
|
-
| **Babel**
|
7
|
+
| Transpiler | Relative Speed | Configuration | Best For |
|
8
|
+
| ----------- | -------------- | ---------------- | ---------------------------------------------- |
|
9
|
+
| **SWC** | **20x faster** | Zero config | Production builds, large codebases |
|
10
|
+
| **esbuild** | **15x faster** | Minimal config | Modern browsers, simple transformations |
|
11
|
+
| **Babel** | **Baseline** | Extensive config | Legacy browser support, custom transformations |
|
12
12
|
|
13
13
|
## Detailed Benchmarks
|
14
14
|
|
15
15
|
### Test Environment
|
16
|
+
|
16
17
|
- **Hardware**: MacBook Pro M1, 16GB RAM
|
17
18
|
- **Node Version**: 20.x
|
18
19
|
- **Project Size Categories**:
|
@@ -23,6 +24,7 @@ This document provides performance benchmarks comparing different JavaScript tra
|
|
23
24
|
### Build Time Comparison
|
24
25
|
|
25
26
|
#### Small Project (<100 files, ~50KB total)
|
27
|
+
|
26
28
|
```text
|
27
29
|
SWC: 0.3s (20x faster)
|
28
30
|
esbuild: 0.4s (15x faster)
|
@@ -30,6 +32,7 @@ Babel: 6.0s (baseline)
|
|
30
32
|
```
|
31
33
|
|
32
34
|
#### Medium Project (500 files, ~2MB total)
|
35
|
+
|
33
36
|
```text
|
34
37
|
SWC: 1.2s (25x faster)
|
35
38
|
esbuild: 1.8s (17x faster)
|
@@ -37,6 +40,7 @@ Babel: 30s (baseline)
|
|
37
40
|
```
|
38
41
|
|
39
42
|
#### Large Project (2000 files, ~10MB total)
|
43
|
+
|
40
44
|
```text
|
41
45
|
SWC: 4.5s (22x faster)
|
42
46
|
esbuild: 6.2s (16x faster)
|
@@ -45,25 +49,26 @@ Babel: 100s (baseline)
|
|
45
49
|
|
46
50
|
### Memory Usage
|
47
51
|
|
48
|
-
| Transpiler
|
49
|
-
|
50
|
-
| **SWC**
|
51
|
-
| **esbuild** | 180MB
|
52
|
-
| **Babel**
|
52
|
+
| Transpiler | Peak Memory (Small) | Peak Memory (Medium) | Peak Memory (Large) |
|
53
|
+
| ----------- | ------------------- | -------------------- | ------------------- |
|
54
|
+
| **SWC** | 150MB | 250MB | 450MB |
|
55
|
+
| **esbuild** | 180MB | 300MB | 500MB |
|
56
|
+
| **Babel** | 350MB | 600MB | 1200MB |
|
53
57
|
|
54
58
|
## Incremental Build Performance
|
55
59
|
|
56
60
|
For development with watch mode enabled:
|
57
61
|
|
58
|
-
| Transpiler
|
59
|
-
|
60
|
-
| **SWC**
|
61
|
-
| **esbuild** | 1.8s
|
62
|
-
| **Babel**
|
62
|
+
| Transpiler | Initial Build | Incremental Build | HMR Update |
|
63
|
+
| ----------- | ------------- | ----------------- | ---------- |
|
64
|
+
| **SWC** | 1.2s | 0.1s | <50ms |
|
65
|
+
| **esbuild** | 1.8s | 0.15s | <70ms |
|
66
|
+
| **Babel** | 30s | 2-5s | 200-500ms |
|
63
67
|
|
64
68
|
## Feature Comparison
|
65
69
|
|
66
70
|
### SWC
|
71
|
+
|
67
72
|
- ✅ TypeScript support built-in
|
68
73
|
- ✅ JSX/TSX transformation
|
69
74
|
- ✅ Minification built-in
|
@@ -73,6 +78,7 @@ For development with watch mode enabled:
|
|
73
78
|
- ⚠️ Newer, less battle-tested
|
74
79
|
|
75
80
|
### esbuild
|
81
|
+
|
76
82
|
- ✅ TypeScript support built-in
|
77
83
|
- ✅ JSX transformation
|
78
84
|
- ✅ Extremely fast bundling
|
@@ -81,6 +87,7 @@ For development with watch mode enabled:
|
|
81
87
|
- ❌ No plugin system for custom transforms
|
82
88
|
|
83
89
|
### Babel
|
90
|
+
|
84
91
|
- ✅ Most comprehensive browser support
|
85
92
|
- ✅ Extensive plugin ecosystem
|
86
93
|
- ✅ Custom transformation support
|
@@ -91,6 +98,7 @@ For development with watch mode enabled:
|
|
91
98
|
## Recommendations by Use Case
|
92
99
|
|
93
100
|
### Choose SWC when:
|
101
|
+
|
94
102
|
- Performance is critical
|
95
103
|
- Using modern JavaScript/TypeScript
|
96
104
|
- Building large applications
|
@@ -98,12 +106,14 @@ For development with watch mode enabled:
|
|
98
106
|
- Default choice for new projects
|
99
107
|
|
100
108
|
### Choose esbuild when:
|
109
|
+
|
101
110
|
- Need the absolute fastest builds
|
102
111
|
- Targeting modern browsers only
|
103
112
|
- Simple transformation requirements
|
104
113
|
- Minimal configuration preferred
|
105
114
|
|
106
115
|
### Choose Babel when:
|
116
|
+
|
107
117
|
- Need extensive browser compatibility (IE11, etc.)
|
108
118
|
- Using experimental JavaScript features
|
109
119
|
- Require specific Babel plugins
|
@@ -112,6 +122,7 @@ For development with watch mode enabled:
|
|
112
122
|
## Migration Impact
|
113
123
|
|
114
124
|
### From Babel to SWC
|
125
|
+
|
115
126
|
- **Build time reduction**: 90-95%
|
116
127
|
- **Memory usage reduction**: 50-70%
|
117
128
|
- **Configuration simplification**: 80% less config
|
@@ -120,16 +131,19 @@ For development with watch mode enabled:
|
|
120
131
|
### Real-world Examples
|
121
132
|
|
122
133
|
#### E-commerce Platform (1500 components)
|
134
|
+
|
123
135
|
- **Before (Babel)**: 120s production build
|
124
136
|
- **After (SWC)**: 5.5s production build
|
125
137
|
- **Improvement**: 95.4% faster
|
126
138
|
|
127
139
|
#### SaaS Dashboard (800 files)
|
140
|
+
|
128
141
|
- **Before (Babel)**: 45s development build
|
129
142
|
- **After (SWC)**: 2.1s development build
|
130
143
|
- **Improvement**: 95.3% faster
|
131
144
|
|
132
145
|
#### Blog Platform (200 files)
|
146
|
+
|
133
147
|
- **Before (Babel)**: 15s build time
|
134
148
|
- **After (SWC)**: 0.8s build time
|
135
149
|
- **Improvement**: 94.7% faster
|
@@ -137,28 +151,34 @@ For development with watch mode enabled:
|
|
137
151
|
## How to Switch Transpilers
|
138
152
|
|
139
153
|
### To SWC (Recommended)
|
154
|
+
|
140
155
|
```yaml
|
141
156
|
# config/shakapacker.yml
|
142
|
-
javascript_transpiler:
|
157
|
+
javascript_transpiler: "swc"
|
143
158
|
```
|
159
|
+
|
144
160
|
```bash
|
145
161
|
npm install @swc/core swc-loader
|
146
162
|
```
|
147
163
|
|
148
164
|
### To esbuild
|
165
|
+
|
149
166
|
```yaml
|
150
167
|
# config/shakapacker.yml
|
151
|
-
javascript_transpiler:
|
168
|
+
javascript_transpiler: "esbuild"
|
152
169
|
```
|
170
|
+
|
153
171
|
```bash
|
154
172
|
npm install esbuild esbuild-loader
|
155
173
|
```
|
156
174
|
|
157
175
|
### To Babel
|
176
|
+
|
158
177
|
```yaml
|
159
178
|
# config/shakapacker.yml
|
160
|
-
javascript_transpiler:
|
179
|
+
javascript_transpiler: "babel"
|
161
180
|
```
|
181
|
+
|
162
182
|
```bash
|
163
183
|
npm install babel-loader @babel/core @babel/preset-env
|
164
184
|
```
|
@@ -166,6 +186,7 @@ npm install babel-loader @babel/core @babel/preset-env
|
|
166
186
|
## Testing Methodology
|
167
187
|
|
168
188
|
Benchmarks were conducted using:
|
189
|
+
|
169
190
|
1. Clean builds (no cache)
|
170
191
|
2. Average of 10 runs
|
171
192
|
3. Same source code for all transpilers
|
@@ -176,4 +197,4 @@ Benchmarks were conducted using:
|
|
176
197
|
|
177
198
|
For most projects, **SWC provides the best balance** of performance, features, and ease of use. It offers a 20x performance improvement over Babel with minimal configuration required.
|
178
199
|
|
179
|
-
Consider your specific requirements around browser support, plugin needs, and existing infrastructure when choosing a transpiler. The performance gains from switching to SWC or esbuild can significantly improve developer productivity and CI/CD pipeline efficiency.
|
200
|
+
Consider your specific requirements around browser support, plugin needs, and existing infrastructure when choosing a transpiler. The performance gains from switching to SWC or esbuild can significantly improve developer productivity and CI/CD pipeline efficiency.
|
data/docs/troubleshooting.md
CHANGED
@@ -18,7 +18,6 @@
|
|
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
20
|
5. **Export your full webpack/rspack configuration for analysis**: Use the `bin/export-bundler-config` utility to export your complete resolved configuration. This is especially helpful for:
|
21
|
-
|
22
21
|
- **Migrations**: Comparing configurations before and after migrating between webpack and rspack, or between different Shakapacker versions
|
23
22
|
- **Debugging**: Inspecting the exact configuration webpack/rspack is using, including all merged settings
|
24
23
|
- **AI Analysis**: Uploading the exported config to ChatGPT or other AI tools for troubleshooting
|
@@ -66,7 +65,6 @@
|
|
66
65
|
```
|
67
66
|
|
68
67
|
**Config files are automatically named:** `{bundler}-{env}-{type}.{ext}`
|
69
|
-
|
70
68
|
- Examples: `webpack-development-client.yaml`, `rspack-production-server.yaml`
|
71
69
|
- YAML format includes inline documentation explaining each config key
|
72
70
|
- Separate files for client and server bundles (cleaner than combined)
|
@@ -3,6 +3,7 @@
|
|
3
3
|
This guide helps you adopt TypeScript types in your Shakapacker configuration files for better type safety and IDE support.
|
4
4
|
|
5
5
|
## Table of Contents
|
6
|
+
|
6
7
|
- [Benefits](#benefits)
|
7
8
|
- [Quick Start](#quick-start)
|
8
9
|
- [Migration Steps](#migration-steps)
|
@@ -12,6 +13,7 @@ This guide helps you adopt TypeScript types in your Shakapacker configuration fi
|
|
12
13
|
## Benefits
|
13
14
|
|
14
15
|
Using TypeScript with Shakapacker provides:
|
16
|
+
|
15
17
|
- **Type Safety**: Catch configuration errors at compile time
|
16
18
|
- **IDE Support**: Get autocompletion and inline documentation
|
17
19
|
- **Better Refactoring**: Safely rename and restructure configurations
|
@@ -56,13 +58,13 @@ Rename `config/webpack/webpack.config.js` to `config/webpack/webpack.config.ts`:
|
|
56
58
|
|
57
59
|
```typescript
|
58
60
|
// config/webpack/webpack.config.ts
|
59
|
-
import { generateWebpackConfig, merge } from
|
60
|
-
import type { WebpackConfigWithDevServer } from
|
61
|
-
import type { Configuration } from
|
61
|
+
import { generateWebpackConfig, merge } from "shakapacker"
|
62
|
+
import type { WebpackConfigWithDevServer } from "shakapacker/types"
|
63
|
+
import type { Configuration } from "webpack"
|
62
64
|
|
63
65
|
const customConfig: Configuration = {
|
64
66
|
resolve: {
|
65
|
-
extensions: [
|
67
|
+
extensions: [".css", ".ts", ".tsx"]
|
66
68
|
}
|
67
69
|
}
|
68
70
|
|
@@ -83,7 +85,7 @@ import type {
|
|
83
85
|
WebpackConfigWithDevServer,
|
84
86
|
RspackConfigWithDevServer,
|
85
87
|
CompressionPluginOptions
|
86
|
-
} from
|
88
|
+
} from "shakapacker/types"
|
87
89
|
```
|
88
90
|
|
89
91
|
### Step 2: Type Your Configuration Objects
|
@@ -94,16 +96,16 @@ Add type annotations to your configuration objects:
|
|
94
96
|
// Before (JavaScript)
|
95
97
|
const customConfig = {
|
96
98
|
resolve: {
|
97
|
-
extensions: [
|
99
|
+
extensions: [".css", ".ts", ".tsx"]
|
98
100
|
}
|
99
101
|
}
|
100
102
|
|
101
103
|
// After (TypeScript)
|
102
|
-
import type { Configuration } from
|
104
|
+
import type { Configuration } from "webpack"
|
103
105
|
|
104
106
|
const customConfig: Configuration = {
|
105
107
|
resolve: {
|
106
|
-
extensions: [
|
108
|
+
extensions: [".css", ".ts", ".tsx"]
|
107
109
|
}
|
108
110
|
}
|
109
111
|
```
|
@@ -120,8 +122,8 @@ function modifyConfig(config) {
|
|
120
122
|
}
|
121
123
|
|
122
124
|
// After (TypeScript)
|
123
|
-
import type { Configuration } from
|
124
|
-
import type { WebpackPluginInstance } from
|
125
|
+
import type { Configuration } from "webpack"
|
126
|
+
import type { WebpackPluginInstance } from "shakapacker/types"
|
125
127
|
|
126
128
|
function modifyConfig(config: Configuration): Configuration {
|
127
129
|
const plugins = config.plugins as WebpackPluginInstance[]
|
@@ -134,11 +136,11 @@ function modifyConfig(config: Configuration): Configuration {
|
|
134
136
|
|
135
137
|
```typescript
|
136
138
|
// config/webpack/development.ts
|
137
|
-
import { generateWebpackConfig } from
|
138
|
-
import type { WebpackConfigWithDevServer } from
|
139
|
+
import { generateWebpackConfig } from "shakapacker"
|
140
|
+
import type { WebpackConfigWithDevServer } from "shakapacker/types"
|
139
141
|
|
140
142
|
const developmentConfig: WebpackConfigWithDevServer = generateWebpackConfig({
|
141
|
-
devtool:
|
143
|
+
devtool: "eval-cheap-module-source-map",
|
142
144
|
devServer: {
|
143
145
|
hot: true,
|
144
146
|
port: 3035
|
@@ -153,11 +155,11 @@ export default developmentConfig
|
|
153
155
|
### Pattern 1: Custom Loaders
|
154
156
|
|
155
157
|
```typescript
|
156
|
-
import type { RuleSetRule } from
|
158
|
+
import type { RuleSetRule } from "webpack"
|
157
159
|
|
158
160
|
const customLoader: RuleSetRule = {
|
159
161
|
test: /\.svg$/,
|
160
|
-
use: [
|
162
|
+
use: ["@svgr/webpack"]
|
161
163
|
}
|
162
164
|
|
163
165
|
const config: Configuration = generateWebpackConfig({
|
@@ -170,12 +172,12 @@ const config: Configuration = generateWebpackConfig({
|
|
170
172
|
### Pattern 2: Plugin Configuration
|
171
173
|
|
172
174
|
```typescript
|
173
|
-
import CompressionPlugin from
|
174
|
-
import type { CompressionPluginOptions } from
|
175
|
+
import CompressionPlugin from "compression-webpack-plugin"
|
176
|
+
import type { CompressionPluginOptions } from "shakapacker/types"
|
175
177
|
|
176
178
|
const compressionOptions: CompressionPluginOptions = {
|
177
|
-
filename:
|
178
|
-
algorithm:
|
179
|
+
filename: "[path][base].gz",
|
180
|
+
algorithm: "gzip",
|
179
181
|
test: /\.(js|css|html|json|ico|svg|eot|otf|ttf)$/
|
180
182
|
}
|
181
183
|
|
@@ -187,8 +189,8 @@ const config: Configuration = generateWebpackConfig({
|
|
187
189
|
### Pattern 3: Conditional Configuration
|
188
190
|
|
189
191
|
```typescript
|
190
|
-
import type { Configuration } from
|
191
|
-
import { env } from
|
192
|
+
import type { Configuration } from "webpack"
|
193
|
+
import { env } from "shakapacker"
|
192
194
|
|
193
195
|
const config: Configuration = generateWebpackConfig()
|
194
196
|
|
@@ -208,11 +210,11 @@ export default config
|
|
208
210
|
|
209
211
|
```typescript
|
210
212
|
// config/rspack/rspack.config.ts
|
211
|
-
import type { RspackConfigWithDevServer } from
|
212
|
-
import { generateWebpackConfig } from
|
213
|
+
import type { RspackConfigWithDevServer } from "shakapacker/types"
|
214
|
+
import { generateWebpackConfig } from "shakapacker"
|
213
215
|
|
214
216
|
const rspackConfig: RspackConfigWithDevServer = generateWebpackConfig({
|
215
|
-
mode:
|
217
|
+
mode: "development",
|
216
218
|
devServer: {
|
217
219
|
hot: true,
|
218
220
|
port: 3036
|
@@ -246,11 +248,13 @@ npm run type-check
|
|
246
248
|
## Available Types Reference
|
247
249
|
|
248
250
|
### Core Types
|
251
|
+
|
249
252
|
- `Config` - Shakapacker configuration from shakapacker.yml
|
250
253
|
- `Env` - Environment variables and helpers
|
251
254
|
- `DevServerConfig` - Development server configuration
|
252
255
|
|
253
256
|
### Webpack/Rspack Types
|
257
|
+
|
254
258
|
- `WebpackConfigWithDevServer` - Webpack configuration with dev server
|
255
259
|
- `RspackConfigWithDevServer` - Rspack configuration with dev server
|
256
260
|
- `WebpackPluginInstance` - Webpack plugin instance type
|
@@ -258,6 +262,7 @@ npm run type-check
|
|
258
262
|
- `RspackPlugin` - **⚠️ Deprecated:** Use `RspackPluginInstance` instead
|
259
263
|
|
260
264
|
### Helper Types
|
265
|
+
|
261
266
|
- `CompressionPluginOptions` - Compression plugin configuration
|
262
267
|
- `ReactRefreshWebpackPlugin` - React refresh for Webpack
|
263
268
|
- `ReactRefreshRspackPlugin` - React refresh for Rspack
|
@@ -287,7 +292,7 @@ plugins.push(new MyPlugin())
|
|
287
292
|
|
288
293
|
```typescript
|
289
294
|
// If types aren't available, declare them
|
290
|
-
declare module
|
295
|
+
declare module "my-custom-loader" {
|
291
296
|
const loader: any
|
292
297
|
export default loader
|
293
298
|
}
|
@@ -316,27 +321,31 @@ Here's a complete example of a typed webpack configuration:
|
|
316
321
|
|
317
322
|
```typescript
|
318
323
|
// config/webpack/webpack.config.ts
|
319
|
-
import {
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
+
import {
|
325
|
+
generateWebpackConfig,
|
326
|
+
merge,
|
327
|
+
config as shakapackerConfig
|
328
|
+
} from "shakapacker"
|
329
|
+
import type { Configuration } from "webpack"
|
330
|
+
import type { WebpackConfigWithDevServer } from "shakapacker/types"
|
331
|
+
import CompressionPlugin from "compression-webpack-plugin"
|
332
|
+
import { resolve } from "path"
|
324
333
|
|
325
334
|
// Type-safe custom configuration
|
326
335
|
const customConfig: Configuration = {
|
327
336
|
resolve: {
|
328
|
-
extensions: [
|
337
|
+
extensions: [".css", ".ts", ".tsx"],
|
329
338
|
alias: {
|
330
|
-
|
331
|
-
|
332
|
-
|
339
|
+
"@": resolve(__dirname, "../../app/javascript"),
|
340
|
+
components: resolve(__dirname, "../../app/javascript/components"),
|
341
|
+
utils: resolve(__dirname, "../../app/javascript/utils")
|
333
342
|
}
|
334
343
|
},
|
335
344
|
module: {
|
336
345
|
rules: [
|
337
346
|
{
|
338
347
|
test: /\.svg$/,
|
339
|
-
use: [
|
348
|
+
use: ["@svgr/webpack"],
|
340
349
|
issuer: /\.(tsx?|jsx?)$/
|
341
350
|
}
|
342
351
|
]
|
@@ -347,13 +356,13 @@ const customConfig: Configuration = {
|
|
347
356
|
const webpackConfig: Configuration = generateWebpackConfig(customConfig)
|
348
357
|
|
349
358
|
// Type-safe modifications based on environment
|
350
|
-
if (shakapackerConfig.env ===
|
359
|
+
if (shakapackerConfig.env === "production") {
|
351
360
|
const plugins = (webpackConfig.plugins || []) as WebpackPluginInstance[]
|
352
361
|
|
353
362
|
plugins.push(
|
354
363
|
new CompressionPlugin({
|
355
|
-
filename:
|
356
|
-
algorithm:
|
364
|
+
filename: "[path][base].br",
|
365
|
+
algorithm: "brotliCompress",
|
357
366
|
test: /\.(js|css|html|json|ico|svg|eot|otf|ttf)$/
|
358
367
|
})
|
359
368
|
)
|
@@ -376,4 +385,4 @@ After migrating to TypeScript:
|
|
376
385
|
- [TypeScript Handbook](https://www.typescriptlang.org/docs/handbook/intro.html)
|
377
386
|
- [Webpack TypeScript Configuration](https://webpack.js.org/configuration/configuration-languages/#typescript)
|
378
387
|
- [Shakapacker Types Documentation](./types/README.md)
|
379
|
-
- [Migration Examples](https://github.com/shakacode/shakapacker/tree/main/examples/typescript-config)
|
388
|
+
- [Migration Examples](https://github.com/shakacode/shakapacker/tree/main/examples/typescript-config)
|
data/docs/typescript.md
CHANGED
@@ -8,8 +8,8 @@ Shakapacker v9 includes TypeScript support, providing type safety and better IDE
|
|
8
8
|
|
9
9
|
```typescript
|
10
10
|
// webpack.config.ts
|
11
|
-
import { generateWebpackConfig } from
|
12
|
-
import type { Configuration } from
|
11
|
+
import { generateWebpackConfig } from "shakapacker"
|
12
|
+
import type { Configuration } from "webpack"
|
13
13
|
|
14
14
|
const config: Configuration = generateWebpackConfig({
|
15
15
|
// Your config with full type safety
|
@@ -22,7 +22,7 @@ export default config
|
|
22
22
|
|
23
23
|
```javascript
|
24
24
|
// webpack.config.js
|
25
|
-
const { generateWebpackConfig } = require(
|
25
|
+
const { generateWebpackConfig } = require("shakapacker")
|
26
26
|
|
27
27
|
/** @type {import('webpack').Configuration} */
|
28
28
|
const config = {
|
@@ -48,10 +48,12 @@ module.exports = generateWebpackConfig(config)
|
|
48
48
|
## IDE Setup
|
49
49
|
|
50
50
|
### VS Code
|
51
|
+
|
51
52
|
- Install TypeScript extension (built-in)
|
52
53
|
- Set `"typescript.tsdk": "node_modules/typescript/lib"` in settings
|
53
54
|
|
54
55
|
### WebStorm/IntelliJ
|
56
|
+
|
55
57
|
- Enable TypeScript service in Settings → Languages & Frameworks → TypeScript
|
56
58
|
|
57
59
|
## Common Patterns
|
@@ -59,7 +61,7 @@ module.exports = generateWebpackConfig(config)
|
|
59
61
|
### Environment-Specific Config
|
60
62
|
|
61
63
|
```typescript
|
62
|
-
import { generateWebpackConfig, env } from
|
64
|
+
import { generateWebpackConfig, env } from "shakapacker"
|
63
65
|
|
64
66
|
const config = generateWebpackConfig({
|
65
67
|
optimization: {
|
@@ -71,8 +73,8 @@ const config = generateWebpackConfig({
|
|
71
73
|
### Rspack Config
|
72
74
|
|
73
75
|
```typescript
|
74
|
-
import { generateRspackConfig } from
|
75
|
-
import type { RspackOptions } from
|
76
|
+
import { generateRspackConfig } from "shakapacker/rspack"
|
77
|
+
import type { RspackOptions } from "@rspack/core"
|
76
78
|
|
77
79
|
const config: RspackOptions = {
|
78
80
|
// Rspack-specific config
|
@@ -84,16 +86,18 @@ export default generateRspackConfig(config)
|
|
84
86
|
## Troubleshooting
|
85
87
|
|
86
88
|
**Cannot find module 'shakapacker'**
|
89
|
+
|
87
90
|
```typescript
|
88
91
|
/// <reference types="shakapacker" />
|
89
92
|
```
|
90
93
|
|
91
94
|
**Type errors with custom loaders**
|
95
|
+
|
92
96
|
```typescript
|
93
|
-
use: [require.resolve(
|
97
|
+
use: [require.resolve("custom-loader") as any]
|
94
98
|
```
|
95
99
|
|
96
100
|
## Further Reading
|
97
101
|
|
98
102
|
- [Webpack TypeScript Documentation](https://webpack.js.org/configuration/configuration-languages/#typescript)
|
99
|
-
- [TypeScript Handbook](https://www.typescriptlang.org/docs/)
|
103
|
+
- [TypeScript Handbook](https://www.typescriptlang.org/docs/)
|
@@ -11,6 +11,7 @@ If you face any issues, please report them at https://github.com/shakacode/shaka
|
|
11
11
|
While esbuild is a complete bundler, through the usage of [esbuild-loader](https://github.com/privatenumber/esbuild-loader), you can still leverage esbuild's speedy transpilation and minification in your Webpack-based configs.
|
12
12
|
|
13
13
|
Please note, that unlike Babel or SWC loader, esbuild-loader has got no support for things like:
|
14
|
+
|
14
15
|
- React Hot Module reload
|
15
16
|
- ES5 as a compilation target
|
16
17
|
- Automatic polyfills for missing browser features
|
@@ -28,7 +29,7 @@ npm install esbuild esbuild-loader
|
|
28
29
|
```
|
29
30
|
|
30
31
|
2. Add or change `javascript_transpiler` value in your default `shakapacker.yml` config to `esbuild`
|
31
|
-
The default configuration of babel is done by using `package.json` to use the file within the `shakapacker` package.
|
32
|
+
The default configuration of babel is done by using `package.json` to use the file within the `shakapacker` package.
|
32
33
|
|
33
34
|
```yml
|
34
35
|
default: &default
|
@@ -47,7 +48,7 @@ default: &default
|
|
47
48
|
cache_manifest: false
|
48
49
|
|
49
50
|
# Select JavaScript transpiler to use, available options are 'babel' (default), 'swc' or 'esbuild'
|
50
|
-
javascript_transpiler:
|
51
|
+
javascript_transpiler: "esbuild"
|
51
52
|
```
|
52
53
|
|
53
54
|
### (Optional) Replace minification with esbuild
|
@@ -59,14 +60,14 @@ o do so, you need to modify your webpack configuration and use `ESBuildMinifyPlu
|
|
59
60
|
Example:
|
60
61
|
|
61
62
|
```js
|
62
|
-
const { generateWebpackConfig } = require(
|
63
|
-
const { ESBuildMinifyPlugin } = require(
|
63
|
+
const { generateWebpackConfig } = require("shakapacker")
|
64
|
+
const { ESBuildMinifyPlugin } = require("esbuild-loader")
|
64
65
|
|
65
66
|
const options = {
|
66
67
|
optimization: {
|
67
68
|
minimizer: [
|
68
69
|
new ESBuildMinifyPlugin({
|
69
|
-
target:
|
70
|
+
target: "es2015"
|
70
71
|
})
|
71
72
|
]
|
72
73
|
}
|
@@ -101,11 +102,10 @@ See some examples below of potential `config/babel.config.js`.
|
|
101
102
|
|
102
103
|
### Example: Specifying esnext target environment
|
103
104
|
|
104
|
-
|
105
105
|
```js
|
106
106
|
const customConfig = {
|
107
107
|
options: {
|
108
|
-
target:
|
108
|
+
target: "esnext"
|
109
109
|
}
|
110
110
|
}
|
111
111
|
|
@@ -115,12 +115,12 @@ module.exports = customConfig
|
|
115
115
|
### Example: Using custom jsxFragment and jsxFactory
|
116
116
|
|
117
117
|
```js
|
118
|
-
const { env } = require(
|
118
|
+
const { env } = require("shakapacker")
|
119
119
|
|
120
120
|
const customConfig = {
|
121
121
|
options: {
|
122
|
-
jsxFragment:
|
123
|
-
jsxFactory:
|
122
|
+
jsxFragment: "Fragment",
|
123
|
+
jsxFactory: "h"
|
124
124
|
}
|
125
125
|
}
|
126
126
|
|