Skip to content

Commit 3d0a9c8

Browse files
add ability to disable SSR part of plugin
1 parent 01ed8b6 commit 3d0a9c8

File tree

3 files changed

+30
-15
lines changed

3 files changed

+30
-15
lines changed

README.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ withFederatedSidecar(
160160
},
161161
},
162162
{
163+
ssr: true, // if you want to disable the server runtimes, set to false. This will mean client side only.
163164
removePlugins: [
164165
// optional
165166
// these are the defaults
@@ -200,17 +201,18 @@ const remotes = (isServer) => {
200201
};
201202

202203
const nextConfig = {
203-
// your original next.config.js export
204-
// we attach next internals to share scope at runtime
204+
// your original next.config.js export
205+
// we attach next internals to share scope at runtime
205206

206-
webpack(config, options) {
207-
const { webpack, isServer } = options;
208-
config.module.rules.push({
209-
test: [/_app.[jt]sx?/, /_document.[jt]sx?/],
210-
loader: "@module-federation/nextjs-ssr/lib/federation-loader.js",
211-
});
207+
webpack(config, options) {
208+
const {webpack, isServer} = options;
209+
config.module.rules.push({
210+
test: [/_app.[jt]sx?/, /_document.[jt]sx?/],
211+
loader: "@module-federation/nextjs-ssr/lib/federation-loader.js",
212+
});
212213

213-
return config;
214+
return config;
215+
}
214216
};
215217

216218
module.exports = withPlugins(

lib/with-federated-sidecar.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ const withModuleFederation =
181181
experiments = {
182182
flushChunks: false,
183183
},
184+
ssr = true,
184185
removePlugins = [
185186
"BuildManifestPlugin",
186187
"DropClientPage",
@@ -391,20 +392,24 @@ const withModuleFederation =
391392
log.warning("warning:");
392393
log.warning(info.warnings);
393394
}
394-
const { outputPath, assets, name, chunks } = info;
395+
const { chunks } = info;
395396
const distPath = path.join(
396397
compilation.options.context,
397398
nextConfig.distDir
398399
);
399400
const hasStats = fs.existsSync(
400401
path.join(distPath, "static/federated-stats.json")
401402
);
402-
if (hasStats && experiments.flushChunks) {
403-
const remoteEntry = path.join(
404-
distPath,
405-
federationPluginOptions.filename.replace("chunks", "ssr")
403+
const hasRemote = fs.existsSync(
404+
path.join(distPath, "static/ssr/remoteEntry.js")
405+
);
406+
if (hasRemote && hasStats && experiments.flushChunks) {
407+
let remoteEntry = path.join(
408+
distPath,
409+
'static/ssr/remoteEntry.js'
406410
);
407411

412+
408413
const statContent = require(path.join(
409414
distPath,
410415
"static/federated-stats.json"
@@ -502,6 +507,14 @@ const withModuleFederation =
502507
* @returns {import("webpack").Configuration}
503508
*/
504509
webpack(config, options) {
510+
if(!ssr && options.isServer) {
511+
log('SSR Disabled')
512+
if (typeof nextConfig.webpack === "function") {
513+
return nextConfig.webpack(config, options);
514+
}
515+
516+
return config;
517+
}
505518
const { webpack } = options;
506519
Object.assign(config.experiments, {
507520
topLevelAwait: true,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"public": true,
33
"name": "@module-federation/nextjs-ssr",
4-
"version": "0.1.0-rc.8",
4+
"version": "0.2.0-rc.0",
55
"description": "Module Federation CSR & SSR Support for Next.js",
66
"main": "bundle.js",
77
"types": "index.d.ts",

0 commit comments

Comments
 (0)