Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,10 @@ lib/bs
/lib/ocaml

client/app/bundles/comments/rescript/**/*.bs.js

# Server-side rendering bundles (private)
# Using React on Rails default directory
/ssr-generated/

# Generated files
/client/app/generated/
5 changes: 5 additions & 0 deletions config/initializers/react_on_rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
# not affect performance.
config.server_bundle_js_file = "server-bundle.js"

# Server bundle output path for private SSR bundles (React on Rails 16+)
# This keeps server bundles separate from public assets for security
# Using the default from React on Rails docs
config.server_bundle_output_path = "ssr-generated"

# React on Rails 16 compatibility: Workaround for removed error handling
#
# BREAKING CHANGE in v16: React on Rails 14.2.1 had robust error handling that would
Expand Down
5 changes: 4 additions & 1 deletion config/webpack/serverWebpackConfig.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// The source code including full typescript support is available at:
// https://github.com/shakacode/react_on_rails_tutorial_with_ssr_and_hmr_fast_refresh/blob/master/config/webpack/serverWebpackConfig.js

const path = require('path');
const { config } = require('shakapacker');
const commonWebpackConfig = require('./commonWebpackConfig');

Expand Down Expand Up @@ -45,12 +46,14 @@ const configureServer = () => {

// Custom output for the server-bundle that matches the config in
// config/initializers/react_on_rails.rb
// Output to a private directory for SSR bundles (not in public/)
// Using the default React on Rails path: ssr-generated
serverWebpackConfig.output = {
filename: 'server-bundle.js',
globalObject: 'this',
// If using the React on Rails Pro node server renderer, uncomment the next line
// libraryTarget: 'commonjs2',
path: config.outputPath,
path: path.resolve(__dirname, '../../ssr-generated'),
publicPath: config.publicPath,
// https://webpack.js.org/configuration/output/#outputglobalobject
};
Expand Down
Loading