Skip to content

Commit 34a1441

Browse files
authored
Add private_output_path configuration for SSR bundles (#592)
Introduces a new configuration option for managing server-side rendering (SSR) bundle outputs separately from public assets. This feature enables better organization and security for server-only bundles that should not be publicly accessible. Key improvements: - Add private_output_path configuration option to shakapacker.yml - Implement Configuration#private_output_path method with nil-safe handling - Default value set to 'ssr-generated' for consistent behavior - Gracefully returns nil when configuration is not set Configuration changes: - New optional setting: private_output_path in shakapacker.yml - Defaults to 'ssr-generated' directory relative to Rails root - Can be set to nil to disable the feature Implementation details: - Method safely handles nil values to prevent join errors - Follows existing configuration pattern for consistency - Includes comprehensive test coverage Impact on existing installations: - No breaking changes - feature is opt-in with sensible defaults - Existing installations without SSR are unaffected - New installations get the default 'ssr-generated' path configured Use cases: - Server-side rendering bundles that shouldn't be served publicly - Separation of public and private webpack outputs - Better security isolation for server-only JavaScript bundles
1 parent 20e3239 commit 34a1441

5 files changed

Lines changed: 29 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Changes since the last non-beta release.
1111

1212
### Added
1313
- Rspack support as an alternative assets bundler to webpack. Configure `assets_bundler: 'rspack'` in `shakapacker.yml` to use Rspack's faster Rust-based bundling with webpack-compatible APIs, built-in SWC loader, and CSS extraction. Automatic assets bundler detection in `bin/shakapacker` with fallback support for webpack configurations.
14+
- Add `private_output_path` configuration option for server-side rendering bundles. This allows specifying a separate output directory for private server bundles that shouldn't be served publicly. [PR 592](https://github.com/shakacode/shakapacker/pull/592) by [justin808](https://github.com/justin808).
1415

1516
### Changed
1617
- Configuration option renamed from `bundler` to `assets_bundler` to avoid confusion with Ruby's Bundler gem manager. The old `bundler` option is deprecated but still supported with a warning (not a breaking change).
@@ -21,7 +22,7 @@ Changes since the last non-beta release.
2122
- Note: Default imports (`import styles from '...'`) will no longer work as css-loader with `namedExport: true` doesn't generate a default export
2223
- See the [CSS Modules Export Mode documentation](./docs/css-modules-export-mode.md) for detailed migration instructions and override options
2324

24-
## [v8.4.0] - September 8, 2025
25+
## [v9.0.0.beta.2] - September 25, 2025
2526
### Added
2627

2728
* Support for subresource integrity. [PR 570](https://github.com/shakacode/shakapacker/pull/570) by [panagiotisplytas](https://github.com/panagiotisplytas)

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -931,6 +931,15 @@ source_path: frontend # packs are the files in frontend/
931931
public_output_path: assets/packs # outputs to => public/assets/packs
932932
```
933933
934+
For server-side rendering (SSR) scenarios where you need to generate bundles that should not be served publicly, you can use the `private_output_path` configuration:
935+
936+
```yml
937+
# config/shakapacker.yml
938+
private_output_path: ssr-generated # outputs to => ssr-generated/
939+
```
940+
941+
This is particularly useful when working with libraries like React on Rails where server bundles need to be kept separate from client bundles.
942+
934943
Similarly, you can also control and configure `webpack-dev-server` settings from `config/shakapacker.yml` file:
935944
936945
```yml

lib/install/config/shakapacker.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ default: &default
2929
# Location for manifest.json, defaults to {public_output_path}/manifest.json if unset
3030
# manifest_path: public/packs/manifest.json
3131

32+
# Location for private output, defaults to ssr-generated
33+
# This setting is for generating bundles that are only used in server-side rendering
34+
# and should not be served publicly (alternative to public_output_path)
35+
# Output path for private server-side bundles (e.g., for SSR)
36+
private_output_path: ssr-generated
37+
3238
# Additional paths webpack should look up modules
3339
# ['app/assets', 'engine/foo/app/assets']
3440
additional_paths: []

lib/shakapacker/configuration.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ def public_path
6868
root_path.join(fetch(:public_root_path))
6969
end
7070

71+
def private_output_path
72+
private_path = fetch(:private_output_path)
73+
return nil unless private_path
74+
root_path.join(private_path)
75+
end
76+
7177
def public_output_path
7278
public_path.join(fetch(:public_output_path))
7379
end

spec/shakapacker/configuration_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@
5454
expect(config.cache_path.to_s).to eq cache_path
5555
end
5656

57+
it "#private_output_path returns correct path" do
58+
private_output_path = File.expand_path File.join(File.dirname(__FILE__), "./test_app/ssr-generated").to_s
59+
60+
expect(config.private_output_path.to_s).to eq private_output_path
61+
end
62+
5763
it "#additional_paths returns correct path" do
5864
expect(config.additional_paths).to eq ["app/assets", "/etc/yarn", "some.config.js", "app/elm"]
5965
end

0 commit comments

Comments
 (0)