@@ -8,17 +8,6 @@ const { RSCWebpackPlugin } = require('react-on-rails-rsc/WebpackPlugin');
88const commonWebpackConfig = require ( './commonWebpackConfig' ) ;
99const { getBundler } = require ( './bundlerUtils' ) ;
1010
11- /**
12- * Locates a loader in a rule's `use` array by loader name substring.
13- *
14- * Exposed on the module exports so rscWebpackConfig.js can call it when
15- * deriving the RSC bundle from serverWebpackConfig(true). Matches the
16- * `extractLoader` helper used in the Pro dummy and marketplace references.
17- *
18- * @param {Object } rule Webpack module rule with a `use` array
19- * @param {string } loaderName Substring to match against each loader's name
20- * @returns {Object|string|undefined } Matching loader entry, or undefined
21- */
2211function extractLoader ( rule , loaderName ) {
2312 if ( ! Array . isArray ( rule . use ) ) return undefined ;
2413 return rule . use . find ( ( item ) => {
@@ -27,26 +16,6 @@ function extractLoader(rule, loaderName) {
2716 } ) ;
2817}
2918
30- /**
31- * Generates the server-side rendering (SSR) bundle configuration for Pro's
32- * Node renderer.
33- *
34- * Key Pro-specific settings (applied after shakapacker's generated config):
35- * - target: 'node' + node: false — required for Node execution in the renderer
36- * - libraryTarget: 'commonjs2' — required so the renderer can `require()` the bundle
37- * - RSCWebpackPlugin({ isServer: true }) — emits the server manifest used by
38- * React Server Components (inert until RSC support is enabled in Sub-PR 3)
39- * - babelLoader caller = { ssr: true } — lets Babel pick SSR-specific transforms
40- * - CSS extraction disabled; css-loader switches to exportOnlyLocals for class
41- * name mapping only
42- *
43- * The `rscBundle` arg exists so Sub-PR 3's rscWebpackConfig.js can derive the
44- * RSC bundle from this same config — when true, the server-manifest plugin is
45- * skipped (the RSC bundle emits the client manifest instead).
46- *
47- * @param {boolean } [rscBundle=false] True when called from rscWebpackConfig.js
48- * @returns {Object } Webpack configuration object for the SSR bundle
49- */
5019const configureServer = ( rscBundle = false ) => {
5120 const bundler = getBundler ( ) ;
5221
@@ -56,7 +25,6 @@ const configureServer = (rscBundle = false) => {
5625 // Using webpack-merge into an empty object avoids this issue.
5726 const serverWebpackConfig = commonWebpackConfig ( ) ;
5827
59- // We just want the single server bundle entry
6028 const serverEntry = {
6129 'server-bundle' : serverWebpackConfig . entry [ 'server-bundle' ] ,
6230 } ;
@@ -80,18 +48,15 @@ const configureServer = (rscBundle = false) => {
8048
8149 serverWebpackConfig . entry = serverEntry ;
8250
83- // No splitting of chunks for a server bundle
8451 serverWebpackConfig . optimization = {
8552 minimize : false ,
8653 } ;
8754 serverWebpackConfig . plugins . unshift ( new bundler . optimize . LimitChunkCountPlugin ( { maxChunks : 1 } ) ) ;
8855
8956 if ( ! rscBundle ) {
90- // Limit client-reference discovery to the app source directory. Without
91- // `clientReferences`, the plugin may traverse into node_modules/ and hit
92- // non-JS source files (e.g. .tsx that aren't configured for a loader),
93- // and would re-scan nodes we don't care about. Matches the Pro dummy
94- // pattern in react_on_rails_pro/spec/dummy/config/webpack/serverWebpackConfig.js.
57+ // Scope client-reference discovery to the app source dir. Without this,
58+ // the plugin can walk into node_modules and hit .tsx source files that
59+ // aren't configured for a loader. Matches the Pro dummy pattern.
9560 serverWebpackConfig . plugins . push (
9661 new RSCWebpackPlugin ( {
9762 isServer : true ,
@@ -102,21 +67,16 @@ const configureServer = (rscBundle = false) => {
10267 ) ;
10368 }
10469
105- // Custom output for the server-bundle.
106- // - libraryTarget: 'commonjs2' is required by the Pro Node renderer so it
107- // can `require()` the evaluated bundle.
108- // - No publicPath: the server bundle is loaded by the Node renderer via the
109- // filesystem, never served over HTTP, so asset URLs would go unused.
70+ // libraryTarget: 'commonjs2' is required by the Pro Node renderer so it can
71+ // `require()` the evaluated bundle. No publicPath: the server bundle is
72+ // loaded from the filesystem, never served over HTTP.
11073 serverWebpackConfig . output = {
11174 filename : 'server-bundle.js' ,
11275 globalObject : 'this' ,
11376 libraryTarget : 'commonjs2' ,
11477 path : path . resolve ( __dirname , '../../ssr-generated' ) ,
11578 } ;
11679
117- // Don't hash the server bundle b/c would conflict with the client manifest
118- // And no need for CSS extraction plugins (webpack's MiniCssExtractPlugin or
119- // rspack's CssExtractRspackPlugin).
12080 serverWebpackConfig . plugins = serverWebpackConfig . plugins . filter (
12181 ( plugin ) =>
12282 plugin . constructor . name !== 'WebpackAssetsManifest' &&
@@ -125,11 +85,6 @@ const configureServer = (rscBundle = false) => {
12585 plugin . constructor . name !== 'ForkTsCheckerWebpackPlugin' ,
12686 ) ;
12787
128- // Configure loader rules for SSR:
129- // - strip CSS extraction and style-loader (client build handles CSS export)
130- // - css-loader exportOnlyLocals: true (keep class name mapping only)
131- // - babel-loader caller.ssr: true (Babel picks SSR-specific transforms)
132- // - url/file-loader emitFile: false (don't duplicate image assets during SSR)
13388 serverWebpackConfig . module . rules . forEach ( ( rule ) => {
13489 if ( Array . isArray ( rule . use ) ) {
13590 rule . use = rule . use . filter ( ( item ) => {
@@ -161,16 +116,12 @@ const configureServer = (rscBundle = false) => {
161116 }
162117 } ) ;
163118
164- // eval works well for the SSR bundle because it's the fastest and shows
165- // lines in the server bundle which is good for debugging SSR.
166119 serverWebpackConfig . devtool = 'eval' ;
167120
168- // Target 'node' so the bundle uses real CommonJS require() and Node globals
169- // like __dirname. Avoids polyfills and fixes libraries like Emotion and
170- // loadable-components that break under target: 'web' in SSR .
121+ // target: 'node' fixes SSR breakage in libraries (Emotion, loadable-components, etc.)
122+ // that don't behave under the default 'web' target. node: false disables the
123+ // polyfill shims that only matter when targeting 'web'.
171124 serverWebpackConfig . target = 'node' ;
172-
173- // Disable Node.js polyfill shims — not needed when targeting Node.
174125 serverWebpackConfig . node = false ;
175126
176127 return serverWebpackConfig ;
0 commit comments