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.
Files changed (115) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE/bug_report.md +6 -9
  3. data/.github/ISSUE_TEMPLATE/feature_request.md +6 -8
  4. data/.github/workflows/claude-code-review.yml +4 -5
  5. data/.github/workflows/claude.yml +1 -2
  6. data/.github/workflows/dummy.yml +4 -4
  7. data/.github/workflows/generator.yml +9 -9
  8. data/.github/workflows/node.yml +11 -2
  9. data/.github/workflows/ruby.yml +16 -16
  10. data/.github/workflows/test-bundlers.yml +9 -9
  11. data/.gitignore +4 -0
  12. data/CHANGELOG.md +19 -4
  13. data/CLAUDE.md +6 -1
  14. data/CONTRIBUTING.md +0 -1
  15. data/Gemfile.lock +1 -1
  16. data/README.md +14 -14
  17. data/TODO.md +10 -2
  18. data/TODO_v9.md +13 -3
  19. data/bin/export-bundler-config +1 -1
  20. data/conductor-setup.sh +1 -1
  21. data/conductor.json +1 -1
  22. data/docs/cdn_setup.md +13 -8
  23. data/docs/common-upgrades.md +2 -1
  24. data/docs/configuration.md +630 -0
  25. data/docs/css-modules-export-mode.md +120 -100
  26. data/docs/customizing_babel_config.md +16 -16
  27. data/docs/deployment.md +18 -0
  28. data/docs/developing_shakapacker.md +6 -0
  29. data/docs/optional-peer-dependencies.md +9 -4
  30. data/docs/peer-dependencies.md +17 -6
  31. data/docs/precompile_hook.md +342 -0
  32. data/docs/react.md +57 -47
  33. data/docs/releasing.md +0 -2
  34. data/docs/rspack.md +25 -21
  35. data/docs/rspack_migration_guide.md +335 -8
  36. data/docs/sprockets.md +1 -0
  37. data/docs/style_loader_vs_mini_css.md +12 -12
  38. data/docs/subresource_integrity.md +13 -7
  39. data/docs/transpiler-performance.md +40 -19
  40. data/docs/troubleshooting.md +0 -2
  41. data/docs/typescript-migration.md +48 -39
  42. data/docs/typescript.md +12 -8
  43. data/docs/using_esbuild_loader.md +10 -10
  44. data/docs/v6_upgrade.md +33 -20
  45. data/docs/v7_upgrade.md +8 -6
  46. data/docs/v8_upgrade.md +13 -12
  47. data/docs/v9_upgrade.md +2 -1
  48. data/eslint.config.fast.js +134 -0
  49. data/eslint.config.js +140 -0
  50. data/knip.ts +54 -0
  51. data/lib/install/bin/export-bundler-config +1 -1
  52. data/lib/install/config/shakapacker.yml +16 -5
  53. data/lib/shakapacker/compiler.rb +80 -0
  54. data/lib/shakapacker/configuration.rb +33 -5
  55. data/lib/shakapacker/dev_server_runner.rb +140 -1
  56. data/lib/shakapacker/doctor.rb +294 -65
  57. data/lib/shakapacker/instance.rb +8 -3
  58. data/lib/shakapacker/runner.rb +244 -8
  59. data/lib/shakapacker/version.rb +1 -1
  60. data/lib/tasks/shakapacker/doctor.rake +42 -2
  61. data/package/babel/preset.ts +7 -4
  62. data/package/config.ts +42 -30
  63. data/package/configExporter/cli.ts +799 -208
  64. data/package/configExporter/configFile.ts +520 -0
  65. data/package/configExporter/fileWriter.ts +12 -8
  66. data/package/configExporter/index.ts +9 -1
  67. data/package/configExporter/types.ts +36 -2
  68. data/package/configExporter/yamlSerializer.ts +22 -8
  69. data/package/dev_server.ts +1 -1
  70. data/package/environments/__type-tests__/rspack-plugin-compatibility.ts +11 -5
  71. data/package/environments/base.ts +18 -13
  72. data/package/environments/development.ts +1 -1
  73. data/package/environments/production.ts +4 -1
  74. data/package/index.d.ts +50 -3
  75. data/package/index.d.ts.template +50 -0
  76. data/package/index.ts +7 -7
  77. data/package/loaders.d.ts +2 -2
  78. data/package/optimization/rspack.ts +1 -1
  79. data/package/plugins/rspack.ts +15 -4
  80. data/package/plugins/webpack.ts +7 -3
  81. data/package/rspack/index.ts +10 -2
  82. data/package/rules/raw.ts +3 -2
  83. data/package/rules/sass.ts +1 -1
  84. data/package/types/README.md +15 -13
  85. data/package/types/index.ts +5 -5
  86. data/package/types.ts +0 -1
  87. data/package/utils/defaultConfigPath.ts +4 -1
  88. data/package/utils/errorCodes.ts +129 -100
  89. data/package/utils/errorHelpers.ts +34 -29
  90. data/package/utils/getStyleRule.ts +5 -2
  91. data/package/utils/helpers.ts +21 -11
  92. data/package/utils/pathValidation.ts +43 -35
  93. data/package/utils/requireOrError.ts +1 -1
  94. data/package/utils/snakeToCamelCase.ts +1 -1
  95. data/package/utils/typeGuards.ts +132 -83
  96. data/package/utils/validateDependencies.ts +1 -1
  97. data/package/webpack-types.d.ts +3 -3
  98. data/package/webpackDevServerConfig.ts +22 -10
  99. data/package-lock.json +2 -2
  100. data/package.json +36 -28
  101. data/scripts/type-check-no-emit.js +1 -1
  102. data/test/configExporter/configFile.test.js +392 -0
  103. data/test/configExporter/integration.test.js +275 -0
  104. data/test/helpers.js +1 -1
  105. data/test/package/configExporter.test.js +154 -0
  106. data/test/package/helpers.test.js +2 -2
  107. data/test/package/rules/sass-version-parsing.test.js +71 -0
  108. data/test/package/rules/sass.test.js +2 -4
  109. data/test/package/rules/sass1.test.js +1 -3
  110. data/test/package/rules/sass16.test.js +23 -0
  111. data/tools/README.md +15 -5
  112. data/tsconfig.eslint.json +2 -9
  113. data/yarn.lock +1894 -1492
  114. metadata +19 -3
  115. 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 | 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 |
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 | Peak Memory (Small) | Peak Memory (Medium) | Peak Memory (Large) |
49
- |------------|-------------------|---------------------|-------------------|
50
- | **SWC** | 150MB | 250MB | 450MB |
51
- | **esbuild** | 180MB | 300MB | 500MB |
52
- | **Babel** | 350MB | 600MB | 1200MB |
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 | Initial Build | Incremental Build | HMR Update |
59
- |------------|--------------|------------------|------------|
60
- | **SWC** | 1.2s | 0.1s | <50ms |
61
- | **esbuild** | 1.8s | 0.15s | <70ms |
62
- | **Babel** | 30s | 2-5s | 200-500ms |
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: 'swc'
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: 'esbuild'
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: 'babel'
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.
@@ -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 'shakapacker'
60
- import type { WebpackConfigWithDevServer } from 'shakapacker/types'
61
- import type { Configuration } from 'webpack'
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: ['.css', '.ts', '.tsx']
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 'shakapacker/types'
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: ['.css', '.ts', '.tsx']
99
+ extensions: [".css", ".ts", ".tsx"]
98
100
  }
99
101
  }
100
102
 
101
103
  // After (TypeScript)
102
- import type { Configuration } from 'webpack'
104
+ import type { Configuration } from "webpack"
103
105
 
104
106
  const customConfig: Configuration = {
105
107
  resolve: {
106
- extensions: ['.css', '.ts', '.tsx']
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 'webpack'
124
- import type { WebpackPluginInstance } from 'shakapacker/types'
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 'shakapacker'
138
- import type { WebpackConfigWithDevServer } from 'shakapacker/types'
139
+ import { generateWebpackConfig } from "shakapacker"
140
+ import type { WebpackConfigWithDevServer } from "shakapacker/types"
139
141
 
140
142
  const developmentConfig: WebpackConfigWithDevServer = generateWebpackConfig({
141
- devtool: 'eval-cheap-module-source-map',
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 'webpack'
158
+ import type { RuleSetRule } from "webpack"
157
159
 
158
160
  const customLoader: RuleSetRule = {
159
161
  test: /\.svg$/,
160
- use: ['@svgr/webpack']
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 'compression-webpack-plugin'
174
- import type { CompressionPluginOptions } from 'shakapacker/types'
175
+ import CompressionPlugin from "compression-webpack-plugin"
176
+ import type { CompressionPluginOptions } from "shakapacker/types"
175
177
 
176
178
  const compressionOptions: CompressionPluginOptions = {
177
- filename: '[path][base].gz',
178
- algorithm: 'gzip',
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 'webpack'
191
- import { env } from 'shakapacker'
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 'shakapacker/types'
212
- import { generateWebpackConfig } from 'shakapacker'
213
+ import type { RspackConfigWithDevServer } from "shakapacker/types"
214
+ import { generateWebpackConfig } from "shakapacker"
213
215
 
214
216
  const rspackConfig: RspackConfigWithDevServer = generateWebpackConfig({
215
- mode: 'development',
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 'my-custom-loader' {
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 { generateWebpackConfig, merge, config as shakapackerConfig } from 'shakapacker'
320
- import type { Configuration } from 'webpack'
321
- import type { WebpackConfigWithDevServer } from 'shakapacker/types'
322
- import CompressionPlugin from 'compression-webpack-plugin'
323
- import { resolve } from 'path'
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: ['.css', '.ts', '.tsx'],
337
+ extensions: [".css", ".ts", ".tsx"],
329
338
  alias: {
330
- '@': resolve(__dirname, '../../app/javascript'),
331
- 'components': resolve(__dirname, '../../app/javascript/components'),
332
- 'utils': resolve(__dirname, '../../app/javascript/utils')
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: ['@svgr/webpack'],
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 === 'production') {
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: '[path][base].br',
356
- algorithm: 'brotliCompress',
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 'shakapacker'
12
- import type { Configuration } from 'webpack'
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('shakapacker')
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 'shakapacker'
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 'shakapacker/rspack'
75
- import type { RspackOptions } from '@rspack/core'
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('custom-loader') as any]
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: 'esbuild'
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('shakapacker')
63
- const { ESBuildMinifyPlugin } = require('esbuild-loader')
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: 'es2015'
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: 'esnext'
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('shakapacker')
118
+ const { env } = require("shakapacker")
119
119
 
120
120
  const customConfig = {
121
121
  options: {
122
- jsxFragment: 'Fragment',
123
- jsxFactory: 'h'
122
+ jsxFragment: "Fragment",
123
+ jsxFactory: "h"
124
124
  }
125
125
  }
126
126