shakapacker 8.4.0 → 9.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (166) hide show
  1. checksums.yaml +4 -4
  2. data/.eslintignore +1 -0
  3. data/.eslintrc.fast.js +40 -0
  4. data/.eslintrc.js +48 -0
  5. data/.github/STATUS.md +1 -0
  6. data/.github/workflows/claude-code-review.yml +54 -0
  7. data/.github/workflows/claude.yml +50 -0
  8. data/.github/workflows/dummy.yml +8 -4
  9. data/.github/workflows/generator.yml +17 -14
  10. data/.github/workflows/node.yml +23 -1
  11. data/.github/workflows/ruby.yml +11 -0
  12. data/.github/workflows/test-bundlers.yml +170 -0
  13. data/.gitignore +17 -0
  14. data/.husky/pre-commit +2 -0
  15. data/.npmignore +56 -0
  16. data/.prettierignore +3 -0
  17. data/.rubocop.yml +1 -0
  18. data/.yalcignore +26 -0
  19. data/CHANGELOG.md +156 -18
  20. data/CLAUDE.md +29 -0
  21. data/CONTRIBUTING.md +138 -20
  22. data/Gemfile.lock +3 -3
  23. data/README.md +130 -5
  24. data/Rakefile +39 -4
  25. data/TODO.md +50 -0
  26. data/TODO_v9.md +87 -0
  27. data/conductor-setup.sh +70 -0
  28. data/conductor.json +7 -0
  29. data/docs/cdn_setup.md +379 -0
  30. data/docs/css-modules-export-mode.md +512 -0
  31. data/docs/deployment.md +10 -1
  32. data/docs/optional-peer-dependencies.md +198 -0
  33. data/docs/peer-dependencies.md +60 -0
  34. data/docs/rspack.md +190 -0
  35. data/docs/rspack_migration_guide.md +202 -0
  36. data/docs/transpiler-migration.md +188 -0
  37. data/docs/transpiler-performance.md +179 -0
  38. data/docs/troubleshooting.md +5 -0
  39. data/docs/typescript-migration.md +378 -0
  40. data/docs/typescript.md +99 -0
  41. data/docs/using_esbuild_loader.md +3 -3
  42. data/docs/using_swc_loader.md +5 -3
  43. data/docs/v6_upgrade.md +10 -0
  44. data/docs/v9_upgrade.md +413 -0
  45. data/lib/install/bin/shakapacker +3 -5
  46. data/lib/install/config/rspack/rspack.config.js +6 -0
  47. data/lib/install/config/rspack/rspack.config.ts +7 -0
  48. data/lib/install/config/shakapacker.yml +12 -2
  49. data/lib/install/config/webpack/webpack.config.ts +7 -0
  50. data/lib/install/package.json +38 -0
  51. data/lib/install/template.rb +194 -44
  52. data/lib/shakapacker/configuration.rb +141 -0
  53. data/lib/shakapacker/dev_server_runner.rb +25 -5
  54. data/lib/shakapacker/doctor.rb +844 -0
  55. data/lib/shakapacker/manifest.rb +4 -2
  56. data/lib/shakapacker/rspack_runner.rb +19 -0
  57. data/lib/shakapacker/runner.rb +144 -4
  58. data/lib/shakapacker/swc_migrator.rb +376 -0
  59. data/lib/shakapacker/utils/manager.rb +2 -0
  60. data/lib/shakapacker/version.rb +1 -1
  61. data/lib/shakapacker/version_checker.rb +1 -1
  62. data/lib/shakapacker/webpack_runner.rb +4 -42
  63. data/lib/shakapacker.rb +2 -1
  64. data/lib/tasks/shakapacker/doctor.rake +8 -0
  65. data/lib/tasks/shakapacker/install.rake +12 -2
  66. data/lib/tasks/shakapacker/migrate_to_swc.rake +13 -0
  67. data/lib/tasks/shakapacker.rake +1 -0
  68. data/package/.npmignore +4 -0
  69. data/package/babel/preset.ts +56 -0
  70. data/package/config.ts +175 -0
  71. data/package/{dev_server.js → dev_server.ts} +8 -5
  72. data/package/env.ts +92 -0
  73. data/package/environments/base.ts +138 -0
  74. data/package/environments/development.ts +90 -0
  75. data/package/environments/production.ts +80 -0
  76. data/package/environments/test.ts +53 -0
  77. data/package/environments/types.ts +90 -0
  78. data/package/esbuild/index.ts +42 -0
  79. data/package/index.d.ts +3 -97
  80. data/package/index.ts +52 -0
  81. data/package/loaders.d.ts +28 -0
  82. data/package/optimization/rspack.ts +36 -0
  83. data/package/optimization/webpack.ts +57 -0
  84. data/package/plugins/rspack.ts +103 -0
  85. data/package/plugins/webpack.ts +62 -0
  86. data/package/rspack/index.ts +64 -0
  87. data/package/rules/{babel.js → babel.ts} +2 -2
  88. data/package/rules/{coffee.js → coffee.ts} +1 -1
  89. data/package/rules/css.ts +3 -0
  90. data/package/rules/{erb.js → erb.ts} +1 -1
  91. data/package/rules/esbuild.ts +10 -0
  92. data/package/rules/file.ts +40 -0
  93. data/package/rules/{jscommon.js → jscommon.ts} +4 -4
  94. data/package/rules/{less.js → less.ts} +4 -4
  95. data/package/rules/raw.ts +25 -0
  96. data/package/rules/rspack.ts +176 -0
  97. data/package/rules/{sass.js → sass.ts} +7 -3
  98. data/package/rules/{stylus.js → stylus.ts} +4 -8
  99. data/package/rules/swc.ts +10 -0
  100. data/package/rules/{index.js → webpack.ts} +1 -1
  101. data/package/swc/index.ts +54 -0
  102. data/package/types/README.md +87 -0
  103. data/package/types/index.ts +60 -0
  104. data/package/types.ts +108 -0
  105. data/package/utils/configPath.ts +6 -0
  106. data/package/utils/debug.ts +49 -0
  107. data/package/utils/defaultConfigPath.ts +4 -0
  108. data/package/utils/errorCodes.ts +219 -0
  109. data/package/utils/errorHelpers.ts +143 -0
  110. data/package/utils/getStyleRule.ts +64 -0
  111. data/package/utils/helpers.ts +85 -0
  112. data/package/utils/{inliningCss.js → inliningCss.ts} +3 -3
  113. data/package/utils/pathValidation.ts +139 -0
  114. data/package/utils/requireOrError.ts +15 -0
  115. data/package/utils/snakeToCamelCase.ts +5 -0
  116. data/package/utils/typeGuards.ts +342 -0
  117. data/package/utils/validateDependencies.ts +61 -0
  118. data/package/webpack-types.d.ts +33 -0
  119. data/package/webpackDevServerConfig.ts +117 -0
  120. data/package.json +134 -9
  121. data/scripts/remove-use-strict.js +45 -0
  122. data/scripts/type-check-no-emit.js +27 -0
  123. data/test/package/config.test.js +3 -0
  124. data/test/package/env.test.js +42 -7
  125. data/test/package/environments/base.test.js +5 -1
  126. data/test/package/rules/babel.test.js +16 -0
  127. data/test/package/rules/esbuild.test.js +1 -1
  128. data/test/package/rules/raw.test.js +40 -7
  129. data/test/package/rules/swc.test.js +1 -1
  130. data/test/package/rules/webpack.test.js +35 -0
  131. data/test/package/staging.test.js +4 -3
  132. data/test/package/transpiler-defaults.test.js +127 -0
  133. data/test/peer-dependencies.sh +85 -0
  134. data/test/scripts/remove-use-strict.test.js +125 -0
  135. data/test/typescript/build.test.js +118 -0
  136. data/test/typescript/environments.test.js +107 -0
  137. data/test/typescript/pathValidation.test.js +142 -0
  138. data/test/typescript/securityValidation.test.js +182 -0
  139. data/tools/README.md +124 -0
  140. data/tools/css-modules-v9-codemod.js +179 -0
  141. data/tsconfig.eslint.json +16 -0
  142. data/tsconfig.json +38 -0
  143. data/yarn.lock +2704 -767
  144. metadata +111 -41
  145. data/package/babel/preset.js +0 -48
  146. data/package/config.js +0 -56
  147. data/package/env.js +0 -48
  148. data/package/environments/base.js +0 -171
  149. data/package/environments/development.js +0 -13
  150. data/package/environments/production.js +0 -88
  151. data/package/environments/test.js +0 -3
  152. data/package/esbuild/index.js +0 -40
  153. data/package/index.js +0 -40
  154. data/package/rules/css.js +0 -3
  155. data/package/rules/esbuild.js +0 -10
  156. data/package/rules/file.js +0 -29
  157. data/package/rules/raw.js +0 -5
  158. data/package/rules/swc.js +0 -10
  159. data/package/swc/index.js +0 -50
  160. data/package/utils/configPath.js +0 -4
  161. data/package/utils/defaultConfigPath.js +0 -2
  162. data/package/utils/getStyleRule.js +0 -40
  163. data/package/utils/helpers.js +0 -62
  164. data/package/utils/snakeToCamelCase.js +0 -5
  165. data/package/webpackDevServerConfig.js +0 -71
  166. data/test/package/rules/index.test.js +0 -16
@@ -0,0 +1,378 @@
1
+ # TypeScript Migration Guide for Shakapacker
2
+
3
+ This guide helps you adopt TypeScript types in your Shakapacker configuration files for better type safety and IDE support.
4
+
5
+ ## Table of Contents
6
+ - [Benefits](#benefits)
7
+ - [Quick Start](#quick-start)
8
+ - [Migration Steps](#migration-steps)
9
+ - [Common Patterns](#common-patterns)
10
+ - [Troubleshooting](#troubleshooting)
11
+
12
+ ## Benefits
13
+
14
+ Using TypeScript with Shakapacker provides:
15
+ - **Type Safety**: Catch configuration errors at compile time
16
+ - **IDE Support**: Get autocompletion and inline documentation
17
+ - **Better Refactoring**: Safely rename and restructure configurations
18
+ - **Self-documenting**: Types serve as inline documentation
19
+
20
+ ## Quick Start
21
+
22
+ ### 1. Install TypeScript Dependencies
23
+
24
+ ```bash
25
+ yarn add --dev typescript @types/node @types/webpack
26
+ # or
27
+ npm install --save-dev typescript @types/node @types/webpack
28
+ ```
29
+
30
+ ### 2. Create a tsconfig.json
31
+
32
+ ```json
33
+ {
34
+ "compilerOptions": {
35
+ "target": "ES2020",
36
+ "module": "commonjs",
37
+ "lib": ["ES2020"],
38
+ "strict": true,
39
+ "esModuleInterop": true,
40
+ "skipLibCheck": true,
41
+ "forceConsistentCasingInFileNames": true,
42
+ "resolveJsonModule": true,
43
+ "moduleResolution": "node",
44
+ "allowJs": true,
45
+ "checkJs": false,
46
+ "noEmit": true
47
+ },
48
+ "include": ["config/webpack/**/*"],
49
+ "exclude": ["node_modules"]
50
+ }
51
+ ```
52
+
53
+ ### 3. Convert Your Webpack Config to TypeScript
54
+
55
+ Rename `config/webpack/webpack.config.js` to `config/webpack/webpack.config.ts`:
56
+
57
+ ```typescript
58
+ // config/webpack/webpack.config.ts
59
+ import { generateWebpackConfig, merge } from 'shakapacker'
60
+ import type { WebpackConfigWithDevServer } from 'shakapacker/types'
61
+ import type { Configuration } from 'webpack'
62
+
63
+ const customConfig: Configuration = {
64
+ resolve: {
65
+ extensions: ['.css', '.ts', '.tsx']
66
+ }
67
+ }
68
+
69
+ const config: Configuration = generateWebpackConfig(customConfig)
70
+
71
+ export default config
72
+ ```
73
+
74
+ ## Migration Steps
75
+
76
+ ### Step 1: Import Types
77
+
78
+ Start by importing the types you need:
79
+
80
+ ```typescript
81
+ import type {
82
+ Config,
83
+ WebpackConfigWithDevServer,
84
+ RspackConfigWithDevServer,
85
+ CompressionPluginOptions
86
+ } from 'shakapacker/types'
87
+ ```
88
+
89
+ ### Step 2: Type Your Configuration Objects
90
+
91
+ Add type annotations to your configuration objects:
92
+
93
+ ```typescript
94
+ // Before (JavaScript)
95
+ const customConfig = {
96
+ resolve: {
97
+ extensions: ['.css', '.ts', '.tsx']
98
+ }
99
+ }
100
+
101
+ // After (TypeScript)
102
+ import type { Configuration } from 'webpack'
103
+
104
+ const customConfig: Configuration = {
105
+ resolve: {
106
+ extensions: ['.css', '.ts', '.tsx']
107
+ }
108
+ }
109
+ ```
110
+
111
+ ### Step 3: Type Your Custom Functions
112
+
113
+ If you have custom configuration functions, add type annotations:
114
+
115
+ ```typescript
116
+ // Before (JavaScript)
117
+ function modifyConfig(config) {
118
+ config.plugins.push(new MyPlugin())
119
+ return config
120
+ }
121
+
122
+ // After (TypeScript)
123
+ import type { Configuration } from 'webpack'
124
+ import type { WebpackPluginInstance } from 'shakapacker/types'
125
+
126
+ function modifyConfig(config: Configuration): Configuration {
127
+ const plugins = config.plugins as WebpackPluginInstance[]
128
+ plugins.push(new MyPlugin())
129
+ return config
130
+ }
131
+ ```
132
+
133
+ ### Step 4: Handle Environment-Specific Configurations
134
+
135
+ ```typescript
136
+ // config/webpack/development.ts
137
+ import { generateWebpackConfig } from 'shakapacker'
138
+ import type { WebpackConfigWithDevServer } from 'shakapacker/types'
139
+
140
+ const developmentConfig: WebpackConfigWithDevServer = generateWebpackConfig({
141
+ devtool: 'eval-cheap-module-source-map',
142
+ devServer: {
143
+ hot: true,
144
+ port: 3035
145
+ }
146
+ })
147
+
148
+ export default developmentConfig
149
+ ```
150
+
151
+ ## Common Patterns
152
+
153
+ ### Pattern 1: Custom Loaders
154
+
155
+ ```typescript
156
+ import type { RuleSetRule } from 'webpack'
157
+
158
+ const customLoader: RuleSetRule = {
159
+ test: /\.svg$/,
160
+ use: ['@svgr/webpack']
161
+ }
162
+
163
+ const config: Configuration = generateWebpackConfig({
164
+ module: {
165
+ rules: [customLoader]
166
+ }
167
+ })
168
+ ```
169
+
170
+ ### Pattern 2: Plugin Configuration
171
+
172
+ ```typescript
173
+ import CompressionPlugin from 'compression-webpack-plugin'
174
+ import type { CompressionPluginOptions } from 'shakapacker/types'
175
+
176
+ const compressionOptions: CompressionPluginOptions = {
177
+ filename: '[path][base].gz',
178
+ algorithm: 'gzip',
179
+ test: /\.(js|css|html|json|ico|svg|eot|otf|ttf)$/
180
+ }
181
+
182
+ const config: Configuration = generateWebpackConfig({
183
+ plugins: [new CompressionPlugin(compressionOptions)]
184
+ })
185
+ ```
186
+
187
+ ### Pattern 3: Conditional Configuration
188
+
189
+ ```typescript
190
+ import type { Configuration } from 'webpack'
191
+ import { env } from 'shakapacker'
192
+
193
+ const config: Configuration = generateWebpackConfig()
194
+
195
+ if (env.isProduction) {
196
+ // TypeScript knows config.optimization exists
197
+ config.optimization = {
198
+ ...config.optimization,
199
+ minimize: true,
200
+ sideEffects: false
201
+ }
202
+ }
203
+
204
+ export default config
205
+ ```
206
+
207
+ ### Pattern 4: Rspack Configuration
208
+
209
+ ```typescript
210
+ // config/rspack/rspack.config.ts
211
+ import type { RspackConfigWithDevServer } from 'shakapacker/types'
212
+ import { generateWebpackConfig } from 'shakapacker'
213
+
214
+ const rspackConfig: RspackConfigWithDevServer = generateWebpackConfig({
215
+ mode: 'development',
216
+ devServer: {
217
+ hot: true,
218
+ port: 3036
219
+ }
220
+ })
221
+
222
+ export default rspackConfig
223
+ ```
224
+
225
+ ## Type-checking Your Configuration
226
+
227
+ Add a script to your package.json to type-check your configuration:
228
+
229
+ ```json
230
+ {
231
+ "scripts": {
232
+ "type-check": "tsc --noEmit",
233
+ "webpack:type-check": "tsc --noEmit config/webpack/*.ts"
234
+ }
235
+ }
236
+ ```
237
+
238
+ Run type checking:
239
+
240
+ ```bash
241
+ yarn type-check
242
+ # or
243
+ npm run type-check
244
+ ```
245
+
246
+ ## Available Types Reference
247
+
248
+ ### Core Types
249
+ - `Config` - Shakapacker configuration from shakapacker.yml
250
+ - `Env` - Environment variables and helpers
251
+ - `DevServerConfig` - Development server configuration
252
+
253
+ ### Webpack/Rspack Types
254
+ - `WebpackConfigWithDevServer` - Webpack configuration with dev server
255
+ - `RspackConfigWithDevServer` - Rspack configuration with dev server
256
+ - `WebpackPluginInstance` - Webpack plugin instance type
257
+ - `RspackPlugin` - Rspack plugin interface
258
+
259
+ ### Helper Types
260
+ - `CompressionPluginOptions` - Compression plugin configuration
261
+ - `ReactRefreshWebpackPlugin` - React refresh for Webpack
262
+ - `ReactRefreshRspackPlugin` - React refresh for Rspack
263
+
264
+ ## Troubleshooting
265
+
266
+ ### Issue: "Cannot find module 'shakapacker/types'"
267
+
268
+ **Solution**: Make sure you're using Shakapacker v9.0.0 or later:
269
+
270
+ ```bash
271
+ yarn upgrade shakapacker
272
+ ```
273
+
274
+ ### Issue: Type errors with plugins
275
+
276
+ **Solution**: Cast plugin arrays when needed:
277
+
278
+ ```typescript
279
+ const plugins = (config.plugins || []) as WebpackPluginInstance[]
280
+ plugins.push(new MyPlugin())
281
+ ```
282
+
283
+ ### Issue: Missing types for custom loaders
284
+
285
+ **Solution**: Install type definitions or declare them:
286
+
287
+ ```typescript
288
+ // If types aren't available, declare them
289
+ declare module 'my-custom-loader' {
290
+ const loader: any
291
+ export default loader
292
+ }
293
+ ```
294
+
295
+ ### Issue: Conflicting types between webpack versions
296
+
297
+ **Solution**: Ensure your webpack types match your webpack version:
298
+
299
+ ```bash
300
+ yarn add --dev @types/webpack@^5
301
+ ```
302
+
303
+ ## Gradual Migration
304
+
305
+ You don't need to convert everything at once. Start with:
306
+
307
+ 1. Convert your main webpack.config.js to TypeScript
308
+ 2. Add types to the most complex configurations
309
+ 3. Gradually type other configuration files
310
+ 4. Add type checking to your CI pipeline
311
+
312
+ ## Example: Full Configuration
313
+
314
+ Here's a complete example of a typed webpack configuration:
315
+
316
+ ```typescript
317
+ // config/webpack/webpack.config.ts
318
+ import { generateWebpackConfig, merge, config as shakapackerConfig } from 'shakapacker'
319
+ import type { Configuration } from 'webpack'
320
+ import type { WebpackConfigWithDevServer } from 'shakapacker/types'
321
+ import CompressionPlugin from 'compression-webpack-plugin'
322
+ import { resolve } from 'path'
323
+
324
+ // Type-safe custom configuration
325
+ const customConfig: Configuration = {
326
+ resolve: {
327
+ extensions: ['.css', '.ts', '.tsx'],
328
+ alias: {
329
+ '@': resolve(__dirname, '../../app/javascript'),
330
+ 'components': resolve(__dirname, '../../app/javascript/components'),
331
+ 'utils': resolve(__dirname, '../../app/javascript/utils')
332
+ }
333
+ },
334
+ module: {
335
+ rules: [
336
+ {
337
+ test: /\.svg$/,
338
+ use: ['@svgr/webpack'],
339
+ issuer: /\.(tsx?|jsx?)$/
340
+ }
341
+ ]
342
+ }
343
+ }
344
+
345
+ // Generate the final configuration
346
+ const webpackConfig: Configuration = generateWebpackConfig(customConfig)
347
+
348
+ // Type-safe modifications based on environment
349
+ if (shakapackerConfig.env === 'production') {
350
+ const plugins = (webpackConfig.plugins || []) as WebpackPluginInstance[]
351
+
352
+ plugins.push(
353
+ new CompressionPlugin({
354
+ filename: '[path][base].br',
355
+ algorithm: 'brotliCompress',
356
+ test: /\.(js|css|html|json|ico|svg|eot|otf|ttf)$/
357
+ })
358
+ )
359
+ }
360
+
361
+ export default webpackConfig
362
+ ```
363
+
364
+ ## Next Steps
365
+
366
+ After migrating to TypeScript:
367
+
368
+ 1. **Enable strict checks**: Gradually enable stricter TypeScript options
369
+ 2. **Add custom types**: Create type definitions for your application-specific configurations
370
+ 3. **Share types**: Export reusable configuration types for your team
371
+ 4. **Document with types**: Use JSDoc comments with your types for better documentation
372
+
373
+ ## Resources
374
+
375
+ - [TypeScript Handbook](https://www.typescriptlang.org/docs/handbook/intro.html)
376
+ - [Webpack TypeScript Configuration](https://webpack.js.org/configuration/configuration-languages/#typescript)
377
+ - [Shakapacker Types Documentation](./types/README.md)
378
+ - [Migration Examples](https://github.com/shakacode/shakapacker/tree/main/examples/typescript-config)
@@ -0,0 +1,99 @@
1
+ # TypeScript Support
2
+
3
+ Shakapacker v9 includes TypeScript support, providing type safety and better IDE experience for your webpack configurations.
4
+
5
+ ## Quick Start
6
+
7
+ ### Using TypeScript Config
8
+
9
+ ```typescript
10
+ // webpack.config.ts
11
+ import { generateWebpackConfig } from 'shakapacker'
12
+ import type { Configuration } from 'webpack'
13
+
14
+ const config: Configuration = generateWebpackConfig({
15
+ // Your config with full type safety
16
+ })
17
+
18
+ export default config
19
+ ```
20
+
21
+ ### Using JSDoc (JavaScript)
22
+
23
+ ```javascript
24
+ // webpack.config.js
25
+ const { generateWebpackConfig } = require('shakapacker')
26
+
27
+ /** @type {import('webpack').Configuration} */
28
+ const config = {
29
+ // Still get autocomplete in JS files!
30
+ }
31
+
32
+ module.exports = generateWebpackConfig(config)
33
+ ```
34
+
35
+ ## Benefits
36
+
37
+ - **Compile-time error detection** - Catch config errors before runtime
38
+ - **IDE autocomplete** - Full IntelliSense for all options
39
+ - **Type safety** - Prevents 85-100% of common configuration errors
40
+ - **No breaking changes** - Fully backward compatible
41
+
42
+ ## Migration
43
+
44
+ 1. **No migration required** - Existing JavaScript configs continue to work
45
+ 2. **Optional TypeScript** - Use it only if you want the benefits
46
+ 3. **Gradual adoption** - Start with JSDoc comments, move to TypeScript later
47
+
48
+ ## IDE Setup
49
+
50
+ ### VS Code
51
+ - Install TypeScript extension (built-in)
52
+ - Set `"typescript.tsdk": "node_modules/typescript/lib"` in settings
53
+
54
+ ### WebStorm/IntelliJ
55
+ - Enable TypeScript service in Settings → Languages & Frameworks → TypeScript
56
+
57
+ ## Common Patterns
58
+
59
+ ### Environment-Specific Config
60
+
61
+ ```typescript
62
+ import { generateWebpackConfig, env } from 'shakapacker'
63
+
64
+ const config = generateWebpackConfig({
65
+ optimization: {
66
+ minimize: env.isProduction
67
+ }
68
+ })
69
+ ```
70
+
71
+ ### Rspack Config
72
+
73
+ ```typescript
74
+ import { generateRspackConfig } from 'shakapacker/rspack'
75
+ import type { RspackOptions } from '@rspack/core'
76
+
77
+ const config: RspackOptions = {
78
+ // Rspack-specific config
79
+ }
80
+
81
+ export default generateRspackConfig(config)
82
+ ```
83
+
84
+ ## Troubleshooting
85
+
86
+ **Cannot find module 'shakapacker'**
87
+ ```typescript
88
+ /// <reference types="shakapacker" />
89
+ ```
90
+
91
+ **Type errors with custom loaders**
92
+ ```typescript
93
+ use: [require.resolve('custom-loader') as any]
94
+ ```
95
+
96
+ ## Further Reading
97
+
98
+ - [Webpack TypeScript Documentation](https://webpack.js.org/configuration/configuration-languages/#typescript)
99
+ - [TypeScript Handbook](https://www.typescriptlang.org/docs/)
@@ -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 `webpack_loader` value in your default `shakapacker.yml` config to `esbuild`
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 loader to use, available options are 'babel' (default), 'swc' or 'esbuild'
50
- webpack_loader: 'esbuild'
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
@@ -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 `webpack_loader` value in your default `shakapacker.yml` config to `swc`
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 loader to use, available options are 'babel' (default) or 'swc'
45
- webpack_loader: 'swc'
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/docs/v6_upgrade.md CHANGED
@@ -101,6 +101,16 @@ _If you're on webpacker v5, follow [how to upgrade to webpacker v6.0.0.rc.6 from
101
101
 
102
102
  1. Update `webpack-dev-server` to the current version, greater than 4.2, updating `package.json`.
103
103
 
104
+ **Important:** If you encounter the error `[webpack-cli] Invalid options object. Dev Server has been initialized using an options object that does not match the API schema` with an unknown property `_assetEmittingPreviousFiles`, this indicates your webpack-dev-server configuration contains deprecated options.
105
+
106
+ To resolve this issue:
107
+ - Ensure you're using webpack-cli >= 4.7.0 with webpack-dev-server 5.x (webpack-cli 4.7+ is compatible with webpack-dev-server v5)
108
+ - Check your current versions: `npm list webpack-cli webpack-dev-server`
109
+ - Remove any legacy options like `_assetEmittingPreviousFiles` from your dev-server configuration
110
+ - Review the [webpack-dev-server migration guide](https://github.com/webpack/webpack-dev-server/blob/master/migration-v5.md) for proper v4 to v5 migration steps
111
+
112
+ See [issue #526](https://github.com/shakacode/shakapacker/issues/526) for more details.
113
+
104
114
  1. Update API usage of the view helpers by changing `javascript_packs_with_chunks_tag` and `stylesheet_packs_with_chunks_tag` to `javascript_pack_tag` and `stylesheet_pack_tag`. Ensure that your layouts and views will only have **at most one call** to `javascript_pack_tag` and **at most one call** to `stylesheet_pack_tag`. You can now pass multiple bundles to these view helper methods. If you fail to changes this, you may experience performance issues, and other bugs related to multiple copies of React, like [issue 2932](https://github.com/rails/webpacker/issues/2932). If you expose jquery globally with `expose-loader` by using `import $ from "expose-loader?exposes=$,jQuery!jquery"` in your `app/javascript/application.js`, pass the option `defer: false` to your `javascript_pack_tag`.
105
115
 
106
116
  1. If you are using any integrations like `css`, `postcss`, `React` or `TypeScript`. Please see https://github.com/shakacode/shakapacker#integrations section on how they work in v6.