shakapacker 8.4.0 → 9.7.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/.claude/commands/address-review.md +206 -0
- data/.claude/commands/update-changelog.md +354 -0
- data/.github/ISSUE_TEMPLATE/bug_report.md +6 -9
- data/.github/ISSUE_TEMPLATE/feature_request.md +6 -8
- data/.github/STATUS.md +1 -0
- data/.github/actionlint-matcher.json +17 -0
- data/.github/workflows/claude-code-review.yml +45 -0
- data/.github/workflows/claude.yml +55 -0
- data/.github/workflows/dummy.yml +18 -5
- data/.github/workflows/eslint-validation.yml +46 -0
- data/.github/workflows/generator.yml +38 -22
- data/.github/workflows/node.yml +116 -2
- data/.github/workflows/ruby.yml +57 -15
- data/.github/workflows/test-bundlers.yml +180 -0
- data/.gitignore +27 -0
- data/.husky/pre-commit +2 -0
- data/.npmignore +56 -0
- data/.prettierignore +7 -0
- data/.rubocop.yml +2 -0
- data/.yalcignore +26 -0
- data/CHANGELOG.md +487 -19
- data/CLAUDE.md +63 -0
- data/CONTRIBUTING.md +268 -21
- data/ESLINT_TECHNICAL_DEBT.md +165 -0
- data/README.md +497 -137
- data/Rakefile +44 -4
- data/TODO.md +58 -0
- data/TODO_v9.md +97 -0
- data/bin/conductor-exec +24 -0
- data/bin/shakapacker-config +11 -0
- data/conductor-setup.sh +147 -0
- data/conductor.json +9 -0
- data/docs/api-reference.md +519 -0
- data/docs/cdn_setup.md +384 -0
- data/docs/common-upgrades.md +695 -0
- data/docs/configuration.md +845 -0
- data/docs/css-modules-export-mode.md +566 -0
- data/docs/customizing_babel_config.md +16 -16
- data/docs/deployment.md +78 -7
- data/docs/developing_shakapacker.md +6 -0
- data/docs/early_hints.md +433 -0
- data/docs/early_hints_manual_api.md +454 -0
- data/docs/feature_testing.md +492 -0
- data/docs/node_package_api.md +70 -0
- data/docs/optional-peer-dependencies.md +203 -0
- data/docs/peer-dependencies.md +71 -0
- data/docs/precompile_hook.md +486 -0
- data/docs/preventing_fouc.md +132 -0
- data/docs/react.md +58 -48
- data/docs/releasing.md +288 -0
- data/docs/rspack.md +218 -0
- data/docs/rspack_migration_guide.md +862 -0
- 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-migration.md +212 -0
- data/docs/transpiler-performance.md +200 -0
- data/docs/troubleshooting.md +272 -24
- data/docs/typescript-migration.md +388 -0
- data/docs/typescript.md +103 -0
- data/docs/using_esbuild_loader.md +12 -12
- data/docs/using_swc_loader.md +121 -16
- data/docs/v6_upgrade.md +42 -19
- data/docs/v7_upgrade.md +8 -6
- data/docs/v8_upgrade.md +13 -12
- data/docs/v9_upgrade.md +616 -0
- data/eslint.config.fast.js +254 -0
- data/eslint.config.js +309 -0
- data/jest.config.js +8 -1
- data/knip.ts +61 -0
- data/lib/install/bin/shakapacker +4 -6
- data/lib/install/bin/shakapacker-config +11 -0
- data/lib/install/bin/shakapacker-dev-server +1 -1
- data/lib/install/binstubs.rb +6 -2
- data/lib/install/config/rspack/rspack.config.js +6 -0
- data/lib/install/config/rspack/rspack.config.ts +7 -0
- data/lib/install/config/shakapacker.yml +75 -12
- data/lib/install/config/webpack/webpack.config.ts +7 -0
- data/lib/install/package.json +38 -0
- data/lib/install/template.rb +207 -45
- data/lib/shakapacker/build_config_loader.rb +147 -0
- data/lib/shakapacker/bundler_switcher.rb +415 -0
- data/lib/shakapacker/compiler.rb +87 -0
- data/lib/shakapacker/configuration.rb +475 -6
- data/lib/shakapacker/dev_server.rb +88 -1
- data/lib/shakapacker/dev_server_runner.rb +240 -6
- data/lib/shakapacker/doctor.rb +1191 -0
- data/lib/shakapacker/env.rb +19 -3
- data/lib/shakapacker/helper.rb +411 -14
- data/lib/shakapacker/install/env.rb +33 -0
- data/lib/shakapacker/instance.rb +93 -4
- data/lib/shakapacker/manifest.rb +167 -30
- data/lib/shakapacker/railtie.rb +4 -0
- data/lib/shakapacker/rspack_runner.rb +19 -0
- data/lib/shakapacker/runner.rb +668 -9
- data/lib/shakapacker/swc_migrator.rb +384 -0
- data/lib/shakapacker/utils/manager.rb +2 -0
- data/lib/shakapacker/utils/version_syntax_converter.rb +1 -1
- data/lib/shakapacker/version.rb +1 -1
- data/lib/shakapacker/version_checker.rb +1 -1
- data/lib/shakapacker/webpack_runner.rb +4 -42
- data/lib/shakapacker.rb +159 -1
- data/lib/tasks/shakapacker/binstubs.rake +4 -2
- data/lib/tasks/shakapacker/check_binstubs.rake +2 -2
- data/lib/tasks/shakapacker/doctor.rake +48 -0
- data/lib/tasks/shakapacker/export_bundler_config.rake +68 -0
- data/lib/tasks/shakapacker/install.rake +16 -4
- data/lib/tasks/shakapacker/migrate_to_swc.rake +13 -0
- data/lib/tasks/shakapacker/switch_bundler.rake +72 -0
- data/lib/tasks/shakapacker.rake +2 -0
- data/package/.npmignore +4 -0
- data/package/babel/preset.ts +59 -0
- data/package/config.ts +189 -0
- data/package/configExporter/buildValidator.ts +906 -0
- data/package/configExporter/cli.ts +1748 -0
- data/package/configExporter/configDocs.ts +102 -0
- data/package/configExporter/configFile.ts +663 -0
- data/package/configExporter/fileWriter.ts +112 -0
- data/package/configExporter/index.ts +15 -0
- data/package/configExporter/types.ts +159 -0
- data/package/configExporter/yamlSerializer.ts +391 -0
- data/package/dev_server.ts +27 -0
- data/package/env.ts +92 -0
- data/package/environments/__type-tests__/rspack-plugin-compatibility.ts +36 -0
- data/package/environments/base.ts +147 -0
- data/package/environments/development.ts +88 -0
- data/package/environments/production.ts +82 -0
- data/package/environments/test.ts +55 -0
- data/package/environments/types.ts +98 -0
- data/package/esbuild/index.ts +40 -0
- data/package/index.d.ts +68 -93
- data/package/index.d.ts.template +72 -0
- data/package/index.ts +104 -0
- data/package/loaders.d.ts +28 -0
- data/package/optimization/rspack.ts +36 -0
- data/package/optimization/webpack.ts +55 -0
- data/package/plugins/envFilter.ts +82 -0
- data/package/plugins/rspack.ts +119 -0
- data/package/plugins/webpack.ts +82 -0
- data/package/rspack/index.ts +91 -0
- data/package/rules/{babel.js → babel.ts} +2 -2
- data/package/rules/{coffee.js → coffee.ts} +1 -1
- data/package/rules/css.ts +3 -0
- data/package/rules/{erb.js → erb.ts} +1 -1
- data/package/rules/esbuild.ts +10 -0
- data/package/rules/file.ts +41 -0
- data/package/rules/{jscommon.js → jscommon.ts} +5 -4
- data/package/rules/{less.js → less.ts} +4 -4
- data/package/rules/raw.ts +28 -0
- data/package/rules/rspack.ts +174 -0
- data/package/rules/sass.ts +21 -0
- data/package/rules/{stylus.js → stylus.ts} +4 -8
- data/package/rules/swc.ts +10 -0
- data/package/rules/{index.js → webpack.ts} +1 -2
- data/package/swc/index.ts +54 -0
- data/package/types/README.md +90 -0
- data/package/types/index.ts +69 -0
- data/package/types.ts +105 -0
- data/package/utils/bundlerUtils.ts +232 -0
- data/package/utils/configPath.ts +6 -0
- data/package/utils/debug.ts +45 -0
- data/package/utils/defaultConfigPath.ts +7 -0
- data/package/utils/ensureManifestExists.ts +17 -0
- data/package/utils/errorCodes.ts +249 -0
- data/package/utils/errorHelpers.ts +152 -0
- data/package/utils/getStyleRule.ts +75 -0
- data/package/utils/helpers.ts +99 -0
- data/package/utils/{inliningCss.js → inliningCss.ts} +3 -3
- data/package/utils/pathValidation.ts +207 -0
- data/package/utils/requireOrError.ts +24 -0
- data/package/utils/snakeToCamelCase.ts +5 -0
- data/package/utils/typeGuards.ts +388 -0
- data/package/utils/validateDependencies.ts +61 -0
- data/package/webpack-types.d.ts +33 -0
- data/package/webpackDevServerConfig.ts +130 -0
- data/package.json +157 -18
- data/scripts/remove-use-strict.js +44 -0
- data/scripts/type-check-no-emit.js +27 -0
- data/shakapacker.gemspec +4 -2
- data/sig/shakapacker/commands.rbs +35 -0
- data/sig/shakapacker/compiler.rbs +65 -0
- data/sig/shakapacker/compiler_strategy.rbs +41 -0
- data/sig/shakapacker/configuration.rbs +140 -0
- data/sig/shakapacker/dev_server.rbs +56 -0
- data/sig/shakapacker/env.rbs +25 -0
- data/sig/shakapacker/helper.rbs +98 -0
- data/sig/shakapacker/instance.rbs +46 -0
- data/sig/shakapacker/manifest.rbs +69 -0
- data/sig/shakapacker/version.rbs +4 -0
- data/sig/shakapacker.rbs +66 -0
- data/test/configExporter/buildValidator.test.js +1295 -0
- data/test/configExporter/configFile.test.js +393 -0
- data/test/configExporter/integration.test.js +262 -0
- data/test/helpers.js +1 -1
- data/test/package/bundlerUtils.rspack.test.js +145 -0
- data/test/package/bundlerUtils.test.js +97 -0
- data/test/package/config.test.js +14 -0
- data/test/package/configExporter/cli.test.js +440 -0
- data/test/package/configExporter/types.test.js +163 -0
- data/test/package/configExporter.test.js +491 -0
- data/test/package/env.test.js +42 -7
- data/test/package/environments/base.test.js +14 -4
- data/test/package/helpers.test.js +2 -2
- data/test/package/plugins/envFiltering.test.js +453 -0
- data/test/package/plugins/webpackSubresourceIntegrity.test.js +89 -0
- data/test/package/rspack/index.test.js +293 -0
- data/test/package/rspack/optimization.test.js +86 -0
- data/test/package/rspack/plugins.test.js +185 -0
- data/test/package/rspack/rules.test.js +229 -0
- data/test/package/rules/babel.test.js +65 -38
- data/test/package/rules/esbuild.test.js +13 -4
- data/test/package/rules/file.test.js +7 -1
- data/test/package/rules/raw.test.js +40 -7
- data/test/package/rules/sass-version-parsing.test.js +71 -0
- data/test/package/rules/sass.test.js +11 -6
- data/test/package/rules/sass1.test.js +8 -5
- data/test/package/rules/sass16.test.js +24 -0
- data/test/package/rules/swc.test.js +50 -39
- data/test/package/rules/webpack.test.js +35 -0
- data/test/package/staging.test.js +4 -3
- data/test/package/transpiler-defaults.test.js +169 -0
- data/test/package/utils/ensureManifestExists.test.js +51 -0
- data/test/package/yamlSerializer.test.js +204 -0
- data/test/peer-dependencies.sh +85 -0
- data/test/resolver.js +34 -3
- data/test/scripts/remove-use-strict.test.js +125 -0
- data/test/typescript/build.test.js +118 -0
- data/test/typescript/environments.test.js +107 -0
- data/test/typescript/pathValidation.test.js +186 -0
- data/test/typescript/requireOrError.test.js +49 -0
- data/test/typescript/securityValidation.test.js +182 -0
- data/tools/README.md +134 -0
- data/tools/css-modules-v9-codemod.js +179 -0
- data/tsconfig.eslint.json +9 -0
- data/tsconfig.json +38 -0
- data/yarn.lock +3202 -1097
- metadata +212 -44
- data/.eslintignore +0 -4
- data/.eslintrc.js +0 -36
- data/Gemfile.lock +0 -251
- data/package/babel/preset.js +0 -48
- data/package/config.js +0 -56
- data/package/dev_server.js +0 -23
- data/package/env.js +0 -48
- data/package/environments/base.js +0 -171
- data/package/environments/development.js +0 -13
- data/package/environments/production.js +0 -88
- data/package/environments/test.js +0 -3
- data/package/esbuild/index.js +0 -40
- data/package/index.js +0 -40
- data/package/rules/css.js +0 -3
- data/package/rules/esbuild.js +0 -10
- data/package/rules/file.js +0 -29
- data/package/rules/raw.js +0 -5
- data/package/rules/sass.js +0 -18
- data/package/rules/swc.js +0 -10
- data/package/swc/index.js +0 -50
- data/package/utils/configPath.js +0 -4
- data/package/utils/defaultConfigPath.js +0 -2
- data/package/utils/getStyleRule.js +0 -40
- data/package/utils/helpers.js +0 -62
- data/package/utils/snakeToCamelCase.js +0 -5
- data/package/webpackDevServerConfig.js +0 -71
- data/test/package/rules/index.test.js +0 -16
|
@@ -0,0 +1,845 @@
|
|
|
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
|
+
- [Quick Reference](#quick-reference)
|
|
8
|
+
- [Basic Configuration](#basic-configuration)
|
|
9
|
+
- [Source Configuration](#source-configuration)
|
|
10
|
+
- [Output Configuration](#output-configuration)
|
|
11
|
+
- [Bundler Configuration](#bundler-configuration)
|
|
12
|
+
- [Development Server](#development-server)
|
|
13
|
+
- [Compilation Options](#compilation-options)
|
|
14
|
+
- [Advanced Options](#advanced-options)
|
|
15
|
+
- [Subresource Integrity](#integrity)
|
|
16
|
+
- [Early Hints](#early_hints)
|
|
17
|
+
- [Environment-Specific Configuration](#environment-specific-configuration)
|
|
18
|
+
- [Build Configurations (config/shakapacker-builds.yml)](#build-configurations-configshakapacker-buildsyml)
|
|
19
|
+
|
|
20
|
+
## Quick Reference
|
|
21
|
+
|
|
22
|
+
Common configuration options with their defaults:
|
|
23
|
+
|
|
24
|
+
| Option | Type | Default | Description |
|
|
25
|
+
| ------------------------------ | ------- | --------------------------------------- | ---------------------------------------------------------- |
|
|
26
|
+
| `assets_bundler` | string | `"webpack"` | Bundler to use: `"webpack"` or `"rspack"` |
|
|
27
|
+
| `assets_bundler_config_path` | string | `"config/webpack"` or `"config/rspack"` | Directory containing bundler config files |
|
|
28
|
+
| `javascript_transpiler` | string | `"swc"`\* | Transpiler: `"swc"`, `"babel"`, or `"esbuild"` |
|
|
29
|
+
| `source_path` | string | `"app/javascript"` | Root directory for JavaScript source files |
|
|
30
|
+
| `source_entry_path` | string | `"packs"` | Subdirectory within `source_path` for entry points |
|
|
31
|
+
| `nested_entries` | boolean | `true` | Discover entry points in subdirectories |
|
|
32
|
+
| `public_output_path` | string | `"packs"` | Subdirectory within `public_root_path` for compiled assets |
|
|
33
|
+
| `private_output_path` | string | `nil` | Directory for private server-side bundles (e.g., SSR) |
|
|
34
|
+
| `compile` | boolean | env-specific | Compile assets on-demand when requests are made |
|
|
35
|
+
| `cache_manifest` | boolean | `false` (dev), `true` (prod) | Cache manifest.json in memory |
|
|
36
|
+
| `compiler_strategy` | string | `"mtime"` (dev), `"digest"` (prod) | How to determine if recompilation is needed |
|
|
37
|
+
| `useContentHash` | boolean | `false` (dev), `true` (prod) | Include content hashes in asset filenames |
|
|
38
|
+
| `webpack_compile_output` | boolean | `true` | Show webpack/rspack compilation output |
|
|
39
|
+
| `shakapacker_precompile` | boolean | `true` | Include in `bundle exec rake assets:precompile` |
|
|
40
|
+
| `ensure_consistent_versioning` | boolean | `true` | Enforce gem/npm version matching |
|
|
41
|
+
| `dev_server.host` | string | `"localhost"` | Development server host |
|
|
42
|
+
| `dev_server.port` | number | `3035` | Development server port |
|
|
43
|
+
| `dev_server.hmr` | boolean | `false` | Enable Hot Module Replacement |
|
|
44
|
+
|
|
45
|
+
For detailed explanations, examples, and additional options, see the sections below.
|
|
46
|
+
|
|
47
|
+
**\*Note on `javascript_transpiler` default**: The installation template sets this to `"swc"` for new projects. However, at runtime, if no explicit value is configured, webpack defaults to `"babel"` (for backward compatibility) while rspack defaults to `"swc"`.
|
|
48
|
+
|
|
49
|
+
## Basic Configuration
|
|
50
|
+
|
|
51
|
+
### `assets_bundler`
|
|
52
|
+
|
|
53
|
+
**Type:** `string`
|
|
54
|
+
**Default:** `"webpack"`
|
|
55
|
+
**Options:** `"webpack"` or `"rspack"`
|
|
56
|
+
|
|
57
|
+
Specifies which bundler to use for compiling assets.
|
|
58
|
+
|
|
59
|
+
```yaml
|
|
60
|
+
# Use webpack (default)
|
|
61
|
+
assets_bundler: "webpack"
|
|
62
|
+
|
|
63
|
+
# Use rspack for faster builds
|
|
64
|
+
assets_bundler: "rspack"
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
See [RSpack Migration Guide](rspack_migration_guide.md) for details on switching bundlers.
|
|
68
|
+
|
|
69
|
+
### `assets_bundler_config_path`
|
|
70
|
+
|
|
71
|
+
**Type:** `string`
|
|
72
|
+
**Default:** `"config/webpack"` for webpack, `"config/rspack"` for rspack
|
|
73
|
+
|
|
74
|
+
Specifies the directory containing your webpack/rspack config files.
|
|
75
|
+
|
|
76
|
+
```yaml
|
|
77
|
+
# Use default paths (config/webpack or config/rspack)
|
|
78
|
+
# assets_bundler_config_path: config/webpack
|
|
79
|
+
|
|
80
|
+
# Use custom directory
|
|
81
|
+
assets_bundler_config_path: "build_configs"
|
|
82
|
+
|
|
83
|
+
# Use project root directory
|
|
84
|
+
assets_bundler_config_path: "."
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
**When to use:**
|
|
88
|
+
|
|
89
|
+
- When migrating from another build tool and want to preserve existing config locations
|
|
90
|
+
- When organizing configs in a monorepo structure
|
|
91
|
+
- When following custom project conventions
|
|
92
|
+
|
|
93
|
+
### `javascript_transpiler`
|
|
94
|
+
|
|
95
|
+
**Type:** `string`
|
|
96
|
+
**Default:** `"swc"` (new installations), `"babel"` (webpack runtime), `"swc"` (rspack runtime)
|
|
97
|
+
**Options:** `"swc"`, `"babel"`, or `"esbuild"`
|
|
98
|
+
|
|
99
|
+
Specifies which transpiler to use for JavaScript/TypeScript.
|
|
100
|
+
|
|
101
|
+
```yaml
|
|
102
|
+
# Use SWC (recommended - 20x faster than Babel, set by default in new installations)
|
|
103
|
+
javascript_transpiler: "swc"
|
|
104
|
+
|
|
105
|
+
# Use Babel (for maximum compatibility, webpack runtime default if not configured)
|
|
106
|
+
javascript_transpiler: "babel"
|
|
107
|
+
|
|
108
|
+
# Use esbuild (fastest, but may have compatibility issues)
|
|
109
|
+
javascript_transpiler: "esbuild"
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
**Important default behavior:**
|
|
113
|
+
|
|
114
|
+
- **New installations**: The installation template explicitly sets `javascript_transpiler: "swc"`
|
|
115
|
+
- **Webpack runtime default**: If not explicitly configured, defaults to `"babel"` for backward compatibility
|
|
116
|
+
- **Rspack runtime default**: If not explicitly configured, defaults to `"swc"` as rspack is a newer bundler
|
|
117
|
+
|
|
118
|
+
See [Transpiler Performance Guide](transpiler-performance.md) for benchmarks and migration guides.
|
|
119
|
+
|
|
120
|
+
## Source Configuration
|
|
121
|
+
|
|
122
|
+
### `source_path`
|
|
123
|
+
|
|
124
|
+
**Type:** `string`
|
|
125
|
+
**Default:** `"app/javascript"`
|
|
126
|
+
|
|
127
|
+
The root directory for your JavaScript source files.
|
|
128
|
+
|
|
129
|
+
```yaml
|
|
130
|
+
# Default
|
|
131
|
+
source_path: app/javascript
|
|
132
|
+
|
|
133
|
+
# Custom location
|
|
134
|
+
source_path: app/frontend
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### `source_entry_path`
|
|
138
|
+
|
|
139
|
+
**Type:** `string`
|
|
140
|
+
**Default:** `"packs"`
|
|
141
|
+
|
|
142
|
+
Subdirectory within `source_path` containing entry points.
|
|
143
|
+
|
|
144
|
+
```yaml
|
|
145
|
+
# Recommended: use a subdirectory
|
|
146
|
+
source_entry_path: packs
|
|
147
|
+
|
|
148
|
+
# Use the entire source_path as entry directory
|
|
149
|
+
source_entry_path: /
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
**Note:** Cannot use `/` when `nested_entries` is `true`.
|
|
153
|
+
|
|
154
|
+
### `nested_entries`
|
|
155
|
+
|
|
156
|
+
**Type:** `boolean`
|
|
157
|
+
**Default:** `true`
|
|
158
|
+
|
|
159
|
+
Whether to automatically discover entry points in subdirectories within `source_entry_path`.
|
|
160
|
+
|
|
161
|
+
```yaml
|
|
162
|
+
# Enable nested entries (recommended)
|
|
163
|
+
nested_entries: true
|
|
164
|
+
|
|
165
|
+
# Disable - only top-level files are entries
|
|
166
|
+
nested_entries: false
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
**Example with nested entries:**
|
|
170
|
+
|
|
171
|
+
```
|
|
172
|
+
app/javascript/packs/
|
|
173
|
+
application.js # Entry: application
|
|
174
|
+
admin/
|
|
175
|
+
dashboard.js # Entry: admin/dashboard
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### `additional_paths`
|
|
179
|
+
|
|
180
|
+
**Type:** `array`
|
|
181
|
+
**Default:** `[]`
|
|
182
|
+
|
|
183
|
+
Additional directories for webpack/rspack to search for modules.
|
|
184
|
+
|
|
185
|
+
```yaml
|
|
186
|
+
additional_paths:
|
|
187
|
+
- app/assets
|
|
188
|
+
- vendor/assets
|
|
189
|
+
- node_modules/legacy-lib
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
**Use cases:**
|
|
193
|
+
|
|
194
|
+
- Resolving modules from Rails asset directories
|
|
195
|
+
- Including vendored JavaScript
|
|
196
|
+
- Sharing code between engines
|
|
197
|
+
|
|
198
|
+
## Output Configuration
|
|
199
|
+
|
|
200
|
+
### `public_root_path`
|
|
201
|
+
|
|
202
|
+
**Type:** `string`
|
|
203
|
+
**Default:** `"public"`
|
|
204
|
+
|
|
205
|
+
The public directory where assets are served from.
|
|
206
|
+
|
|
207
|
+
```yaml
|
|
208
|
+
public_root_path: public
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
### `public_output_path`
|
|
212
|
+
|
|
213
|
+
**Type:** `string`
|
|
214
|
+
**Default:** `"packs"`
|
|
215
|
+
|
|
216
|
+
Subdirectory within `public_root_path` for compiled assets.
|
|
217
|
+
|
|
218
|
+
```yaml
|
|
219
|
+
# Default - outputs to public/packs
|
|
220
|
+
public_output_path: packs
|
|
221
|
+
|
|
222
|
+
# Custom output directory
|
|
223
|
+
public_output_path: webpack-bundles
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
### `private_output_path`
|
|
227
|
+
|
|
228
|
+
**Type:** `string`
|
|
229
|
+
**Default:** `nil`
|
|
230
|
+
|
|
231
|
+
Directory for private server-side bundles (e.g., for SSR) that should not be publicly accessible.
|
|
232
|
+
|
|
233
|
+
```yaml
|
|
234
|
+
# Enable private output for SSR bundles
|
|
235
|
+
private_output_path: ssr-generated
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
**Important:** Must be different from `public_output_path` to prevent serving private bundles.
|
|
239
|
+
|
|
240
|
+
### `manifest_path`
|
|
241
|
+
|
|
242
|
+
**Type:** `string`
|
|
243
|
+
**Default:** `"{public_output_path}/manifest.json"`
|
|
244
|
+
|
|
245
|
+
Location of the manifest.json file that maps entry points to compiled assets.
|
|
246
|
+
|
|
247
|
+
```yaml
|
|
248
|
+
# Custom manifest location
|
|
249
|
+
manifest_path: public/assets/webpack-manifest.json
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
**Note:** Rarely needs to be changed from the default.
|
|
253
|
+
|
|
254
|
+
### `cache_path`
|
|
255
|
+
|
|
256
|
+
**Type:** `string`
|
|
257
|
+
**Default:** `"tmp/shakapacker"`
|
|
258
|
+
|
|
259
|
+
Directory for webpack/rspack cache files.
|
|
260
|
+
|
|
261
|
+
```yaml
|
|
262
|
+
cache_path: tmp/shakapacker
|
|
263
|
+
|
|
264
|
+
# Use a shared cache in CI
|
|
265
|
+
cache_path: /mnt/shared/webpack-cache
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
## Bundler Configuration
|
|
269
|
+
|
|
270
|
+
### `webpack_compile_output`
|
|
271
|
+
|
|
272
|
+
**Type:** `boolean`
|
|
273
|
+
**Default:** `true`
|
|
274
|
+
|
|
275
|
+
Whether to show webpack/rspack compilation output in the console.
|
|
276
|
+
|
|
277
|
+
```yaml
|
|
278
|
+
# Show detailed output (helpful for debugging)
|
|
279
|
+
webpack_compile_output: true
|
|
280
|
+
|
|
281
|
+
# Minimal output (cleaner logs)
|
|
282
|
+
webpack_compile_output: false
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
### `useContentHash`
|
|
286
|
+
|
|
287
|
+
**Type:** `boolean`
|
|
288
|
+
**Default:** `false` (development), `true` (production - enforced)
|
|
289
|
+
|
|
290
|
+
Whether to include content hashes in asset filenames for cache busting.
|
|
291
|
+
|
|
292
|
+
```yaml
|
|
293
|
+
# Production only (default)
|
|
294
|
+
useContentHash: false
|
|
295
|
+
|
|
296
|
+
# Always use content hash (not recommended for development)
|
|
297
|
+
useContentHash: true
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
**Note:** In production, this is always `true` regardless of configuration.
|
|
301
|
+
|
|
302
|
+
### `css_extract_ignore_order_warnings`
|
|
303
|
+
|
|
304
|
+
**Type:** `boolean`
|
|
305
|
+
**Default:** `false`
|
|
306
|
+
|
|
307
|
+
Whether to suppress mini-css-extract-plugin order warnings.
|
|
308
|
+
|
|
309
|
+
```yaml
|
|
310
|
+
# Enable if you have consistent CSS scoping
|
|
311
|
+
css_extract_ignore_order_warnings: true
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
**When to enable:**
|
|
315
|
+
|
|
316
|
+
- When using CSS modules or scoped styles
|
|
317
|
+
- When following BEM or similar naming conventions
|
|
318
|
+
- When order warnings are false positives
|
|
319
|
+
|
|
320
|
+
## Development Server
|
|
321
|
+
|
|
322
|
+
### `dev_server`
|
|
323
|
+
|
|
324
|
+
Configuration for `bin/shakapacker-dev-server`. See [Dev Server Options](#dev-server-options) below.
|
|
325
|
+
|
|
326
|
+
#### Dev Server Options
|
|
327
|
+
|
|
328
|
+
```yaml
|
|
329
|
+
dev_server:
|
|
330
|
+
# Host to bind to
|
|
331
|
+
host: localhost
|
|
332
|
+
|
|
333
|
+
# Port to listen on
|
|
334
|
+
port: 3035
|
|
335
|
+
|
|
336
|
+
# Enable HTTPS
|
|
337
|
+
# server: https
|
|
338
|
+
|
|
339
|
+
# Hot Module Replacement
|
|
340
|
+
hmr: false
|
|
341
|
+
|
|
342
|
+
# Live reload (alternative to HMR)
|
|
343
|
+
# live_reload: true
|
|
344
|
+
|
|
345
|
+
# Inline CSS with HMR (requires style-loader)
|
|
346
|
+
inline_css: true
|
|
347
|
+
|
|
348
|
+
# Compression
|
|
349
|
+
compress: true
|
|
350
|
+
|
|
351
|
+
# Allowed hosts (security)
|
|
352
|
+
allowed_hosts: "auto"
|
|
353
|
+
|
|
354
|
+
# Client configuration
|
|
355
|
+
client:
|
|
356
|
+
# Show error overlay
|
|
357
|
+
overlay: true
|
|
358
|
+
|
|
359
|
+
# Custom WebSocket URL
|
|
360
|
+
# webSocketURL:
|
|
361
|
+
# hostname: '0.0.0.0'
|
|
362
|
+
# pathname: '/ws'
|
|
363
|
+
# port: 8080
|
|
364
|
+
|
|
365
|
+
# Custom headers for dev server responses
|
|
366
|
+
# Uncomment to enable CORS (e.g., when webpack-dev-server runs on a different
|
|
367
|
+
# port than your Rails server and the browser blocks cross-origin asset requests):
|
|
368
|
+
# headers:
|
|
369
|
+
# "Access-Control-Allow-Origin": "*"
|
|
370
|
+
|
|
371
|
+
# Static file serving
|
|
372
|
+
static:
|
|
373
|
+
watch:
|
|
374
|
+
ignored: "**/node_modules/**"
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
**Key Options:**
|
|
378
|
+
|
|
379
|
+
- **hmr:** Hot Module Replacement updates modules without full reload. Requires additional setup.
|
|
380
|
+
- **inline_css:** With HMR, CSS is delivered via JavaScript. Set to `false` to use `<link>` tags.
|
|
381
|
+
- **overlay:** Shows errors/warnings in browser overlay. Helpful for development.
|
|
382
|
+
- **allowed_hosts:** Protects against DNS rebinding attacks. Use `"all"` to disable (not recommended).
|
|
383
|
+
|
|
384
|
+
## Compilation Options
|
|
385
|
+
|
|
386
|
+
### `compile`
|
|
387
|
+
|
|
388
|
+
**Type:** `boolean`
|
|
389
|
+
**Environment-specific**
|
|
390
|
+
|
|
391
|
+
Whether to compile assets on-demand when requests are made.
|
|
392
|
+
|
|
393
|
+
```yaml
|
|
394
|
+
development:
|
|
395
|
+
compile: true # Compile on demand
|
|
396
|
+
|
|
397
|
+
production:
|
|
398
|
+
compile: false # Assets must be precompiled
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
### `shakapacker_precompile`
|
|
402
|
+
|
|
403
|
+
**Type:** `boolean`
|
|
404
|
+
**Default:** `true`
|
|
405
|
+
|
|
406
|
+
Whether `bundle exec rake assets:precompile` should compile webpack/rspack assets.
|
|
407
|
+
|
|
408
|
+
```yaml
|
|
409
|
+
# Include in assets:precompile (recommended)
|
|
410
|
+
shakapacker_precompile: true
|
|
411
|
+
|
|
412
|
+
# Skip webpack compilation during assets:precompile
|
|
413
|
+
shakapacker_precompile: false
|
|
414
|
+
```
|
|
415
|
+
|
|
416
|
+
**Override via environment variable:**
|
|
417
|
+
|
|
418
|
+
```bash
|
|
419
|
+
SHAKAPACKER_PRECOMPILE=false bundle exec rake assets:precompile
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
### `cache_manifest`
|
|
423
|
+
|
|
424
|
+
**Type:** `boolean`
|
|
425
|
+
**Default:** `false` (development), `true` (production)
|
|
426
|
+
|
|
427
|
+
Whether to cache manifest.json in memory.
|
|
428
|
+
|
|
429
|
+
```yaml
|
|
430
|
+
development:
|
|
431
|
+
cache_manifest: false # Reload on every request
|
|
432
|
+
|
|
433
|
+
production:
|
|
434
|
+
cache_manifest: true # Cache for performance
|
|
435
|
+
```
|
|
436
|
+
|
|
437
|
+
### `compiler_strategy`
|
|
438
|
+
|
|
439
|
+
**Type:** `string`
|
|
440
|
+
**Default:** `"mtime"` (development), `"digest"` (production)
|
|
441
|
+
**Options:** `"mtime"` or `"digest"`
|
|
442
|
+
|
|
443
|
+
How to determine if assets need recompilation.
|
|
444
|
+
|
|
445
|
+
```yaml
|
|
446
|
+
development:
|
|
447
|
+
# Fast: check file modification times
|
|
448
|
+
compiler_strategy: mtime
|
|
449
|
+
|
|
450
|
+
production:
|
|
451
|
+
# Accurate: check content hashes
|
|
452
|
+
compiler_strategy: digest
|
|
453
|
+
```
|
|
454
|
+
|
|
455
|
+
**mtime:** Faster but may miss changes if timestamps are unreliable.
|
|
456
|
+
**digest:** Slower but guarantees accuracy by comparing content hashes.
|
|
457
|
+
|
|
458
|
+
## Advanced Options
|
|
459
|
+
|
|
460
|
+
### `precompile_hook`
|
|
461
|
+
|
|
462
|
+
**Type:** `string`
|
|
463
|
+
**Default:** `nil`
|
|
464
|
+
|
|
465
|
+
Command to run before webpack/rspack compilation. Useful for generating dynamic entry points.
|
|
466
|
+
|
|
467
|
+
```yaml
|
|
468
|
+
precompile_hook: "bin/shakapacker-precompile-hook"
|
|
469
|
+
```
|
|
470
|
+
|
|
471
|
+
**Security:** Only reference trusted scripts within your project. The path is validated.
|
|
472
|
+
|
|
473
|
+
See [Precompile Hook Guide](precompile_hook.md) for examples and use cases.
|
|
474
|
+
|
|
475
|
+
### `ensure_consistent_versioning`
|
|
476
|
+
|
|
477
|
+
**Type:** `boolean`
|
|
478
|
+
**Default:** `true`
|
|
479
|
+
|
|
480
|
+
Raises an error if shakapacker gem and npm package versions don't match.
|
|
481
|
+
|
|
482
|
+
```yaml
|
|
483
|
+
# Enforce version matching (recommended)
|
|
484
|
+
ensure_consistent_versioning: true
|
|
485
|
+
|
|
486
|
+
# Allow version mismatches (not recommended)
|
|
487
|
+
ensure_consistent_versioning: false
|
|
488
|
+
```
|
|
489
|
+
|
|
490
|
+
### `asset_host`
|
|
491
|
+
|
|
492
|
+
**Type:** `string`
|
|
493
|
+
**Default:** `nil` (uses Rails asset host)
|
|
494
|
+
|
|
495
|
+
Override Rails asset host for webpack assets specifically.
|
|
496
|
+
|
|
497
|
+
```yaml
|
|
498
|
+
# Use custom CDN for webpack assets
|
|
499
|
+
asset_host: https://cdn.example.com
|
|
500
|
+
```
|
|
501
|
+
|
|
502
|
+
**Environment variable override:**
|
|
503
|
+
|
|
504
|
+
```bash
|
|
505
|
+
SHAKAPACKER_ASSET_HOST=https://cdn.example.com
|
|
506
|
+
```
|
|
507
|
+
|
|
508
|
+
See [CDN Setup Guide](cdn_setup.md) for complete configuration.
|
|
509
|
+
|
|
510
|
+
### `integrity`
|
|
511
|
+
|
|
512
|
+
**Type:** `object`
|
|
513
|
+
**Default:** `{ enabled: false }`
|
|
514
|
+
|
|
515
|
+
Enable Subresource Integrity (SRI) for security.
|
|
516
|
+
|
|
517
|
+
```yaml
|
|
518
|
+
integrity:
|
|
519
|
+
enabled: true
|
|
520
|
+
hash_functions: ["sha384"] # or ["sha256"], ["sha512"]
|
|
521
|
+
cross_origin: "anonymous" # or "use-credentials"
|
|
522
|
+
```
|
|
523
|
+
|
|
524
|
+
See [Subresource Integrity Guide](subresource_integrity.md) for details.
|
|
525
|
+
|
|
526
|
+
### `early_hints`
|
|
527
|
+
|
|
528
|
+
**Type:** `object`
|
|
529
|
+
**Default:** `{ enabled: false, css: "preload", js: "preload" }`
|
|
530
|
+
**Requires:** Rails 5.2+, HTTP/2 server
|
|
531
|
+
|
|
532
|
+
Automatically send HTTP 103 Early Hints for faster asset loading.
|
|
533
|
+
|
|
534
|
+
```yaml
|
|
535
|
+
early_hints:
|
|
536
|
+
enabled: true # Master switch (default: false)
|
|
537
|
+
css: "preload" # 'preload' | 'prefetch' | 'none' (default: 'preload')
|
|
538
|
+
js: "preload" # 'preload' | 'prefetch' | 'none' (default: 'preload')
|
|
539
|
+
```
|
|
540
|
+
|
|
541
|
+
**Options:**
|
|
542
|
+
|
|
543
|
+
- `enabled`: Enable/disable early hints (default: `false`)
|
|
544
|
+
- `css`: Hint type for CSS - `'preload'`, `'prefetch'`, or `'none'` (default: `'preload'`)
|
|
545
|
+
- `js`: Hint type for JS - `'preload'`, `'prefetch'`, or `'none'` (default: `'preload'`)
|
|
546
|
+
|
|
547
|
+
⚠️ **Performance note**: May improve or hurt page load depending on content. Configure per-page for best results.
|
|
548
|
+
|
|
549
|
+
See the [Early Hints Guide](early_hints.md) for:
|
|
550
|
+
|
|
551
|
+
- Performance considerations and warnings
|
|
552
|
+
- Per-page configuration (`configure_pack_early_hints`)
|
|
553
|
+
- Dynamic configuration examples
|
|
554
|
+
- Hero image preloading with `preload_link_tag`
|
|
555
|
+
- Troubleshooting and testing recommendations
|
|
556
|
+
|
|
557
|
+
## Environment-Specific Configuration
|
|
558
|
+
|
|
559
|
+
Shakapacker supports per-environment configuration with fallback logic:
|
|
560
|
+
|
|
561
|
+
1. Checks for environment-specific config (e.g., `development`, `staging`)
|
|
562
|
+
2. Falls back to `production` if not found
|
|
563
|
+
3. Uses bundled defaults if neither exists
|
|
564
|
+
|
|
565
|
+
```yaml
|
|
566
|
+
# Shared defaults
|
|
567
|
+
default: &default
|
|
568
|
+
source_path: app/javascript
|
|
569
|
+
assets_bundler: "webpack"
|
|
570
|
+
|
|
571
|
+
# Development
|
|
572
|
+
development:
|
|
573
|
+
<<: *default
|
|
574
|
+
compile: true
|
|
575
|
+
compiler_strategy: mtime
|
|
576
|
+
dev_server:
|
|
577
|
+
hmr: true
|
|
578
|
+
|
|
579
|
+
# Test
|
|
580
|
+
test:
|
|
581
|
+
<<: *default
|
|
582
|
+
compile: true
|
|
583
|
+
public_output_path: packs-test
|
|
584
|
+
|
|
585
|
+
# Production
|
|
586
|
+
production:
|
|
587
|
+
<<: *default
|
|
588
|
+
compile: false
|
|
589
|
+
cache_manifest: true
|
|
590
|
+
compiler_strategy: digest
|
|
591
|
+
useContentHash: true # Enforced regardless
|
|
592
|
+
```
|
|
593
|
+
|
|
594
|
+
### Custom Environments
|
|
595
|
+
|
|
596
|
+
For custom environments (e.g., `staging`), define a section or let it fall back to production:
|
|
597
|
+
|
|
598
|
+
```yaml
|
|
599
|
+
# Option 1: Explicit staging config
|
|
600
|
+
staging:
|
|
601
|
+
<<: *default
|
|
602
|
+
compile: false
|
|
603
|
+
# staging-specific options
|
|
604
|
+
|
|
605
|
+
# Option 2: Let staging fall back to production
|
|
606
|
+
# (no staging section needed)
|
|
607
|
+
```
|
|
608
|
+
|
|
609
|
+
## Configuration Validation
|
|
610
|
+
|
|
611
|
+
Shakapacker validates configuration at runtime and provides helpful error messages:
|
|
612
|
+
|
|
613
|
+
- **Missing config files:** Suggests creating config or checking `assets_bundler_config_path`
|
|
614
|
+
- **Transpiler mismatch:** Warns if package.json dependencies don't match configured transpiler
|
|
615
|
+
- **Path conflicts:** Prevents `private_output_path` from being the same as `public_output_path`
|
|
616
|
+
- **Version mismatches:** Detects gem/npm version differences when `ensure_consistent_versioning` is enabled
|
|
617
|
+
|
|
618
|
+
## Environment Variables
|
|
619
|
+
|
|
620
|
+
Some options can be overridden via environment variables:
|
|
621
|
+
|
|
622
|
+
| Variable | Description | Example |
|
|
623
|
+
| ---------------------------- | -------------------------------------------------- | ---------------------------- |
|
|
624
|
+
| `SHAKAPACKER_CONFIG` | Path to shakapacker.yml | `config/webpack.yml` |
|
|
625
|
+
| `SHAKAPACKER_ASSETS_BUNDLER` | Override assets bundler | `rspack` |
|
|
626
|
+
| `SHAKAPACKER_PRECOMPILE` | Override precompile flag | `false` |
|
|
627
|
+
| `SHAKAPACKER_ASSET_HOST` | Override asset host | `https://cdn.example.com` |
|
|
628
|
+
| `SHAKAPACKER_PUBLIC_*` | Auto-exposed to client-side JS (prefix convention) | `SHAKAPACKER_PUBLIC_API_URL` |
|
|
629
|
+
| `SHAKAPACKER_ENV_VARS` | Additional env vars to expose to client-side JS | `API_URL,FEATURE_FLAGS` |
|
|
630
|
+
| `NODE_ENV` | Node environment | `production` |
|
|
631
|
+
| `RAILS_ENV` | Rails environment | `staging` |
|
|
632
|
+
|
|
633
|
+
### Exposing Environment Variables to Client-Side JavaScript
|
|
634
|
+
|
|
635
|
+
By default, only `NODE_ENV`, `RAILS_ENV`, and `WEBPACK_SERVE` are exposed to client-side JavaScript via webpack/rspack's `EnvironmentPlugin`. This is a security measure to prevent accidentally leaking secrets like `DATABASE_URL`, `API_SECRET_KEY`, etc. into your JavaScript bundles.
|
|
636
|
+
|
|
637
|
+
#### SHAKAPACKER*PUBLIC*\* Prefix (Recommended)
|
|
638
|
+
|
|
639
|
+
Any environment variable prefixed with `SHAKAPACKER_PUBLIC_` is automatically exposed to client-side code. This follows the same convention used by Next.js (`NEXT_PUBLIC_*`) and Vite (`VITE_*`):
|
|
640
|
+
|
|
641
|
+
```bash
|
|
642
|
+
# These are automatically available in your JavaScript
|
|
643
|
+
export SHAKAPACKER_PUBLIC_API_URL=https://api.example.com
|
|
644
|
+
export SHAKAPACKER_PUBLIC_ANALYTICS_ID=UA-12345
|
|
645
|
+
export SHAKAPACKER_PUBLIC_FEATURE_FLAGS=dark_mode,beta_ui
|
|
646
|
+
```
|
|
647
|
+
|
|
648
|
+
```javascript
|
|
649
|
+
// Access in your JavaScript code
|
|
650
|
+
console.log(process.env.SHAKAPACKER_PUBLIC_API_URL)
|
|
651
|
+
console.log(process.env.SHAKAPACKER_PUBLIC_ANALYTICS_ID)
|
|
652
|
+
```
|
|
653
|
+
|
|
654
|
+
The prefix makes it explicit which variables are intended for client-side use, preventing accidental exposure of secrets.
|
|
655
|
+
|
|
656
|
+
#### SHAKAPACKER_ENV_VARS (Legacy/Escape Hatch)
|
|
657
|
+
|
|
658
|
+
For variables without the `SHAKAPACKER_PUBLIC_` prefix, you can use `SHAKAPACKER_ENV_VARS` to expose them:
|
|
659
|
+
|
|
660
|
+
```bash
|
|
661
|
+
# Expose additional variables during build
|
|
662
|
+
SHAKAPACKER_ENV_VARS=API_BASE_URL,FEATURE_FLAGS bundle exec rake assets:precompile
|
|
663
|
+
|
|
664
|
+
# In development
|
|
665
|
+
SHAKAPACKER_ENV_VARS=API_BASE_URL bin/shakapacker-dev-server
|
|
666
|
+
```
|
|
667
|
+
|
|
668
|
+
```javascript
|
|
669
|
+
// These are available after adding to SHAKAPACKER_ENV_VARS
|
|
670
|
+
console.log(process.env.API_BASE_URL)
|
|
671
|
+
console.log(process.env.FEATURE_FLAGS)
|
|
672
|
+
```
|
|
673
|
+
|
|
674
|
+
## Best Practices
|
|
675
|
+
|
|
676
|
+
1. **Use default paths** unless you have a specific reason to change them
|
|
677
|
+
2. **Enable SWC transpiler** for faster builds (20x faster than Babel)
|
|
678
|
+
3. **Use rspack** for even faster builds if compatible with your setup
|
|
679
|
+
4. **Cache manifest** in production for better performance
|
|
680
|
+
5. **Enable integrity hashes** in production for security
|
|
681
|
+
6. **Keep development and production configs aligned** except for optimization settings
|
|
682
|
+
7. **Use content hashes** in production for proper cache busting
|
|
683
|
+
8. **Validate after changes** by running `bin/shakapacker` to ensure compilation works
|
|
684
|
+
|
|
685
|
+
## Common Configuration Patterns
|
|
686
|
+
|
|
687
|
+
### Fast Development Setup
|
|
688
|
+
|
|
689
|
+
```yaml
|
|
690
|
+
development:
|
|
691
|
+
assets_bundler: "rspack"
|
|
692
|
+
javascript_transpiler: "swc"
|
|
693
|
+
compiler_strategy: mtime
|
|
694
|
+
webpack_compile_output: true
|
|
695
|
+
dev_server:
|
|
696
|
+
hmr: true
|
|
697
|
+
inline_css: true
|
|
698
|
+
```
|
|
699
|
+
|
|
700
|
+
### Production-Optimized
|
|
701
|
+
|
|
702
|
+
```yaml
|
|
703
|
+
production:
|
|
704
|
+
assets_bundler: "rspack"
|
|
705
|
+
javascript_transpiler: "swc"
|
|
706
|
+
compiler_strategy: digest
|
|
707
|
+
cache_manifest: true
|
|
708
|
+
useContentHash: true
|
|
709
|
+
integrity:
|
|
710
|
+
enabled: true
|
|
711
|
+
```
|
|
712
|
+
|
|
713
|
+
### Monorepo Setup
|
|
714
|
+
|
|
715
|
+
```yaml
|
|
716
|
+
default: &default
|
|
717
|
+
source_path: packages/frontend/src
|
|
718
|
+
assets_bundler_config_path: build_configs/webpack
|
|
719
|
+
additional_paths:
|
|
720
|
+
- packages/shared
|
|
721
|
+
- packages/ui-components
|
|
722
|
+
```
|
|
723
|
+
|
|
724
|
+
## Build Configurations (config/shakapacker-builds.yml)
|
|
725
|
+
|
|
726
|
+
Shakapacker supports defining reusable build configurations in `config/shakapacker-builds.yml`. This allows you to run predefined builds with a simple command, making it easy to switch between different build scenarios.
|
|
727
|
+
|
|
728
|
+
### Creating a Build Configuration File
|
|
729
|
+
|
|
730
|
+
Generate `config/shakapacker-builds.yml` with example builds:
|
|
731
|
+
|
|
732
|
+
```bash
|
|
733
|
+
bin/shakapacker --init # Creates config/shakapacker-builds.yml
|
|
734
|
+
```
|
|
735
|
+
|
|
736
|
+
This generates a file with example builds for common scenarios (HMR development, standard development, and production).
|
|
737
|
+
|
|
738
|
+
### Running Builds by Name
|
|
739
|
+
|
|
740
|
+
Once you have `config/shakapacker-builds.yml`, you can run builds by name:
|
|
741
|
+
|
|
742
|
+
```bash
|
|
743
|
+
# List available builds
|
|
744
|
+
bin/shakapacker --list-builds
|
|
745
|
+
|
|
746
|
+
# Run a specific build
|
|
747
|
+
bin/shakapacker --build dev-hmr # Client bundle with HMR (automatically uses dev server)
|
|
748
|
+
bin/shakapacker --build prod # Client and server bundles for production
|
|
749
|
+
bin/shakapacker --build dev # Client bundle for development
|
|
750
|
+
```
|
|
751
|
+
|
|
752
|
+
### Build Configuration Format
|
|
753
|
+
|
|
754
|
+
Example `config/shakapacker-builds.yml`:
|
|
755
|
+
|
|
756
|
+
```yaml
|
|
757
|
+
builds:
|
|
758
|
+
dev-hmr:
|
|
759
|
+
description: Client bundle with HMR (React Fast Refresh)
|
|
760
|
+
bundler: rspack # Optional: override assets_bundler from config/shakapacker.yml
|
|
761
|
+
environment:
|
|
762
|
+
NODE_ENV: development
|
|
763
|
+
RAILS_ENV: development
|
|
764
|
+
WEBPACK_SERVE: "true" # Automatically uses bin/shakapacker-dev-server
|
|
765
|
+
outputs:
|
|
766
|
+
- client
|
|
767
|
+
config: config/${BUNDLER}/custom.config.js # Optional: custom config file with variable substitution
|
|
768
|
+
|
|
769
|
+
prod:
|
|
770
|
+
description: Production client and server bundles
|
|
771
|
+
environment:
|
|
772
|
+
NODE_ENV: production
|
|
773
|
+
RAILS_ENV: production
|
|
774
|
+
outputs:
|
|
775
|
+
- client # Multiple outputs - builds both client and server bundles
|
|
776
|
+
- server
|
|
777
|
+
```
|
|
778
|
+
|
|
779
|
+
### Build Configuration Options
|
|
780
|
+
|
|
781
|
+
- **`description`** (optional): Human-readable description of the build
|
|
782
|
+
- **`bundler`** (optional): Override the default bundler from `config/shakapacker.yml` (`webpack` or `rspack`)
|
|
783
|
+
- **`dev_server`** (optional): Boolean flag to force routing to dev server (overrides environment variable detection)
|
|
784
|
+
- **`environment`**: Environment variables to set when running the build
|
|
785
|
+
- **`outputs`**: Array of output types - can include `client`, `server`, or both for multiple bundles in a single build
|
|
786
|
+
- **`config`** (optional): Custom config file path (supports `${BUNDLER}` variable substitution)
|
|
787
|
+
- **`bundler_env`** (optional): Key-value pairs passed as bundler `--env` flags (e.g., `{ analyze: true }` becomes `--env analyze=true`)
|
|
788
|
+
|
|
789
|
+
### Automatic Dev Server Detection
|
|
790
|
+
|
|
791
|
+
Shakapacker automatically uses `bin/shakapacker-dev-server` instead of the regular build command when:
|
|
792
|
+
|
|
793
|
+
1. The build has `dev_server: true` explicitly set (preferred method - takes precedence over environment variables), OR
|
|
794
|
+
2. The build has `WEBPACK_SERVE=true` or `HMR=true` in its environment variables (fallback for backward compatibility)
|
|
795
|
+
|
|
796
|
+
Example:
|
|
797
|
+
|
|
798
|
+
```bash
|
|
799
|
+
# These are equivalent:
|
|
800
|
+
bin/shakapacker --build dev-hmr
|
|
801
|
+
WEBPACK_SERVE=true bin/shakapacker-dev-server # (with dev-hmr environment vars)
|
|
802
|
+
```
|
|
803
|
+
|
|
804
|
+
### Variable Substitution
|
|
805
|
+
|
|
806
|
+
The `config` field supports `${BUNDLER}` substitution:
|
|
807
|
+
|
|
808
|
+
```yaml
|
|
809
|
+
builds:
|
|
810
|
+
custom:
|
|
811
|
+
bundler: rspack
|
|
812
|
+
config: config/${BUNDLER}/custom.config.js # Becomes: config/rspack/custom.config.js
|
|
813
|
+
```
|
|
814
|
+
|
|
815
|
+
### When to Use Build Configurations
|
|
816
|
+
|
|
817
|
+
Build configurations are useful for:
|
|
818
|
+
|
|
819
|
+
- **Multiple build scenarios**: Use when you need different builds for HMR development, standard development, and production
|
|
820
|
+
- **CI/CD pipelines**: Use when you want predefined builds that can be referenced in deployment scripts
|
|
821
|
+
- **Team consistency**: Use to ensure all developers use the same build configurations
|
|
822
|
+
- **Complex setups**: Use to manage different bundler configs or environment variables for different scenarios
|
|
823
|
+
|
|
824
|
+
## Troubleshooting
|
|
825
|
+
|
|
826
|
+
If you encounter configuration issues:
|
|
827
|
+
|
|
828
|
+
1. **Check error messages** - they often suggest the fix
|
|
829
|
+
2. **Validate YAML syntax** - use a YAML validator to ensure proper formatting
|
|
830
|
+
3. **Review fallback behavior** - missing environment configs fall back to production
|
|
831
|
+
4. **Check environment variables** - they override config file settings
|
|
832
|
+
5. **Inspect manifest.json** - verify assets are being compiled correctly
|
|
833
|
+
|
|
834
|
+
See [Troubleshooting Guide](troubleshooting.md) for more help.
|
|
835
|
+
|
|
836
|
+
## Related Guides
|
|
837
|
+
|
|
838
|
+
- [RSpack Migration Guide](rspack_migration_guide.md)
|
|
839
|
+
- [Transpiler Performance Guide](transpiler-performance.md)
|
|
840
|
+
- [Deployment Guide](deployment.md)
|
|
841
|
+
- [CDN Setup Guide](cdn_setup.md)
|
|
842
|
+
- [Precompile Hook Guide](precompile_hook.md)
|
|
843
|
+
- [Early Hints Guide](early_hints.md)
|
|
844
|
+
- [Subresource Integrity Guide](subresource_integrity.md)
|
|
845
|
+
- [Troubleshooting Guide](troubleshooting.md)
|