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
@@ -0,0 +1,630 @@
|
|
1
|
+
# Shakapacker Configuration Guide
|
2
|
+
|
3
|
+
This guide covers all configuration options available in `config/shakapacker.yml` and how to use them effectively.
|
4
|
+
|
5
|
+
## Table of Contents
|
6
|
+
|
7
|
+
- [Basic Configuration](#basic-configuration)
|
8
|
+
- [Source Configuration](#source-configuration)
|
9
|
+
- [Output Configuration](#output-configuration)
|
10
|
+
- [Bundler Configuration](#bundler-configuration)
|
11
|
+
- [Development Server](#development-server)
|
12
|
+
- [Compilation Options](#compilation-options)
|
13
|
+
- [Advanced Options](#advanced-options)
|
14
|
+
- [Environment-Specific Configuration](#environment-specific-configuration)
|
15
|
+
|
16
|
+
## Basic Configuration
|
17
|
+
|
18
|
+
### `assets_bundler`
|
19
|
+
|
20
|
+
**Type:** `string`
|
21
|
+
**Default:** `"webpack"`
|
22
|
+
**Options:** `"webpack"` or `"rspack"`
|
23
|
+
|
24
|
+
Specifies which bundler to use for compiling assets.
|
25
|
+
|
26
|
+
```yaml
|
27
|
+
# Use webpack (default)
|
28
|
+
assets_bundler: "webpack"
|
29
|
+
|
30
|
+
# Use rspack for faster builds
|
31
|
+
assets_bundler: "rspack"
|
32
|
+
```
|
33
|
+
|
34
|
+
See [RSpack Migration Guide](rspack_migration_guide.md) for details on switching bundlers.
|
35
|
+
|
36
|
+
### `assets_bundler_config_path`
|
37
|
+
|
38
|
+
**Type:** `string`
|
39
|
+
**Default:** `"config/webpack"` for webpack, `"config/rspack"` for rspack
|
40
|
+
|
41
|
+
Specifies the directory containing your webpack/rspack config files.
|
42
|
+
|
43
|
+
```yaml
|
44
|
+
# Use default paths (config/webpack or config/rspack)
|
45
|
+
# assets_bundler_config_path: config/webpack
|
46
|
+
|
47
|
+
# Use custom directory
|
48
|
+
assets_bundler_config_path: "build_configs"
|
49
|
+
|
50
|
+
# Use project root directory
|
51
|
+
assets_bundler_config_path: "."
|
52
|
+
```
|
53
|
+
|
54
|
+
**When to use:**
|
55
|
+
|
56
|
+
- When migrating from another build tool and want to preserve existing config locations
|
57
|
+
- When organizing configs in a monorepo structure
|
58
|
+
- When following custom project conventions
|
59
|
+
|
60
|
+
### `javascript_transpiler`
|
61
|
+
|
62
|
+
**Type:** `string`
|
63
|
+
**Default:** `"swc"` (or `"babel"` for webpack when not specified)
|
64
|
+
**Options:** `"swc"`, `"babel"`, or `"esbuild"`
|
65
|
+
|
66
|
+
Specifies which transpiler to use for JavaScript/TypeScript.
|
67
|
+
|
68
|
+
```yaml
|
69
|
+
# Use SWC (recommended - 20x faster than Babel)
|
70
|
+
javascript_transpiler: "swc"
|
71
|
+
|
72
|
+
# Use Babel (for maximum compatibility)
|
73
|
+
javascript_transpiler: "babel"
|
74
|
+
|
75
|
+
# Use esbuild (fastest, but may have compatibility issues)
|
76
|
+
javascript_transpiler: "esbuild"
|
77
|
+
```
|
78
|
+
|
79
|
+
**Note:** When using rspack, swc is used automatically regardless of this setting due to built-in support.
|
80
|
+
|
81
|
+
See [Transpiler Performance Guide](transpiler-performance.md) for benchmarks and migration guides.
|
82
|
+
|
83
|
+
## Source Configuration
|
84
|
+
|
85
|
+
### `source_path`
|
86
|
+
|
87
|
+
**Type:** `string`
|
88
|
+
**Default:** `"app/javascript"`
|
89
|
+
|
90
|
+
The root directory for your JavaScript source files.
|
91
|
+
|
92
|
+
```yaml
|
93
|
+
# Default
|
94
|
+
source_path: app/javascript
|
95
|
+
|
96
|
+
# Custom location
|
97
|
+
source_path: app/frontend
|
98
|
+
```
|
99
|
+
|
100
|
+
### `source_entry_path`
|
101
|
+
|
102
|
+
**Type:** `string`
|
103
|
+
**Default:** `"packs"`
|
104
|
+
|
105
|
+
Subdirectory within `source_path` containing entry points.
|
106
|
+
|
107
|
+
```yaml
|
108
|
+
# Recommended: use a subdirectory
|
109
|
+
source_entry_path: packs
|
110
|
+
|
111
|
+
# Use the entire source_path as entry directory
|
112
|
+
source_entry_path: /
|
113
|
+
```
|
114
|
+
|
115
|
+
**Note:** Cannot use `/` when `nested_entries` is `true`.
|
116
|
+
|
117
|
+
### `nested_entries`
|
118
|
+
|
119
|
+
**Type:** `boolean`
|
120
|
+
**Default:** `true`
|
121
|
+
|
122
|
+
Whether to automatically discover entry points in subdirectories within `source_entry_path`.
|
123
|
+
|
124
|
+
```yaml
|
125
|
+
# Enable nested entries (recommended)
|
126
|
+
nested_entries: true
|
127
|
+
|
128
|
+
# Disable - only top-level files are entries
|
129
|
+
nested_entries: false
|
130
|
+
```
|
131
|
+
|
132
|
+
**Example with nested entries:**
|
133
|
+
|
134
|
+
```
|
135
|
+
app/javascript/packs/
|
136
|
+
application.js # Entry: application
|
137
|
+
admin/
|
138
|
+
dashboard.js # Entry: admin/dashboard
|
139
|
+
```
|
140
|
+
|
141
|
+
### `additional_paths`
|
142
|
+
|
143
|
+
**Type:** `array`
|
144
|
+
**Default:** `[]`
|
145
|
+
|
146
|
+
Additional directories for webpack/rspack to search for modules.
|
147
|
+
|
148
|
+
```yaml
|
149
|
+
additional_paths:
|
150
|
+
- app/assets
|
151
|
+
- vendor/assets
|
152
|
+
- node_modules/legacy-lib
|
153
|
+
```
|
154
|
+
|
155
|
+
**Use cases:**
|
156
|
+
|
157
|
+
- Resolving modules from Rails asset directories
|
158
|
+
- Including vendored JavaScript
|
159
|
+
- Sharing code between engines
|
160
|
+
|
161
|
+
## Output Configuration
|
162
|
+
|
163
|
+
### `public_root_path`
|
164
|
+
|
165
|
+
**Type:** `string`
|
166
|
+
**Default:** `"public"`
|
167
|
+
|
168
|
+
The public directory where assets are served from.
|
169
|
+
|
170
|
+
```yaml
|
171
|
+
public_root_path: public
|
172
|
+
```
|
173
|
+
|
174
|
+
### `public_output_path`
|
175
|
+
|
176
|
+
**Type:** `string`
|
177
|
+
**Default:** `"packs"`
|
178
|
+
|
179
|
+
Subdirectory within `public_root_path` for compiled assets.
|
180
|
+
|
181
|
+
```yaml
|
182
|
+
# Default - outputs to public/packs
|
183
|
+
public_output_path: packs
|
184
|
+
|
185
|
+
# Custom output directory
|
186
|
+
public_output_path: webpack-bundles
|
187
|
+
```
|
188
|
+
|
189
|
+
### `private_output_path`
|
190
|
+
|
191
|
+
**Type:** `string`
|
192
|
+
**Default:** `nil`
|
193
|
+
|
194
|
+
Directory for private server-side bundles (e.g., for SSR) that should not be publicly accessible.
|
195
|
+
|
196
|
+
```yaml
|
197
|
+
# Enable private output for SSR bundles
|
198
|
+
private_output_path: ssr-generated
|
199
|
+
```
|
200
|
+
|
201
|
+
**Important:** Must be different from `public_output_path` to prevent serving private bundles.
|
202
|
+
|
203
|
+
### `manifest_path`
|
204
|
+
|
205
|
+
**Type:** `string`
|
206
|
+
**Default:** `"{public_output_path}/manifest.json"`
|
207
|
+
|
208
|
+
Location of the manifest.json file that maps entry points to compiled assets.
|
209
|
+
|
210
|
+
```yaml
|
211
|
+
# Custom manifest location
|
212
|
+
manifest_path: public/assets/webpack-manifest.json
|
213
|
+
```
|
214
|
+
|
215
|
+
**Note:** Rarely needs to be changed from the default.
|
216
|
+
|
217
|
+
### `cache_path`
|
218
|
+
|
219
|
+
**Type:** `string`
|
220
|
+
**Default:** `"tmp/shakapacker"`
|
221
|
+
|
222
|
+
Directory for webpack/rspack cache files.
|
223
|
+
|
224
|
+
```yaml
|
225
|
+
cache_path: tmp/shakapacker
|
226
|
+
|
227
|
+
# Use a shared cache in CI
|
228
|
+
cache_path: /mnt/shared/webpack-cache
|
229
|
+
```
|
230
|
+
|
231
|
+
## Bundler Configuration
|
232
|
+
|
233
|
+
### `webpack_compile_output`
|
234
|
+
|
235
|
+
**Type:** `boolean`
|
236
|
+
**Default:** `true`
|
237
|
+
|
238
|
+
Whether to show webpack/rspack compilation output in the console.
|
239
|
+
|
240
|
+
```yaml
|
241
|
+
# Show detailed output (helpful for debugging)
|
242
|
+
webpack_compile_output: true
|
243
|
+
|
244
|
+
# Minimal output (cleaner logs)
|
245
|
+
webpack_compile_output: false
|
246
|
+
```
|
247
|
+
|
248
|
+
### `useContentHash`
|
249
|
+
|
250
|
+
**Type:** `boolean`
|
251
|
+
**Default:** `false` (development), `true` (production - enforced)
|
252
|
+
|
253
|
+
Whether to include content hashes in asset filenames for cache busting.
|
254
|
+
|
255
|
+
```yaml
|
256
|
+
# Production only (default)
|
257
|
+
useContentHash: false
|
258
|
+
|
259
|
+
# Always use content hash (not recommended for development)
|
260
|
+
useContentHash: true
|
261
|
+
```
|
262
|
+
|
263
|
+
**Note:** In production, this is always `true` regardless of configuration.
|
264
|
+
|
265
|
+
### `css_extract_ignore_order_warnings`
|
266
|
+
|
267
|
+
**Type:** `boolean`
|
268
|
+
**Default:** `false`
|
269
|
+
|
270
|
+
Whether to suppress mini-css-extract-plugin order warnings.
|
271
|
+
|
272
|
+
```yaml
|
273
|
+
# Enable if you have consistent CSS scoping
|
274
|
+
css_extract_ignore_order_warnings: true
|
275
|
+
```
|
276
|
+
|
277
|
+
**When to enable:**
|
278
|
+
|
279
|
+
- When using CSS modules or scoped styles
|
280
|
+
- When following BEM or similar naming conventions
|
281
|
+
- When order warnings are false positives
|
282
|
+
|
283
|
+
## Development Server
|
284
|
+
|
285
|
+
### `dev_server`
|
286
|
+
|
287
|
+
Configuration for `bin/shakapacker-dev-server`. See [Dev Server Options](#dev-server-options) below.
|
288
|
+
|
289
|
+
#### Dev Server Options
|
290
|
+
|
291
|
+
```yaml
|
292
|
+
dev_server:
|
293
|
+
# Host to bind to
|
294
|
+
host: localhost
|
295
|
+
|
296
|
+
# Port to listen on
|
297
|
+
port: 3035
|
298
|
+
|
299
|
+
# Enable HTTPS
|
300
|
+
# server: https
|
301
|
+
|
302
|
+
# Hot Module Replacement
|
303
|
+
hmr: false
|
304
|
+
|
305
|
+
# Live reload (alternative to HMR)
|
306
|
+
# live_reload: true
|
307
|
+
|
308
|
+
# Inline CSS with HMR (requires style-loader)
|
309
|
+
inline_css: true
|
310
|
+
|
311
|
+
# Compression
|
312
|
+
compress: true
|
313
|
+
|
314
|
+
# Allowed hosts (security)
|
315
|
+
allowed_hosts: "auto"
|
316
|
+
|
317
|
+
# Client configuration
|
318
|
+
client:
|
319
|
+
# Show error overlay
|
320
|
+
overlay: true
|
321
|
+
|
322
|
+
# Custom WebSocket URL
|
323
|
+
# webSocketURL:
|
324
|
+
# hostname: '0.0.0.0'
|
325
|
+
# pathname: '/ws'
|
326
|
+
# port: 8080
|
327
|
+
|
328
|
+
# Headers for CORS
|
329
|
+
headers:
|
330
|
+
"Access-Control-Allow-Origin": "*"
|
331
|
+
|
332
|
+
# Static file serving
|
333
|
+
static:
|
334
|
+
watch:
|
335
|
+
ignored: "**/node_modules/**"
|
336
|
+
```
|
337
|
+
|
338
|
+
**Key Options:**
|
339
|
+
|
340
|
+
- **hmr:** Hot Module Replacement updates modules without full reload. Requires additional setup.
|
341
|
+
- **inline_css:** With HMR, CSS is delivered via JavaScript. Set to `false` to use `<link>` tags.
|
342
|
+
- **overlay:** Shows errors/warnings in browser overlay. Helpful for development.
|
343
|
+
- **allowed_hosts:** Protects against DNS rebinding attacks. Use `"all"` to disable (not recommended).
|
344
|
+
|
345
|
+
## Compilation Options
|
346
|
+
|
347
|
+
### `compile`
|
348
|
+
|
349
|
+
**Type:** `boolean`
|
350
|
+
**Environment-specific**
|
351
|
+
|
352
|
+
Whether to compile assets on-demand when requests are made.
|
353
|
+
|
354
|
+
```yaml
|
355
|
+
development:
|
356
|
+
compile: true # Compile on demand
|
357
|
+
|
358
|
+
production:
|
359
|
+
compile: false # Assets must be precompiled
|
360
|
+
```
|
361
|
+
|
362
|
+
### `shakapacker_precompile`
|
363
|
+
|
364
|
+
**Type:** `boolean`
|
365
|
+
**Default:** `true`
|
366
|
+
|
367
|
+
Whether `rails assets:precompile` should compile webpack/rspack assets.
|
368
|
+
|
369
|
+
```yaml
|
370
|
+
# Include in assets:precompile (recommended)
|
371
|
+
shakapacker_precompile: true
|
372
|
+
|
373
|
+
# Skip webpack compilation during assets:precompile
|
374
|
+
shakapacker_precompile: false
|
375
|
+
```
|
376
|
+
|
377
|
+
**Override via environment variable:**
|
378
|
+
|
379
|
+
```bash
|
380
|
+
SHAKAPACKER_PRECOMPILE=false rails assets:precompile
|
381
|
+
```
|
382
|
+
|
383
|
+
### `cache_manifest`
|
384
|
+
|
385
|
+
**Type:** `boolean`
|
386
|
+
**Default:** `false` (development), `true` (production)
|
387
|
+
|
388
|
+
Whether to cache manifest.json in memory.
|
389
|
+
|
390
|
+
```yaml
|
391
|
+
development:
|
392
|
+
cache_manifest: false # Reload on every request
|
393
|
+
|
394
|
+
production:
|
395
|
+
cache_manifest: true # Cache for performance
|
396
|
+
```
|
397
|
+
|
398
|
+
### `compiler_strategy`
|
399
|
+
|
400
|
+
**Type:** `string`
|
401
|
+
**Default:** `"mtime"` (development), `"digest"` (production)
|
402
|
+
**Options:** `"mtime"` or `"digest"`
|
403
|
+
|
404
|
+
How to determine if assets need recompilation.
|
405
|
+
|
406
|
+
```yaml
|
407
|
+
development:
|
408
|
+
# Fast: check file modification times
|
409
|
+
compiler_strategy: mtime
|
410
|
+
|
411
|
+
production:
|
412
|
+
# Accurate: check content hashes
|
413
|
+
compiler_strategy: digest
|
414
|
+
```
|
415
|
+
|
416
|
+
**mtime:** Faster but may miss changes if timestamps are unreliable.
|
417
|
+
**digest:** Slower but guarantees accuracy by comparing content hashes.
|
418
|
+
|
419
|
+
## Advanced Options
|
420
|
+
|
421
|
+
### `precompile_hook`
|
422
|
+
|
423
|
+
**Type:** `string`
|
424
|
+
**Default:** `nil`
|
425
|
+
|
426
|
+
Command to run before webpack/rspack compilation. Useful for generating dynamic entry points.
|
427
|
+
|
428
|
+
```yaml
|
429
|
+
precompile_hook: "bin/shakapacker-precompile-hook"
|
430
|
+
```
|
431
|
+
|
432
|
+
**Security:** Only reference trusted scripts within your project. The path is validated.
|
433
|
+
|
434
|
+
See [Precompile Hook Guide](precompile_hook.md) for examples and use cases.
|
435
|
+
|
436
|
+
### `ensure_consistent_versioning`
|
437
|
+
|
438
|
+
**Type:** `boolean`
|
439
|
+
**Default:** `true`
|
440
|
+
|
441
|
+
Raises an error if shakapacker gem and npm package versions don't match.
|
442
|
+
|
443
|
+
```yaml
|
444
|
+
# Enforce version matching (recommended)
|
445
|
+
ensure_consistent_versioning: true
|
446
|
+
|
447
|
+
# Allow version mismatches (not recommended)
|
448
|
+
ensure_consistent_versioning: false
|
449
|
+
```
|
450
|
+
|
451
|
+
### `asset_host`
|
452
|
+
|
453
|
+
**Type:** `string`
|
454
|
+
**Default:** `nil` (uses Rails asset host)
|
455
|
+
|
456
|
+
Override Rails asset host for webpack assets specifically.
|
457
|
+
|
458
|
+
```yaml
|
459
|
+
# Use custom CDN for webpack assets
|
460
|
+
asset_host: https://cdn.example.com
|
461
|
+
```
|
462
|
+
|
463
|
+
**Environment variable override:**
|
464
|
+
|
465
|
+
```bash
|
466
|
+
SHAKAPACKER_ASSET_HOST=https://cdn.example.com
|
467
|
+
```
|
468
|
+
|
469
|
+
See [CDN Setup Guide](cdn_setup.md) for complete configuration.
|
470
|
+
|
471
|
+
### `integrity`
|
472
|
+
|
473
|
+
**Type:** `object`
|
474
|
+
**Default:** `{ enabled: false }`
|
475
|
+
|
476
|
+
Enable Subresource Integrity (SRI) for security.
|
477
|
+
|
478
|
+
```yaml
|
479
|
+
integrity:
|
480
|
+
enabled: true
|
481
|
+
hash_functions: ["sha384"] # or ["sha256"], ["sha512"]
|
482
|
+
cross_origin: "anonymous" # or "use-credentials"
|
483
|
+
```
|
484
|
+
|
485
|
+
See [Subresource Integrity Guide](subresource_integrity.md) for details.
|
486
|
+
|
487
|
+
## Environment-Specific Configuration
|
488
|
+
|
489
|
+
Shakapacker supports per-environment configuration with fallback logic:
|
490
|
+
|
491
|
+
1. Checks for environment-specific config (e.g., `development`, `staging`)
|
492
|
+
2. Falls back to `production` if not found
|
493
|
+
3. Uses bundled defaults if neither exists
|
494
|
+
|
495
|
+
```yaml
|
496
|
+
# Shared defaults
|
497
|
+
default: &default
|
498
|
+
source_path: app/javascript
|
499
|
+
assets_bundler: "webpack"
|
500
|
+
|
501
|
+
# Development
|
502
|
+
development:
|
503
|
+
<<: *default
|
504
|
+
compile: true
|
505
|
+
compiler_strategy: mtime
|
506
|
+
dev_server:
|
507
|
+
hmr: true
|
508
|
+
|
509
|
+
# Test
|
510
|
+
test:
|
511
|
+
<<: *default
|
512
|
+
compile: true
|
513
|
+
public_output_path: packs-test
|
514
|
+
|
515
|
+
# Production
|
516
|
+
production:
|
517
|
+
<<: *default
|
518
|
+
compile: false
|
519
|
+
cache_manifest: true
|
520
|
+
compiler_strategy: digest
|
521
|
+
useContentHash: true # Enforced regardless
|
522
|
+
```
|
523
|
+
|
524
|
+
### Custom Environments
|
525
|
+
|
526
|
+
For custom environments (e.g., `staging`), define a section or let it fall back to production:
|
527
|
+
|
528
|
+
```yaml
|
529
|
+
# Option 1: Explicit staging config
|
530
|
+
staging:
|
531
|
+
<<: *default
|
532
|
+
compile: false
|
533
|
+
# staging-specific options
|
534
|
+
|
535
|
+
# Option 2: Let staging fall back to production
|
536
|
+
# (no staging section needed)
|
537
|
+
```
|
538
|
+
|
539
|
+
## Configuration Validation
|
540
|
+
|
541
|
+
Shakapacker validates configuration at runtime and provides helpful error messages:
|
542
|
+
|
543
|
+
- **Missing config files:** Suggests creating config or checking `assets_bundler_config_path`
|
544
|
+
- **Transpiler mismatch:** Warns if package.json dependencies don't match configured transpiler
|
545
|
+
- **Path conflicts:** Prevents `private_output_path` from being the same as `public_output_path`
|
546
|
+
- **Version mismatches:** Detects gem/npm version differences when `ensure_consistent_versioning` is enabled
|
547
|
+
|
548
|
+
## Environment Variables
|
549
|
+
|
550
|
+
Some options can be overridden via environment variables:
|
551
|
+
|
552
|
+
| Variable | Description | Example |
|
553
|
+
| ---------------------------- | ------------------------ | ------------------------- |
|
554
|
+
| `SHAKAPACKER_CONFIG` | Path to shakapacker.yml | `config/webpack.yml` |
|
555
|
+
| `SHAKAPACKER_ASSETS_BUNDLER` | Override assets bundler | `rspack` |
|
556
|
+
| `SHAKAPACKER_PRECOMPILE` | Override precompile flag | `false` |
|
557
|
+
| `SHAKAPACKER_ASSET_HOST` | Override asset host | `https://cdn.example.com` |
|
558
|
+
| `NODE_ENV` | Node environment | `production` |
|
559
|
+
| `RAILS_ENV` | Rails environment | `staging` |
|
560
|
+
|
561
|
+
## Best Practices
|
562
|
+
|
563
|
+
1. **Use default paths** unless you have a specific reason to change them
|
564
|
+
2. **Enable SWC transpiler** for faster builds (20x faster than Babel)
|
565
|
+
3. **Use rspack** for even faster builds if compatible with your setup
|
566
|
+
4. **Cache manifest** in production for better performance
|
567
|
+
5. **Enable integrity hashes** in production for security
|
568
|
+
6. **Keep development and production configs aligned** except for optimization settings
|
569
|
+
7. **Use content hashes** in production for proper cache busting
|
570
|
+
8. **Validate after changes** by running `bin/shakapacker` to ensure compilation works
|
571
|
+
|
572
|
+
## Common Configuration Patterns
|
573
|
+
|
574
|
+
### Fast Development Setup
|
575
|
+
|
576
|
+
```yaml
|
577
|
+
development:
|
578
|
+
assets_bundler: "rspack"
|
579
|
+
javascript_transpiler: "swc"
|
580
|
+
compiler_strategy: mtime
|
581
|
+
webpack_compile_output: true
|
582
|
+
dev_server:
|
583
|
+
hmr: true
|
584
|
+
inline_css: true
|
585
|
+
```
|
586
|
+
|
587
|
+
### Production-Optimized
|
588
|
+
|
589
|
+
```yaml
|
590
|
+
production:
|
591
|
+
assets_bundler: "rspack"
|
592
|
+
javascript_transpiler: "swc"
|
593
|
+
compiler_strategy: digest
|
594
|
+
cache_manifest: true
|
595
|
+
useContentHash: true
|
596
|
+
integrity:
|
597
|
+
enabled: true
|
598
|
+
```
|
599
|
+
|
600
|
+
### Monorepo Setup
|
601
|
+
|
602
|
+
```yaml
|
603
|
+
default: &default
|
604
|
+
source_path: packages/frontend/src
|
605
|
+
assets_bundler_config_path: build_configs/webpack
|
606
|
+
additional_paths:
|
607
|
+
- packages/shared
|
608
|
+
- packages/ui-components
|
609
|
+
```
|
610
|
+
|
611
|
+
## Troubleshooting
|
612
|
+
|
613
|
+
If you encounter configuration issues:
|
614
|
+
|
615
|
+
1. **Check error messages** - they often suggest the fix
|
616
|
+
2. **Validate YAML syntax** - use a YAML validator to ensure proper formatting
|
617
|
+
3. **Review fallback behavior** - missing environment configs fall back to production
|
618
|
+
4. **Check environment variables** - they override config file settings
|
619
|
+
5. **Inspect manifest.json** - verify assets are being compiled correctly
|
620
|
+
|
621
|
+
See [Troubleshooting Guide](troubleshooting.md) for more help.
|
622
|
+
|
623
|
+
## Related Guides
|
624
|
+
|
625
|
+
- [RSpack Migration Guide](rspack_migration_guide.md)
|
626
|
+
- [Transpiler Performance Guide](transpiler-performance.md)
|
627
|
+
- [Deployment Guide](deployment.md)
|
628
|
+
- [CDN Setup Guide](cdn_setup.md)
|
629
|
+
- [Precompile Hook Guide](precompile_hook.md)
|
630
|
+
- [Troubleshooting Guide](troubleshooting.md)
|