Skip to content

Commit

Permalink
Merge branch 'main' into use-enhanced-resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
ScriptedAlchemy authored Nov 17, 2024
2 parents 35f40b0 + 5ad75fd commit f8226db
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/red-meals-sleep.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@module-federation/nextjs-mf': minor
---

Enabled JSON manifest remote protocol for NextJS plugin
36 changes: 36 additions & 0 deletions packages/nextjs-mf/src/plugins/container/runtimePlugin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { FederationRuntimePlugin } from '@module-federation/runtime/types';
import {
ModuleInfo,
ConsumerModuleInfoWithPublicPath,
} from '@module-federation/sdk';

export default function (): FederationRuntimePlugin {
return {
Expand Down Expand Up @@ -182,7 +186,39 @@ export default function (): FederationRuntimePlugin {

return args;
},
loadRemoteSnapshot(args) {
const { from, remoteSnapshot, manifestUrl, manifestJson, options } = args;

// ensure snapshot is loaded from manifest
if (
from !== 'manifest' ||
!manifestUrl ||
!manifestJson ||
!('publicPath' in remoteSnapshot)
) {
return args;
}

// re-assign publicPath based on remoteEntry location
if (options.inBrowser) {
remoteSnapshot.publicPath = remoteSnapshot.publicPath.substring(
0,
remoteSnapshot.publicPath.lastIndexOf('/_next/') + 7,
);
} else {
const serverPublicPath = manifestUrl.substring(
0,
manifestUrl.indexOf('mf-manifest.json'),
);

remoteSnapshot.publicPath = serverPublicPath;
if ('publicPath' in manifestJson.metaData) {
manifestJson.metaData.publicPath = serverPublicPath;
}
}

return args;
},
resolveShare: function (args: any) {
if (
args.pkgName !== 'react' &&
Expand Down

0 comments on commit f8226db

Please sign in to comment.