Skip to content

Commit affab37

Browse files
fix(nextjs-mf): use addInclude to ensure defaults are consumed somewhere (#3004)
1 parent 2042777 commit affab37

File tree

1 file changed

+26
-13
lines changed
  • packages/nextjs-mf/src/plugins/NextFederationPlugin

1 file changed

+26
-13
lines changed

packages/nextjs-mf/src/plugins/NextFederationPlugin/index.ts

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,32 @@ export class NextFederationPlugin {
8383
});
8484
},
8585
});
86-
const runtimeESMPath = require.resolve(
87-
'@module-federation/runtime/dist/index.esm.js',
88-
);
86+
87+
const noop = this.getNoopPath();
88+
89+
if (!this._extraOptions.skipSharingNextInternals) {
90+
compiler.hooks.make.tapAsync(
91+
'NextFederationPlugin',
92+
(compilation, callback) => {
93+
const dep = compiler.webpack.EntryPlugin.createDependency(
94+
noop,
95+
'noop',
96+
);
97+
compilation.addEntry(
98+
compiler.context,
99+
dep,
100+
{ name: 'noop' },
101+
(err, module) => {
102+
if (err) {
103+
return callback(err);
104+
}
105+
callback();
106+
},
107+
);
108+
},
109+
);
110+
}
111+
89112
if (!compiler.options.ignoreWarnings) {
90113
compiler.options.ignoreWarnings = [
91114
//@ts-ignore
@@ -171,16 +194,7 @@ export class NextFederationPlugin {
171194
const defaultShared = this._extraOptions.skipSharingNextInternals
172195
? {}
173196
: retrieveDefaultShared(isServer);
174-
const noop = this.getNoopPath();
175197

176-
const defaultExpose = this._extraOptions.skipSharingNextInternals
177-
? {}
178-
: {
179-
'./noop': noop,
180-
'./react': require.resolve('react'),
181-
'./react-dom': require.resolve('react-dom'),
182-
'./next/router': require.resolve('next/router'),
183-
};
184198
return {
185199
...this._options,
186200
runtime: false,
@@ -194,7 +208,6 @@ export class NextFederationPlugin {
194208
].map((plugin) => plugin + '?runtimePlugin'),
195209
//@ts-ignore
196210
exposes: {
197-
...defaultExpose,
198211
...this._options.exposes,
199212
...(this._extraOptions.exposePages
200213
? exposeNextjsPages(compiler.options.context as string)

0 commit comments

Comments
 (0)