@module-federation/nextjs-mf 5.5.0 → 5.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. package/README.md +1 -27
  2. package/{lib/client → client}/CombinedPages.d.ts +27 -28
  3. package/client/CombinedPages.js +38 -0
  4. package/client/CombinedPages.js.map +1 -0
  5. package/{lib/client → client}/MFClient.d.ts +72 -73
  6. package/client/MFClient.js +159 -0
  7. package/client/MFClient.js.map +1 -0
  8. package/{lib/client → client}/RemoteContainer.d.ts +46 -58
  9. package/client/RemoteContainer.js +121 -0
  10. package/client/RemoteContainer.js.map +1 -0
  11. package/{lib/client → client}/RemotePages.d.ts +49 -49
  12. package/client/RemotePages.js +138 -0
  13. package/client/RemotePages.js.map +1 -0
  14. package/{lib/client → client}/UrlNode.d.ts +17 -18
  15. package/{lib/client → client}/UrlNode.js +157 -161
  16. package/client/UrlNode.js.map +1 -0
  17. package/{lib/client → client}/helpers.d.ts +16 -17
  18. package/{lib/client → client}/helpers.js +90 -104
  19. package/client/helpers.js.map +1 -0
  20. package/client/index.d.ts +2 -0
  21. package/client/index.js +6 -0
  22. package/client/index.js.map +1 -0
  23. package/{lib/client → client}/useMFClient.d.ts +24 -25
  24. package/client/useMFClient.js +55 -0
  25. package/client/useMFClient.js.map +1 -0
  26. package/{lib/client → client}/useMFRemote.d.ts +16 -17
  27. package/client/useMFRemote.js +50 -0
  28. package/client/useMFRemote.js.map +1 -0
  29. package/jest.config.d.ts +13 -0
  30. package/jest.config.js +18 -0
  31. package/jest.config.js.map +1 -0
  32. package/package.json +19 -42
  33. package/src/include-defaults.d.ts +0 -0
  34. package/{lib → src}/include-defaults.js +4 -3
  35. package/src/include-defaults.js.map +1 -0
  36. package/src/index.d.ts +3 -0
  37. package/src/index.js +9 -0
  38. package/src/index.js.map +1 -0
  39. package/src/internal.d.ts +12 -0
  40. package/src/internal.js +260 -0
  41. package/src/internal.js.map +1 -0
  42. package/src/loaders/fixImageLoader.d.ts +16 -0
  43. package/src/loaders/fixImageLoader.js +53 -0
  44. package/src/loaders/fixImageLoader.js.map +1 -0
  45. package/src/loaders/fixUrlLoader.d.ts +13 -0
  46. package/src/loaders/fixUrlLoader.js +25 -0
  47. package/src/loaders/fixUrlLoader.js.map +1 -0
  48. package/src/loaders/helpers.d.ts +10 -0
  49. package/src/loaders/helpers.js +46 -0
  50. package/src/loaders/helpers.js.map +1 -0
  51. package/src/loaders/nextPageMapLoader.d.ts +15 -0
  52. package/src/loaders/nextPageMapLoader.js +151 -0
  53. package/src/loaders/nextPageMapLoader.js.map +1 -0
  54. package/src/loaders/patchNextClientPageLoader.d.ts +7 -0
  55. package/src/loaders/patchNextClientPageLoader.js +43 -0
  56. package/src/loaders/patchNextClientPageLoader.js.map +1 -0
  57. package/src/plugins/AddRuntimeRequirementToPromiseExternalPlugin.d.ts +5 -0
  58. package/src/plugins/AddRuntimeRequirementToPromiseExternalPlugin.js +19 -0
  59. package/src/plugins/AddRuntimeRequirementToPromiseExternalPlugin.js.map +1 -0
  60. package/src/plugins/ChildFederationPlugin.d.ts +9 -0
  61. package/src/plugins/ChildFederationPlugin.js +281 -0
  62. package/src/plugins/ChildFederationPlugin.js.map +1 -0
  63. package/src/plugins/DevHmrFixInvalidPongPlugin.d.ts +11 -0
  64. package/src/plugins/DevHmrFixInvalidPongPlugin.js +55 -0
  65. package/src/plugins/DevHmrFixInvalidPongPlugin.js.map +1 -0
  66. package/src/plugins/ModuleFederationPlugin.d.ts +7 -0
  67. package/src/plugins/ModuleFederationPlugin.js +50 -0
  68. package/src/plugins/ModuleFederationPlugin.js.map +1 -0
  69. package/src/plugins/NextFederationPlugin.d.ts +9 -0
  70. package/src/plugins/NextFederationPlugin.js +111 -0
  71. package/src/plugins/NextFederationPlugin.js.map +1 -0
  72. package/src/plugins/RemoveRRRuntimePlugin.d.ts +5 -0
  73. package/src/plugins/RemoveRRRuntimePlugin.js +39 -0
  74. package/src/plugins/RemoveRRRuntimePlugin.js.map +1 -0
  75. package/utils/Template.d.ts +148 -0
  76. package/utils/Template.js +381 -0
  77. package/utils/Template.js.map +1 -0
  78. package/utils/build-utils.d.ts +3 -0
  79. package/utils/build-utils.js +175 -0
  80. package/utils/build-utils.js.map +1 -0
  81. package/utils/index.d.ts +1 -0
  82. package/utils/index.js +7 -0
  83. package/utils/index.js.map +1 -0
  84. package/.prettierignore +0 -2
  85. package/.prettierrc +0 -7
  86. package/LICENSE +0 -21
  87. package/lib/ModuleFederationPlugin.js +0 -84
  88. package/lib/NextFederationPlugin.js +0 -513
  89. package/lib/_virtual/Template.js +0 -7
  90. package/lib/_virtual/UrlNode.js +0 -9
  91. package/lib/_virtual/_commonjsHelpers.js +0 -44
  92. package/lib/_virtual/_fast-glob.js +0 -16
  93. package/lib/_virtual/_fs.js +0 -16
  94. package/lib/_virtual/_path.js +0 -16
  95. package/lib/_virtual/_tslib.js +0 -277
  96. package/lib/_virtual/_webpack-sources.js +0 -16
  97. package/lib/_virtual/fs.js +0 -4
  98. package/lib/_virtual/fs2.js +0 -7
  99. package/lib/_virtual/helpers.js +0 -7
  100. package/lib/_virtual/nextPageMapLoader.js +0 -7
  101. package/lib/_virtual/options.js +0 -7
  102. package/lib/_virtual/utils.js +0 -7
  103. package/lib/build-utils.js +0 -176
  104. package/lib/client/CombinedPages.d.ts.map +0 -1
  105. package/lib/client/CombinedPages.js +0 -60
  106. package/lib/client/MFClient.d.ts.map +0 -1
  107. package/lib/client/MFClient.js +0 -213
  108. package/lib/client/RemoteContainer.d.ts.map +0 -1
  109. package/lib/client/RemoteContainer.js +0 -162
  110. package/lib/client/RemotePages.d.ts.map +0 -1
  111. package/lib/client/RemotePages.js +0 -194
  112. package/lib/client/UrlNode.d.ts.map +0 -1
  113. package/lib/client/helpers.d.ts.map +0 -1
  114. package/lib/client/useMFClient.d.ts.map +0 -1
  115. package/lib/client/useMFClient.js +0 -79
  116. package/lib/client/useMFRemote.d.ts.map +0 -1
  117. package/lib/client/useMFRemote.js +0 -72
  118. package/lib/dependencies/webpack/lib/Template.js +0 -437
  119. package/lib/dependencies/webpack/lib/container/options.js +0 -102
  120. package/lib/dependencies/webpack/lib/sharing/utils.js +0 -104
  121. package/lib/dependencies/webpack/lib/util/fs.js +0 -359
  122. package/lib/index.js +0 -3
  123. package/lib/internal.js +0 -271
  124. package/lib/loaders/UrlNode.js +0 -219
  125. package/lib/loaders/fixImageLoader.js +0 -65
  126. package/lib/loaders/fixUrlLoader.js +0 -25
  127. package/lib/loaders/helpers.js +0 -60
  128. package/lib/loaders/nextPageMapLoader.js +0 -200
  129. package/lib/loaders/patchNextClientPageLoader.js +0 -53
  130. package/lib/plugins/DevHmrFixInvalidPongPlugin.js +0 -82
  131. package/lib/utils.js +0 -125
  132. package/node-plugin/README.md +0 -27
  133. package/node-plugin/package.json +0 -4
  134. package/node-plugin/streaming/CommonJsChunkLoadingPlugin.js +0 -89
  135. package/node-plugin/streaming/LoadFileChunkLoadingRuntimeModule.js +0 -410
  136. package/node-plugin/streaming/NodeRuntime.js +0 -245
  137. package/node-plugin/streaming/index.js +0 -42
  138. package/node-plugin/streaming/loadScript.js +0 -51
  139. package/tsconfig.json +0 -33
@@ -1,513 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var require$$1 = require('fs');
6
- var path = require('path');
7
- var helpers = require('./loaders/helpers.js');
8
- var nextPageMapLoader = require('./loaders/nextPageMapLoader.js');
9
- var DevHmrFixInvalidPongPlugin = require('./plugins/DevHmrFixInvalidPongPlugin.js');
10
- var internal = require('./internal.js');
11
- var ModuleFederationPlugin = require('./ModuleFederationPlugin.js');
12
-
13
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
14
-
15
- var require$$1__default = /*#__PURE__*/_interopDefaultLegacy(require$$1);
16
- var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
17
-
18
- /*
19
- MIT License http://www.opensource.org/licenses/mit-license.php
20
- Author Zackary Jackson @ScriptedAlchemy
21
- */
22
- 'use strict';
23
-
24
- const CHILD_PLUGIN_NAME = 'ChildFederationPlugin';
25
-
26
- class RemoveRRRuntimePlugin {
27
- /**
28
- * Apply the plugin
29
- * @param {Compiler} compiler the compiler instance
30
- * @returns {void}
31
- */
32
- apply(compiler) {
33
- const webpack = compiler.webpack;
34
- // only impacts dev mode - dont waste the memory during prod build
35
- if (compiler.options.mode === 'development') {
36
- compiler.hooks.thisCompilation.tap(
37
- 'RemoveRRRuntimePlugin',
38
- (compilation) => {
39
- compilation.hooks.processAssets.tap(
40
- {
41
- name: 'RemoveRRRuntimePlugin',
42
- state:
43
- compilation.constructor.PROCESS_ASSETS_STAGE_OPTIMIZE_INLINE,
44
- },
45
- (assets) => {
46
- //can this be improved? I need react refresh not to cause global collision in dev mode
47
- Object.keys(assets).forEach((filename) => {
48
- if (filename.endsWith('.js') || filename.endsWith('.mjs')) {
49
- const asset = compilation.getAsset(filename);
50
- // easiest way to solve it is to prevent react refresh helpers from running when its a federated module chunk
51
- const newSource = asset.source
52
- .source()
53
- .replace(/RefreshHelpers/g, 'NoExist');
54
- const updatedAsset = new webpack.sources.RawSource(newSource);
55
-
56
- if (asset) {
57
- compilation.updateAsset(filename, updatedAsset);
58
- } else {
59
- compilation.emitAsset(filename, updatedAsset);
60
- }
61
- }
62
- });
63
- }
64
- );
65
- }
66
- );
67
- }
68
- }
69
- }
70
-
71
- const computeRemoteFilename = (isServer, filename) => {
72
- if (isServer && filename) {
73
- return path__default["default"].basename(filename);
74
- }
75
- return filename;
76
- };
77
- const childCompilers = {};
78
- class ChildFederationPlugin {
79
- constructor(options, extraOptions = {}) {
80
- this._options = options;
81
- this._extraOptions = extraOptions;
82
- }
83
- /**
84
- * Apply the plugin
85
- * @param {Compiler} compiler the compiler instance
86
- * @returns {void}
87
- */
88
- apply(compiler) {
89
- const webpack = compiler.webpack;
90
- const LibraryPlugin = webpack.library.EnableLibraryPlugin;
91
- const LoaderTargetPlugin = webpack.LoaderTargetPlugin;
92
- const library = compiler.options.output.library;
93
- const isServer = compiler.options.name === 'server';
94
- const isDev = compiler.options.mode === 'development';
95
- let outputPath;
96
- if (isDev && isServer) {
97
- outputPath = path__default["default"].join(internal.getOutputPath(compiler), 'static/ssr');
98
- } else {
99
- if (isServer) {
100
- outputPath = path__default["default"].join(internal.getOutputPath(compiler), 'static/ssr');
101
- } else {
102
- outputPath = compiler.options.output.path;
103
- }
104
- }
105
-
106
- compiler.hooks.thisCompilation.tap(CHILD_PLUGIN_NAME, (compilation) => {
107
- const buildName = this._options.name;
108
- const childOutput = {
109
- ...compiler.options.output,
110
- path: outputPath,
111
- // path: deriveOutputPath(isServer, compiler.options.output.path),
112
- publicPath: 'auto',
113
- chunkLoadingGlobal: buildName + 'chunkLoader',
114
- uniqueName: buildName,
115
- library: {
116
- name: buildName,
117
- type: library.type,
118
- },
119
- chunkFilename: compiler.options.output.chunkFilename.replace(
120
- '.js',
121
- '-fed.js'
122
- ),
123
- filename: compiler.options.output.filename.replace('.js', '-fed.js'),
124
- };
125
-
126
- // using ModuleFederationPlugin does not work, i had to fork because of afterPlugins hook on containerPlugin.
127
- const FederationPlugin = ModuleFederationPlugin["default"];
128
-
129
- const federationPluginOptions = {
130
- // library: {type: 'var', name: buildName},
131
- ...this._options,
132
- filename: computeRemoteFilename(isServer, this._options.filename),
133
- exposes: {
134
- ...this._options.exposes,
135
- ...(this._extraOptions.exposePages
136
- ? nextPageMapLoader.exposeNextjsPages(compiler.options.context)
137
- : {}),
138
- },
139
- runtime: false,
140
- shared: {
141
- ...(this._extraOptions.skipSharingNextInternals
142
- ? {}
143
- : internal.externalizedShares),
144
- ...this._options.shared,
145
- },
146
- };
147
-
148
- let plugins;
149
- if (compiler.options.name === 'client') {
150
- plugins = [
151
- new FederationPlugin(federationPluginOptions),
152
- new webpack.web.JsonpTemplatePlugin(childOutput),
153
- new LoaderTargetPlugin('web'),
154
- new LibraryPlugin(this._options.library.type),
155
- new webpack.DefinePlugin({
156
- 'process.env.REMOTES': createRuntimeVariables(
157
- this._options.remotes
158
- ),
159
- 'process.env.CURRENT_HOST': JSON.stringify(this._options.name),
160
- }),
161
- new AddRuntimeRequirementToPromiseExternal(),
162
- ];
163
- } else if (compiler.options.name === 'server') {
164
- const StreamingTargetPlugin = require('../node-plugin/streaming').default;
165
- const NodeFederationPlugin = require('../node-plugin/streaming/NodeRuntime').default;
166
-
167
- plugins = [
168
- new NodeFederationPlugin(federationPluginOptions, {ModuleFederationPlugin: FederationPlugin}),
169
- new webpack.node.NodeTemplatePlugin(childOutput),
170
- //TODO: Externals function needs to internalize any shared module for host and remote build
171
- new webpack.ExternalsPlugin(compiler.options.externalsType, [
172
- // next dynamic needs to be within webpack, cannot be externalized
173
- ...Object.keys(internal.DEFAULT_SHARE_SCOPE).filter(
174
- (k) => k !== 'next/dynamic'
175
- ),
176
- 'react/jsx-runtime',
177
- 'react/jsx-dev-runtime',
178
- ]),
179
- // new LoaderTargetPlugin('async-node'),
180
- new StreamingTargetPlugin(federationPluginOptions, webpack),
181
- new LibraryPlugin(federationPluginOptions.library.type),
182
- // new webpack.DefinePlugin({
183
- // 'process.env.REMOTES': JSON.stringify(this._options.remotes),
184
- // 'process.env.CURRENT_HOST': JSON.stringify(this._options.name),
185
- // }),
186
- new AddRuntimeRequirementToPromiseExternal(),
187
- ];
188
- }
189
- const childCompiler = compilation.createChildCompiler(
190
- CHILD_PLUGIN_NAME,
191
- childOutput,
192
- plugins
193
- );
194
-
195
- childCompiler.outputPath = outputPath;
196
- childCompiler.options.module.rules.forEach((rule) => {
197
- // next-image-loader fix which adds remote's hostname to the assets url
198
- if (
199
- this._extraOptions.enableImageLoaderFix &&
200
- helpers.hasLoader(rule, 'next-image-loader')
201
- ) {
202
- helpers.injectRuleLoader(rule, {
203
- loader: path__default["default"].resolve(__dirname, './loaders/fixImageLoader.js'),
204
- });
205
- }
206
-
207
- // url-loader fix for which adds remote's hostname to the assets url
208
- if (
209
- this._extraOptions.enableUrlLoaderFix &&
210
- helpers.hasLoader(rule, 'url-loader')
211
- ) {
212
- helpers.injectRuleLoader({
213
- loader: path__default["default"].resolve(__dirname, './loaders/fixUrlLoader.js'),
214
- });
215
- }
216
- });
217
- childCompiler.options.experiments.lazyCompilation = false;
218
- childCompiler.options.optimization.runtimeChunk = false;
219
- // no custom chunk splitting should be derived from host (next)
220
- delete childCompiler.options.optimization.splitChunks;
221
- childCompiler.outputFileSystem = require$$1__default["default"];
222
-
223
- if (compiler.options.optimization.minimize) {
224
- for (const minimizer of compiler.options.optimization.minimizer) {
225
- if (typeof minimizer === "function") {
226
- minimizer.call(childCompiler, childCompiler);
227
- } else if (minimizer !== "...") {
228
- minimizer.apply(childCompiler);
229
- }
230
- }
231
- }
232
-
233
- new RemoveRRRuntimePlugin().apply(childCompiler);
234
-
235
- const MiniCss = childCompiler.options.plugins.find((p) => {
236
- return p.constructor.name === 'NextMiniCssExtractPlugin';
237
- });
238
-
239
- childCompiler.options.plugins = childCompiler.options.plugins.filter(
240
- (plugin) => !internal.removePlugins.includes(plugin.constructor.name)
241
- );
242
-
243
- if (MiniCss) {
244
- // grab mini-css and reconfigure it to avoid conflicts with host
245
- new MiniCss.constructor({
246
- ...MiniCss.options,
247
- filename: MiniCss.options.filename.replace('.css', '-fed.css'),
248
- chunkFilename: MiniCss.options.chunkFilename.replace(
249
- '.css',
250
- '-fed.css'
251
- ),
252
- }).apply(childCompiler);
253
- }
254
-
255
-
256
- // TODO: this can likely be deleted now, if running server child compiler under client is the best way to go
257
- // help wanted for all asset pipeline stuff below
258
- // let childAssets
259
- // if (isServer) {
260
- // childAssets = new Promise((resolve) => {
261
- // childCompiler.hooks.afterEmit.tap(
262
- // CHILD_PLUGIN_NAME,
263
- // (childCompilation) => {
264
- // console.log('after emit assets server');
265
- // resolve(childCompilation.assets);
266
- // }
267
- // );
268
- // });
269
- // } else {
270
- // if(isDev) {
271
- // childAssets = new Promise((resolve) => {
272
- // childCompiler.hooks.afterEmit.tap(
273
- // CHILD_PLUGIN_NAME,
274
- // (childCompilation) => {
275
- // resolve(childCompilation.assets);
276
- // }
277
- // );
278
- // });
279
- //
280
- // } else {
281
- //
282
- // TODO: improve this
283
- // childAssets = new Promise((resolve, reject) => {
284
- // fs.readdir(
285
- // path.join(childCompiler.context, '.next/ssr'),
286
- // function (err, files) {
287
- // if (err) {
288
- // reject('Unable to scan directory: ' + err);
289
- // return;
290
- // }
291
- //
292
- // const allFiles = files.map(function (file) {
293
- // return new Promise((res, rej) => {
294
- // fs.readFile(
295
- // path.join(childCompiler.context, '.next/ssr', file),
296
- // (err, data) => {
297
- // if (err) rej(err);
298
- // compilation.assets[path.join('static/ssr', file)] = new compiler.webpack.sources.RawSource(data)
299
- // res();
300
- // }
301
- // );
302
- // });
303
- // });
304
- // Promise.all(allFiles).then(resolve).catch(reject)
305
- // }
306
- // );
307
- // });
308
- // }
309
- // }
310
- // on main compiler add extra assets from server output to browser build
311
- // compilation.hooks.additionalAssets.tapPromise(CHILD_PLUGIN_NAME, () => {
312
- // console.log('additional hooks', compiler.options.name);
313
- // console.log('in additional assets hook for main build');
314
- // return childAssets
315
- // });
316
-
317
- // cache the serer compiler instance, we will run the server child compiler during the client main compilation
318
- // we need to do this because i need access to data from the client build to inject into the server build
319
- // in prod builds, server build runs first, followed by client build
320
- // in dev, client build runs first, followed by server build
321
- childCompilers[compiler.options.name] = childCompiler;
322
-
323
- if (isDev) {
324
- // in dev, run the compilers in the order they are created (client, server)
325
- childCompiler.run((err, stats) => {
326
- if (err) {
327
- compilation.errors.push(err);
328
- }
329
- if (stats && stats.hasErrors()) {
330
- compilation.errors.push(
331
- new Error(helpers.toDisplayErrors(stats.compilation.errors))
332
- );
333
- }
334
- });
335
- // in prod, if client
336
- } else if (!isServer) {
337
- // if ssr enabled and server in compiler cache
338
- if(childCompilers['server']) {
339
- //wrong hook for this
340
- // add hook for additional assets to prevent compile from sealing.
341
- compilation.hooks.additionalAssets.tapPromise(CHILD_PLUGIN_NAME, () => {
342
- return new Promise((res, rej) => {
343
- // run server child compilation during client main compilation
344
- childCompilers['server'].run((err, stats) => {
345
- if (err) {
346
- compilation.errors.push(err);
347
- rej();
348
- }
349
- if (stats && stats.hasErrors()) {
350
- compilation.errors.push(
351
- new Error(helpers.toDisplayErrors(stats.compilation.errors))
352
- );
353
- rej();
354
- }
355
- res();
356
- });
357
- });
358
- });
359
- }
360
- // run client child compiler like normal
361
- childCompiler.run((err, stats) => {
362
- if (err) {
363
- compilation.errors.push(err);
364
- }
365
- if (stats && stats.hasErrors()) {
366
- compilation.errors.push(
367
- new Error(helpers.toDisplayErrors(stats.compilation.errors))
368
- );
369
- }
370
- });
371
- }
372
- });
373
- }
374
- }
375
-
376
- class AddRuntimeRequirementToPromiseExternal {
377
- /**
378
- * Apply the plugin
379
- * @param {Compiler} compiler the compiler instance
380
- * @returns {void}
381
- */
382
- apply(compiler) {
383
- compiler.hooks.compilation.tap(
384
- 'AddRuntimeRequirementToPromiseExternal',
385
- (compilation) => {
386
- const RuntimeGlobals = compiler.webpack.RuntimeGlobals;
387
- // if (compilation.outputOptions.trustedTypes) {
388
- compilation.hooks.additionalModuleRuntimeRequirements.tap(
389
- 'AddRuntimeRequirementToPromiseExternal',
390
- (module, set, context) => {
391
- if (module.externalType === 'promise') {
392
- set.add(RuntimeGlobals.loadScript);
393
- set.add(RuntimeGlobals.require);
394
- }
395
- }
396
- );
397
- // }
398
- }
399
- );
400
- }
401
- }
402
-
403
- function createRuntimeVariables(remotes) {
404
- return Object.entries(remotes).reduce((acc, remote) => {
405
- // handle promise new promise and external new promise
406
- if (remote[1].startsWith('promise ') || remote[1].startsWith('external ')) {
407
- const promiseCall = remote[1]
408
- .replace('promise ', '')
409
- .replace('external ', '');
410
- acc[remote[0]] = `function() {
411
- return ${promiseCall}
412
- }`;
413
- return acc;
414
- }
415
- // if somehow its just the @ syntax or something else, pass it through
416
- acc[remote[0]] = JSON.stringify(remote[1]);
417
- return acc;
418
- }, {});
419
- }
420
-
421
- class NextFederationPlugin {
422
- constructor(options) {
423
- const {extraOptions, ...mainOpts} = options;
424
- this._options = mainOpts;
425
- this._extraOptions = extraOptions || {};
426
- }
427
-
428
- /**
429
- * Apply the plugin
430
- * @param {Compiler} compiler the compiler instance
431
- * @returns {void}
432
- */
433
- apply(compiler) {
434
- const isServer = compiler.options.name === 'server';
435
- const webpack = compiler.webpack;
436
- if (isServer) {
437
- console.error('[nextjs-mf] WARNING: SSR IS NOT FULLY SUPPORTED YET, Only use pluign on client builds');
438
- // target false because we use our own target for node env
439
- compiler.options.target = false;
440
- const StreamingTargetPlugin = require('../node-plugin/streaming').default;
441
- new StreamingTargetPlugin(this._options, webpack).apply(compiler);
442
- this._options.library = {};
443
- this._options.library.type = 'commonjs-module';
444
- this._options.library.name = this._options.name;
445
- // output remote to ssr if server
446
- this._options.filename = this._options.filename.replace(
447
- '/chunks',
448
- '/ssr'
449
- );
450
-
451
- // should this be a plugin that we apply to the compiler?
452
- internal.internalizeSharedPackages(this._options, compiler);
453
- } else {
454
- if (this._extraOptions.automaticPageStitching) {
455
- compiler.options.module.rules.push({
456
- test: /next[\\/]dist[\\/]client[\\/]page-loader\.js$/,
457
- loader: path__default["default"].resolve(__dirname, './loaders/patchNextClientPageLoader'),
458
- });
459
- }
460
-
461
- if (this._options.remotes) {
462
- this._options.remotes = internal.parseRemotes(this._options.remotes);
463
- }
464
- if (this._options.library) {
465
- console.error('[mf] you cannot set custom library');
466
- }
467
- this._options.library = {
468
- // assign remote name to object to avoid SWC mangling top level variable
469
- type: 'window',
470
- name: this._options.name,
471
- };
472
- }
473
- //todo runtime variable creation needs to be applied for server as well. this is just for client
474
- // todo: this needs to be refactored into something more comprehensive. this is just a quick fix
475
- new webpack.DefinePlugin({
476
- 'process.env.REMOTES': createRuntimeVariables(this._options.remotes),
477
- 'process.env.CURRENT_HOST': JSON.stringify(this._options.name),
478
- }).apply(compiler);
479
-
480
- const ModuleFederationPlugin = isServer ? require('../node-plugin/streaming/NodeRuntime').default : webpack.container.ModuleFederationPlugin;
481
-
482
- // ignore edge runtime and middleware builds
483
- if (ModuleFederationPlugin) {
484
- const internalShare = internal.reKeyHostShared(this._options.shared);
485
- const hostFederationPluginOptions = {
486
- ...this._options,
487
- exposes: {},
488
- shared: {
489
- noop: {
490
- import: 'data:text/javascript,module.exports = {};',
491
- requiredVersion: false,
492
- eager: true,
493
- version: '0',
494
- },
495
- ...internalShare,
496
- },
497
- };
498
-
499
- compiler.options.optimization.chunkIds = 'named';
500
-
501
- new ModuleFederationPlugin(hostFederationPluginOptions, {
502
- ModuleFederationPlugin,
503
- }).apply(compiler);
504
- new ChildFederationPlugin(this._options, this._extraOptions).apply(compiler);
505
- new AddRuntimeRequirementToPromiseExternal().apply(compiler);
506
- if (compiler.options.mode === 'development') {
507
- new DevHmrFixInvalidPongPlugin["default"]().apply(compiler);
508
- }
509
- }
510
- }
511
- }
512
-
513
- exports["default"] = NextFederationPlugin;
@@ -1,7 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var Template = {exports: {}};
6
-
7
- exports.Template = Template;
@@ -1,9 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var UrlNode = require('../loaders/UrlNode.js');
6
-
7
-
8
-
9
- exports["default"] = UrlNode["default"];
@@ -1,44 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
6
-
7
- function getDefaultExportFromCjs (x) {
8
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
9
- }
10
-
11
- function getDefaultExportFromNamespaceIfPresent (n) {
12
- return n && Object.prototype.hasOwnProperty.call(n, 'default') ? n['default'] : n;
13
- }
14
-
15
- function getDefaultExportFromNamespaceIfNotNamed (n) {
16
- return n && Object.prototype.hasOwnProperty.call(n, 'default') && Object.keys(n).length === 1 ? n['default'] : n;
17
- }
18
-
19
- function getAugmentedNamespace(n) {
20
- var f = n.default;
21
- if (typeof f == "function") {
22
- var a = function () {
23
- return f.apply(this, arguments);
24
- };
25
- a.prototype = f.prototype;
26
- } else a = {};
27
- Object.defineProperty(a, '__esModule', {value: true});
28
- Object.keys(n).forEach(function (k) {
29
- var d = Object.getOwnPropertyDescriptor(n, k);
30
- Object.defineProperty(a, k, d.get ? d : {
31
- enumerable: true,
32
- get: function () {
33
- return n[k];
34
- }
35
- });
36
- });
37
- return a;
38
- }
39
-
40
- exports.commonjsGlobal = commonjsGlobal;
41
- exports.getAugmentedNamespace = getAugmentedNamespace;
42
- exports.getDefaultExportFromCjs = getDefaultExportFromCjs;
43
- exports.getDefaultExportFromNamespaceIfNotNamed = getDefaultExportFromNamespaceIfNotNamed;
44
- exports.getDefaultExportFromNamespaceIfPresent = getDefaultExportFromNamespaceIfPresent;
@@ -1,16 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var require$$0 = require('fast-glob');
6
-
7
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
-
9
- var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0);
10
-
11
-
12
-
13
- Object.defineProperty(exports, 'default', {
14
- enumerable: true,
15
- get: function () { return require$$0__default["default"]; }
16
- });
@@ -1,16 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var require$$1 = require('fs');
6
-
7
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
-
9
- var require$$1__default = /*#__PURE__*/_interopDefaultLegacy(require$$1);
10
-
11
-
12
-
13
- Object.defineProperty(exports, 'default', {
14
- enumerable: true,
15
- get: function () { return require$$1__default["default"]; }
16
- });
@@ -1,16 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var path = require('path');
6
-
7
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
-
9
- var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
10
-
11
-
12
-
13
- Object.defineProperty(exports, 'default', {
14
- enumerable: true,
15
- get: function () { return path__default["default"]; }
16
- });