@module-federation/nextjs-mf 6.4.0 → 6.4.1-beta.1

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 (101) hide show
  1. package/CHANGELOG.md +111 -0
  2. package/README.md +3 -0
  3. package/package.json +4 -4
  4. package/src/default-delegate.d.ts +2 -0
  5. package/src/default-delegate.js +17 -0
  6. package/src/default-delegate.js.map +1 -0
  7. package/src/delegate-hoist-container.d.ts +0 -0
  8. package/src/delegate-hoist-container.js +2 -0
  9. package/src/delegate-hoist-container.js.map +1 -0
  10. package/src/index.d.ts +1 -1
  11. package/src/index.js +6 -5
  12. package/src/index.js.map +1 -1
  13. package/src/internal-delegate-hoist.js +1 -0
  14. package/src/internal-delegate-hoist.js.map +1 -1
  15. package/src/internal.d.ts +39 -9
  16. package/src/internal.js +149 -235
  17. package/src/internal.js.map +1 -1
  18. package/src/inverse-self-formation.d.ts +0 -0
  19. package/src/inverse-self-formation.js +2 -0
  20. package/src/inverse-self-formation.js.map +1 -0
  21. package/src/loaders/async-boundary-loader.js +10 -2
  22. package/src/loaders/async-boundary-loader.js.map +1 -1
  23. package/src/loaders/delegateLoader.js +2 -4
  24. package/src/loaders/delegateLoader.js.map +1 -1
  25. package/src/loaders/inject-hoist.d.ts +3 -0
  26. package/src/loaders/inject-hoist.js +8 -0
  27. package/src/loaders/inject-hoist.js.map +1 -0
  28. package/src/loaders/nextPageMapLoader.js +0 -2
  29. package/src/loaders/nextPageMapLoader.js.map +1 -1
  30. package/src/loaders/share-scope-hoist.d.ts +5 -0
  31. package/src/loaders/share-scope-hoist.js +52 -0
  32. package/src/loaders/share-scope-hoist.js.map +1 -0
  33. package/src/plugins/AddModulesToRuntime.d.ts +19 -0
  34. package/src/plugins/AddModulesToRuntime.js +268 -0
  35. package/src/plugins/AddModulesToRuntime.js.map +1 -0
  36. package/src/plugins/ContainerStatsPlugin.d.ts +6 -0
  37. package/src/plugins/ContainerStatsPlugin.js +176 -0
  38. package/src/plugins/ContainerStatsPlugin.js.map +1 -0
  39. package/src/plugins/CopyFederationPlugin.d.ts +7 -0
  40. package/src/plugins/CopyFederationPlugin.js +48 -0
  41. package/src/plugins/CopyFederationPlugin.js.map +1 -0
  42. package/src/plugins/NextFederationPlugin/apply-automatic-async-boundary.d.ts +11 -0
  43. package/src/plugins/NextFederationPlugin/apply-automatic-async-boundary.js +61 -0
  44. package/src/plugins/NextFederationPlugin/apply-automatic-async-boundary.js.map +1 -0
  45. package/src/plugins/NextFederationPlugin/apply-client-plugins.d.ts +24 -0
  46. package/src/plugins/NextFederationPlugin/apply-client-plugins.js +79 -0
  47. package/src/plugins/NextFederationPlugin/apply-client-plugins.js.map +1 -0
  48. package/src/plugins/NextFederationPlugin/apply-server-plugins.d.ts +61 -0
  49. package/src/plugins/NextFederationPlugin/apply-server-plugins.js +158 -0
  50. package/src/plugins/NextFederationPlugin/apply-server-plugins.js.map +1 -0
  51. package/src/plugins/NextFederationPlugin/index.d.ts +18 -0
  52. package/src/plugins/NextFederationPlugin/index.js +133 -0
  53. package/src/plugins/NextFederationPlugin/index.js.map +1 -0
  54. package/src/plugins/NextFederationPlugin/next-fragments.d.ts +44 -0
  55. package/src/plugins/NextFederationPlugin/next-fragments.js +115 -0
  56. package/src/plugins/NextFederationPlugin/next-fragments.js.map +1 -0
  57. package/src/plugins/NextFederationPlugin/regex-equal.d.ts +14 -0
  58. package/src/plugins/NextFederationPlugin/regex-equal.js +25 -0
  59. package/src/plugins/NextFederationPlugin/regex-equal.js.map +1 -0
  60. package/src/plugins/NextFederationPlugin/remove-unnecessary-shared-keys.d.ts +1 -0
  61. package/src/plugins/NextFederationPlugin/remove-unnecessary-shared-keys.js +20 -0
  62. package/src/plugins/NextFederationPlugin/remove-unnecessary-shared-keys.js.map +1 -0
  63. package/src/plugins/NextFederationPlugin/set-options.d.ts +21 -0
  64. package/src/plugins/NextFederationPlugin/set-options.js +35 -0
  65. package/src/plugins/NextFederationPlugin/set-options.js.map +1 -0
  66. package/src/plugins/NextFederationPlugin/validate-options.d.ts +26 -0
  67. package/src/plugins/NextFederationPlugin/validate-options.js +46 -0
  68. package/src/plugins/NextFederationPlugin/validate-options.js.map +1 -0
  69. package/src/plugins/async-pages-loader.d.ts +1 -0
  70. package/src/plugins/async-pages-loader.js +41 -0
  71. package/src/plugins/async-pages-loader.js.map +1 -0
  72. package/src/plugins/container/InvertedContainerPlugin.d.ts +25 -0
  73. package/src/plugins/container/InvertedContainerPlugin.js +73 -0
  74. package/src/plugins/container/InvertedContainerPlugin.js.map +1 -0
  75. package/src/plugins/container/InvertedContainerRuntimeModule.d.ts +42 -0
  76. package/src/plugins/container/InvertedContainerRuntimeModule.js +82 -0
  77. package/src/plugins/container/InvertedContainerRuntimeModule.js.map +1 -0
  78. package/src/plugins/container/types.d.ts +2 -0
  79. package/src/plugins/container/types.js +3 -0
  80. package/src/plugins/container/types.js.map +1 -0
  81. package/utils/Template.d.ts +1 -1
  82. package/utils/Template.js +1 -1
  83. package/utils/Template.js.map +1 -1
  84. package/utils/build-utils.d.ts +0 -8
  85. package/utils/build-utils.js +1 -228
  86. package/utils/build-utils.js.map +1 -1
  87. package/utils/index.d.ts +2 -2
  88. package/utils/index.js +8 -2
  89. package/utils/index.js.map +1 -1
  90. package/src/plugins/ChildFederationPlugin.d.ts +0 -11
  91. package/src/plugins/ChildFederationPlugin.js +0 -299
  92. package/src/plugins/ChildFederationPlugin.js.map +0 -1
  93. package/src/plugins/ModuleFederationPlugin.d.ts +0 -7
  94. package/src/plugins/ModuleFederationPlugin.js +0 -50
  95. package/src/plugins/ModuleFederationPlugin.js.map +0 -1
  96. package/src/plugins/NextFederationPlugin.d.ts +0 -9
  97. package/src/plugins/NextFederationPlugin.js +0 -234
  98. package/src/plugins/NextFederationPlugin.js.map +0 -1
  99. package/src/plugins/RemoveRRRuntimePlugin.d.ts +0 -5
  100. package/src/plugins/RemoveRRRuntimePlugin.js +0 -40
  101. package/src/plugins/RemoveRRRuntimePlugin.js.map +0 -1
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.applyAutomaticAsyncBoundary = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const regex_equal_1 = require("./regex-equal");
6
+ const path_1 = tslib_1.__importDefault(require("path"));
7
+ /**
8
+
9
+ Apply automatic async boundary.
10
+ @param {ModuleFederationPluginOptions} options - The ModuleFederationPluginOptions instance.
11
+ @param {NextFederationPluginExtraOptions} extraOptions - The NextFederationPluginExtraOptions instance.
12
+ @param {Compiler} compiler - The Webpack compiler instance.
13
+ @remarks This function applies an automatic async boundary to the Next.js application.
14
+ */
15
+ function applyAutomaticAsyncBoundary(options, extraOptions, compiler) {
16
+ const allowedPaths = ['pages/', 'app/', 'src/pages/', 'src/app/'];
17
+ const jsRules = compiler.options.module.rules.find((r) => {
18
+ //@ts-ignore
19
+ return r && r.oneOf;
20
+ });
21
+ //@ts-ignore
22
+ if (jsRules?.oneOf) {
23
+ // @ts-ignore
24
+ const foundJsLayer = jsRules.oneOf.find((r) => {
25
+ //@ts-ignore
26
+ return (0, regex_equal_1.regexEqual)(r.test, /\.(tsx|ts|js|cjs|mjs|jsx)$/) && !r.issuerLayer;
27
+ });
28
+ if (foundJsLayer) {
29
+ const loaderChain = Array.isArray(foundJsLayer.use)
30
+ ? foundJsLayer.use
31
+ : [foundJsLayer.use];
32
+ // Add a new rule for pages that need async boundaries
33
+ //@ts-ignore
34
+ jsRules.oneOf.unshift({
35
+ test: (request) => {
36
+ return (allowedPaths.some((p) => request.includes(path_1.default.join(compiler.context, p))) && /\.(js|jsx|ts|tsx|md|mdx|mjs)$/i.test(request));
37
+ },
38
+ exclude: [
39
+ /node_modules/,
40
+ /_document/,
41
+ /_middleware/,
42
+ /pages[\\/]middleware/,
43
+ /pages[\\/]api/,
44
+ ],
45
+ resourceQuery: (query) => !query.includes('hasBoundary'),
46
+ use: [
47
+ //@ts-ignore
48
+ ...loaderChain,
49
+ //@ts-ignore
50
+ {
51
+ // This loader auto-wraps page entrypoints
52
+ // and re-exports them as a dynamic import so module sharing works without eager issues.
53
+ loader: path_1.default.resolve(__dirname, '../../loaders/async-boundary-loader'),
54
+ },
55
+ ],
56
+ });
57
+ }
58
+ }
59
+ }
60
+ exports.applyAutomaticAsyncBoundary = applyAutomaticAsyncBoundary;
61
+ //# sourceMappingURL=apply-automatic-async-boundary.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apply-automatic-async-boundary.js","sourceRoot":"","sources":["../../../../../../packages/nextjs-mf/src/plugins/NextFederationPlugin/apply-automatic-async-boundary.ts"],"names":[],"mappings":";;;;AAKA,+CAA2C;AAC3C,wDAAwB;AAExB;;;;;;;GAOG;AACH,SAAgB,2BAA2B,CACzC,OAAsC,EACtC,YAA8C,EAC9C,QAAkB;IAElB,MAAM,YAAY,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,YAAY,EAAE,UAAU,CAAC,CAAC;IAElE,MAAM,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE;QACvD,YAAY;QACZ,OAAO,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC;IACtB,CAAC,CAAC,CAAC;IAEH,YAAY;IACZ,IAAI,OAAO,EAAE,KAAK,EAAE;QAClB,aAAa;QACb,MAAM,YAAY,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE;YAC5C,YAAY;YACZ,OAAO,IAAA,wBAAU,EAAC,CAAC,CAAC,IAAI,EAAE,4BAA4B,CAAC,IAAI,CAAC,CAAC,CAAC,WAAW,CAAC;QAC5E,CAAC,CAAC,CAAC;QAEH,IAAI,YAAY,EAAE;YAChB,MAAM,WAAW,GAAG,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,GAAG,CAAC;gBACjD,CAAC,CAAC,YAAY,CAAC,GAAG;gBAClB,CAAC,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;YAEvB,sDAAsD;YACtD,YAAY;YACZ,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC;gBACpB,IAAI,EAAE,CAAC,OAAe,EAAE,EAAE;oBACxB,OAAO,CACL,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CACtB,OAAO,CAAC,QAAQ,CAAC,cAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CACjD,IAAI,gCAAgC,CAAC,IAAI,CAAC,OAAO,CAAC,CACpD,CAAC;gBACJ,CAAC;gBACD,OAAO,EAAE;oBACP,cAAc;oBACd,WAAW;oBACX,aAAa;oBACb,sBAAsB;oBACtB,eAAe;iBAChB;gBACD,aAAa,EAAE,CAAC,KAAa,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,aAAa,CAAC;gBAChE,GAAG,EAAE;oBACH,YAAY;oBACZ,GAAG,WAAW;oBACd,YAAY;oBACZ;wBACE,0CAA0C;wBAC1C,wFAAwF;wBACxF,MAAM,EAAE,cAAI,CAAC,OAAO,CAClB,SAAS,EACT,qCAAqC,CACtC;qBACF;iBACF;aACF,CAAC,CAAC;SACJ;KACF;AACH,CAAC;AA3DD,kEA2DC"}
@@ -0,0 +1,24 @@
1
+ import { Compiler } from 'webpack';
2
+ import { ModuleFederationPluginOptions, NextFederationPluginExtraOptions } from '@module-federation/utilities';
3
+ /**
4
+ * Applies client-specific plugins.
5
+ *
6
+ * @param compiler - The Webpack compiler instance.
7
+ * @param options - The ModuleFederationPluginOptions instance.
8
+ * @param extraOptions - The NextFederationPluginExtraOptions instance.
9
+ *
10
+ * @remarks
11
+ * This function applies plugins to the Webpack compiler instance that are specific to the client build of
12
+ * a Next.js application with Module Federation enabled. These plugins include the following:
13
+ *
14
+ * - AddModulesPlugin: Adds modules to the webpack container runtime that can be streamed to other runtimes.
15
+ * - EntryPlugin: Creates an entry point for the application that delegates module loading to the container runtime.
16
+ * - ChunkCorrelationPlugin: Collects metadata on chunks to enable proper module loading across different runtimes.
17
+ * - InvertedContainerPlugin: Adds custom runtime modules to the container runtime to allow a host to expose its
18
+ * own remote interface at startup.
19
+ *
20
+ * If automatic page stitching is enabled, a loader is added to process the `next/dist/client/page-loader.js`
21
+ * file. If a custom library is specified in the options, an error is thrown. The options.library property is
22
+ * also set to `{ type: 'window', name: options.name }`.
23
+ */
24
+ export declare function applyClientPlugins(compiler: Compiler, options: ModuleFederationPluginOptions, extraOptions: NextFederationPluginExtraOptions): void;
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.applyClientPlugins = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const AddModulesToRuntime_1 = tslib_1.__importDefault(require("../AddModulesToRuntime"));
6
+ const internal_1 = require("../../internal");
7
+ const path_1 = tslib_1.__importDefault(require("path"));
8
+ const node_1 = require("@module-federation/node");
9
+ const InvertedContainerPlugin_1 = tslib_1.__importDefault(require("../container/InvertedContainerPlugin"));
10
+ /**
11
+ * Applies client-specific plugins.
12
+ *
13
+ * @param compiler - The Webpack compiler instance.
14
+ * @param options - The ModuleFederationPluginOptions instance.
15
+ * @param extraOptions - The NextFederationPluginExtraOptions instance.
16
+ *
17
+ * @remarks
18
+ * This function applies plugins to the Webpack compiler instance that are specific to the client build of
19
+ * a Next.js application with Module Federation enabled. These plugins include the following:
20
+ *
21
+ * - AddModulesPlugin: Adds modules to the webpack container runtime that can be streamed to other runtimes.
22
+ * - EntryPlugin: Creates an entry point for the application that delegates module loading to the container runtime.
23
+ * - ChunkCorrelationPlugin: Collects metadata on chunks to enable proper module loading across different runtimes.
24
+ * - InvertedContainerPlugin: Adds custom runtime modules to the container runtime to allow a host to expose its
25
+ * own remote interface at startup.
26
+ *
27
+ * If automatic page stitching is enabled, a loader is added to process the `next/dist/client/page-loader.js`
28
+ * file. If a custom library is specified in the options, an error is thrown. The options.library property is
29
+ * also set to `{ type: 'window', name: options.name }`.
30
+ */
31
+ function applyClientPlugins(compiler, options, extraOptions) {
32
+ const { webpack } = compiler;
33
+ const { remotes, name } = options;
34
+ //@ts-ignore
35
+ compiler.options.output.publicPath = 'auto';
36
+ // Add a new plugin to hoist modules into remote runtime
37
+ new AddModulesToRuntime_1.default({
38
+ debug: false,
39
+ runtime: 'webpack',
40
+ eager: true,
41
+ remotes,
42
+ // @ts-ignore
43
+ shared: internal_1.DEFAULT_SHARE_SCOPE_BROWSER,
44
+ container: name,
45
+ // @ts-ignore
46
+ applicationName: name,
47
+ }).apply(compiler);
48
+ // If automatic page stitching is enabled, add a new rule to the compiler's module rules
49
+ if (extraOptions.automaticPageStitching) {
50
+ compiler.options.module.rules.push({
51
+ test: /next[\\/]dist[\\/]client[\\/]page-loader\.js$/,
52
+ loader: path_1.default.resolve(__dirname, '../../loaders/patchNextClientPageLoader'),
53
+ });
54
+ }
55
+ // If a custom library is set, log an error message
56
+ if (options.library) {
57
+ console.error('[nextjs-mf] you cannot set custom library');
58
+ }
59
+ // Set the library option to be a window object with the name of the module federation plugin
60
+ options.library = {
61
+ type: 'window',
62
+ name,
63
+ };
64
+ // Add a new entry plugin to the compiler to delegate hoisting
65
+ new webpack.EntryPlugin(compiler.context, require.resolve('../../internal-delegate-hoist'), 'main').apply(compiler);
66
+ // Add a new chunk correlation plugin to the compiler
67
+ new node_1.ChunkCorrelationPlugin({
68
+ filename: 'static/chunks/federated-stats.json',
69
+ }).apply(compiler);
70
+ // Add a new commonjs chunk loading plugin to the compiler
71
+ new InvertedContainerPlugin_1.default({
72
+ runtime: 'webpack',
73
+ container: options.name,
74
+ remotes: options.remotes,
75
+ debug: false,
76
+ }).apply(compiler);
77
+ }
78
+ exports.applyClientPlugins = applyClientPlugins;
79
+ //# sourceMappingURL=apply-client-plugins.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apply-client-plugins.js","sourceRoot":"","sources":["../../../../../../packages/nextjs-mf/src/plugins/NextFederationP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,CACP,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAElB,qDAAqD;IACrD,IAAI,6BAAsB,CAAC;QACzB,QAAQ,EAAE,oCAAoC;KAC/C,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAEnB,0DAA0D;IAC1D,IAAI,iCAAuB,CAAC;QAC1B,OAAO,EAAE,SAAS;QAClB,SAAS,EAAE,OAAO,CAAC,IAAI;QACvB,OAAO,EAAE,OAAO,CAAC,OAAiC;QAClD,KAAK,EAAE,KAAK;KACb,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;AACrB,CAAC;AA/DD,gDA+DC"}
@@ -0,0 +1,61 @@
1
+ import { Compiler } from 'webpack';
2
+ import { ModuleFederationPluginOptions } from '@module-federation/utilities';
3
+ /**
4
+ * Applies server-specific plugins.
5
+ *
6
+ * @param compiler - The Webpack compiler instance.
7
+ * @param options - The ModuleFederationPluginOptions instance.
8
+ *
9
+ * @remarks
10
+ * The AddModulesPlugin lets us move modules between webpack chunks. In this case,
11
+ * we are moving modules into the runtime chunks of the host and removing eager shared
12
+ * modules from the remote container runtimes. This works around Next.js' lack of async
13
+ * boundary, allowing us to execute the code more efficiently and with better performance.
14
+ * By removing eager shared modules from the remote container runtimes, we can also improve
15
+ * the load time of the application by reducing the amount of unnecessary code that needs
16
+ * to be loaded.
17
+ */
18
+ export declare function applyServerPlugins(compiler: Compiler, options: ModuleFederationPluginOptions): void;
19
+ /**
20
+ * Configures server-specific library and filename options.
21
+ *
22
+ * @param options - The ModuleFederationPluginOptions instance.
23
+ *
24
+ * @remarks
25
+ * This function configures the library and filename options for server builds. The library option is
26
+ * set to the commonjs-module format for chunks and the container, which allows them to be streamed over
27
+ * to hosts with the NodeFederationPlugin. The filename option is set to the basename of the current
28
+ * filename.
29
+ */
30
+ export declare function configureServerLibraryAndFilename(options: ModuleFederationPluginOptions): void;
31
+ /**
32
+ * Patches Next.js' default externals function to make sure shared modules are bundled and not treated as external.
33
+ *
34
+ * @param compiler - The Webpack compiler instance.
35
+ * @param options - The ModuleFederationPluginOptions instance.
36
+ *
37
+ * @remarks
38
+ * In server builds, all node modules are treated as external, which prevents them from being shared
39
+ * via module federation. To work around this limitation, we mark shared modules as internalizable
40
+ * modules that webpack puts into chunks that can be streamed to other runtimes as needed.
41
+ *
42
+ * This function replaces Next.js' default externals function with a new asynchronous function that
43
+ * checks whether a module should be treated as external. If the module should not be treated as
44
+ * external, the function returns without calling the original externals function. Otherwise, the
45
+ * function calls the original externals function and retrieves the result. If the result is null,
46
+ * the function returns without further processing. If the module is from Next.js or React, the
47
+ * function returns the original result. Otherwise, the function returns null.
48
+ */
49
+ export declare function handleServerExternals(compiler: Compiler, options: ModuleFederationPluginOptions): void;
50
+ /**
51
+ * Configures server-specific compiler options.
52
+ *
53
+ * @param compiler - The Webpack compiler instance.
54
+ *
55
+ * @remarks
56
+ * This function configures the compiler options for server builds. It turns off the compiler target on node
57
+ * builds because it adds its own chunk loading runtime module with NodeFederationPlugin and StreamingTargetPlugin.
58
+ * It also disables split chunks to prevent conflicts from occurring in the graph.
59
+ *
60
+ */
61
+ export declare function configureServerCompilerOptions(compiler: Compiler): void;
@@ -0,0 +1,158 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.configureServerCompilerOptions = exports.handleServerExternals = exports.configureServerLibraryAndFilename = exports.applyServerPlugins = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const AddModulesToRuntime_1 = tslib_1.__importDefault(require("../AddModulesToRuntime"));
6
+ const path_1 = tslib_1.__importDefault(require("path"));
7
+ const InvertedContainerPlugin_1 = tslib_1.__importDefault(require("../container/InvertedContainerPlugin"));
8
+ /**
9
+ * Applies server-specific plugins.
10
+ *
11
+ * @param compiler - The Webpack compiler instance.
12
+ * @param options - The ModuleFederationPluginOptions instance.
13
+ *
14
+ * @remarks
15
+ * The AddModulesPlugin lets us move modules between webpack chunks. In this case,
16
+ * we are moving modules into the runtime chunks of the host and removing eager shared
17
+ * modules from the remote container runtimes. This works around Next.js' lack of async
18
+ * boundary, allowing us to execute the code more efficiently and with better performance.
19
+ * By removing eager shared modules from the remote container runtimes, we can also improve
20
+ * the load time of the application by reducing the amount of unnecessary code that needs
21
+ * to be loaded.
22
+ */
23
+ function applyServerPlugins(compiler, options) {
24
+ // Import the StreamingTargetPlugin from @module-federation/node
25
+ const { StreamingTargetPlugin } = require('@module-federation/node');
26
+ // Add the AddModulesPlugin for the webpack runtime with eager loading and remote configuration
27
+ new AddModulesToRuntime_1.default({
28
+ runtime: 'webpack-runtime',
29
+ eager: true,
30
+ remotes: options.remotes,
31
+ isServer: true,
32
+ container: options.name,
33
+ }).apply(compiler);
34
+ // Add the AddModulesPlugin for the server with lazy loading and remote configuration
35
+ // new AddModulesPlugin({
36
+ // runtime: options.name,
37
+ // eager: false,
38
+ // remotes: options.remotes
39
+ // }).apply(compiler);
40
+ // Add the StreamingTargetPlugin with the ModuleFederationPlugin from the webpack container
41
+ new StreamingTargetPlugin(options, {
42
+ ModuleFederationPlugin: compiler.webpack.container.ModuleFederationPlugin,
43
+ }).apply(compiler);
44
+ // Add a new commonjs chunk loading plugin to the compiler
45
+ new InvertedContainerPlugin_1.default({
46
+ runtime: 'webpack-runtime',
47
+ container: options.name,
48
+ remotes: options.remotes,
49
+ debug: true,
50
+ }).apply(compiler);
51
+ }
52
+ exports.applyServerPlugins = applyServerPlugins;
53
+ /**
54
+ * Configures server-specific library and filename options.
55
+ *
56
+ * @param options - The ModuleFederationPluginOptions instance.
57
+ *
58
+ * @remarks
59
+ * This function configures the library and filename options for server builds. The library option is
60
+ * set to the commonjs-module format for chunks and the container, which allows them to be streamed over
61
+ * to hosts with the NodeFederationPlugin. The filename option is set to the basename of the current
62
+ * filename.
63
+ */
64
+ function configureServerLibraryAndFilename(options) {
65
+ // Configure the library option with type "commonjs-module" and the name from the options
66
+ options.library = {
67
+ type: 'commonjs-module',
68
+ name: options.name,
69
+ };
70
+ // Set the filename option to the basename of the current filename
71
+ options.filename = path_1.default.basename(options.filename);
72
+ }
73
+ exports.configureServerLibraryAndFilename = configureServerLibraryAndFilename;
74
+ /**
75
+ * Patches Next.js' default externals function to make sure shared modules are bundled and not treated as external.
76
+ *
77
+ * @param compiler - The Webpack compiler instance.
78
+ * @param options - The ModuleFederationPluginOptions instance.
79
+ *
80
+ * @remarks
81
+ * In server builds, all node modules are treated as external, which prevents them from being shared
82
+ * via module federation. To work around this limitation, we mark shared modules as internalizable
83
+ * modules that webpack puts into chunks that can be streamed to other runtimes as needed.
84
+ *
85
+ * This function replaces Next.js' default externals function with a new asynchronous function that
86
+ * checks whether a module should be treated as external. If the module should not be treated as
87
+ * external, the function returns without calling the original externals function. Otherwise, the
88
+ * function calls the original externals function and retrieves the result. If the result is null,
89
+ * the function returns without further processing. If the module is from Next.js or React, the
90
+ * function returns the original result. Otherwise, the function returns null.
91
+ */
92
+ function handleServerExternals(compiler, options) {
93
+ // Check if the compiler has an `externals` array
94
+ if (Array.isArray(compiler.options.externals) &&
95
+ compiler.options.externals[0]) {
96
+ // Retrieve the original externals function
97
+ const originalExternals = compiler.options.externals[0];
98
+ // Replace the original externals function with a new asynchronous function
99
+ compiler.options.externals[0] = async function (ctx, callback) {
100
+ // Check if the module should not be treated as external
101
+ if (ctx.request &&
102
+ (ctx.request.includes('@module-federation/utilities') ||
103
+ ctx.request.includes('internal-delegate-hoist') ||
104
+ Object.keys(options.shared || {}).some((key) => {
105
+ return (
106
+ //@ts-ignore
107
+ options.shared?.[key]?.import !== false &&
108
+ ctx?.request?.includes(key));
109
+ }) ||
110
+ ctx.request.includes('@module-federation/dashboard-plugin'))) {
111
+ // If the module should not be treated as external, return without calling the original externals function
112
+ return;
113
+ }
114
+ // Call the original externals function and retrieve the result
115
+ // @ts-ignore
116
+ const fromNext = await originalExternals(ctx, callback);
117
+ // If the result is null, return without further processing
118
+ if (!fromNext) {
119
+ return;
120
+ }
121
+ // If the module is from Next.js or React, return the original result
122
+ const req = fromNext.split(' ')[1];
123
+ if (req.startsWith('next') || req.startsWith('react')) {
124
+ return fromNext;
125
+ }
126
+ // Otherwise, return null
127
+ return;
128
+ };
129
+ }
130
+ }
131
+ exports.handleServerExternals = handleServerExternals;
132
+ /**
133
+ * Configures server-specific compiler options.
134
+ *
135
+ * @param compiler - The Webpack compiler instance.
136
+ *
137
+ * @remarks
138
+ * This function configures the compiler options for server builds. It turns off the compiler target on node
139
+ * builds because it adds its own chunk loading runtime module with NodeFederationPlugin and StreamingTargetPlugin.
140
+ * It also disables split chunks to prevent conflicts from occurring in the graph.
141
+ *
142
+ */
143
+ function configureServerCompilerOptions(compiler) {
144
+ // Turn off the compiler target on node builds because we add our own chunk loading runtime module
145
+ // with NodeFederationPlugin and StreamingTargetPlugin
146
+ compiler.options.target = false;
147
+ compiler.options.node = {
148
+ ...compiler.options.node,
149
+ global: false,
150
+ };
151
+ // Set chunkIds optimization to 'named'
152
+ compiler.options.optimization.chunkIds = 'named'; // for debugging
153
+ // Disable split chunks to prevent conflicts from occurring in the graph
154
+ // TODO on the `compiler.options.optimization.splitChunks` line would be to find a way to only opt out chunks/modules related to module federation from chunk splitting logic.
155
+ compiler.options.optimization.splitChunks = false;
156
+ }
157
+ exports.configureServerCompilerOptions = configureServerCompilerOptions;
158
+ //# sourceMappingURL=apply-server-plugins.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apply-server-plugins.js","sourceRoot":"","sources":["../../../../../../packages/nextjs-mf/src/plugins/NextFederationPlugin/apply-server-plugins.ts"],"names":[],"mappings":";;;;AAEA,yFAAsD;AACtD,wDAAwB;AACxB,2GAA2E;AAE3E;;;;;;;;;;;;;;GAcG;AACH,SAAgB,kBAAkB,CAChC,QAAkB,EAClB,OAAsC;IAEtC,gEAAgE;IAChE,MAAM,EAAE,qBAAqB,EAAE,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAAC;IAErE,+FAA+F;IAC/F,IAAI,6BAAgB,CAAC;QACnB,OAAO,EAAE,iBAAiB;QAC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;;;GAUG;AACH,SAAgB,8BAA8B,CAAC,QAAkB;IAC/D,kGAAkG;IAClG,sDAAsD;IACtD,QAAQ,CAAC,OAAO,CAAC,MAAM,GAAG,KAAK,CAAC;IAChC,QAAQ,CAAC,OAAO,CAAC,IAAI,GAAG;QACtB,GAAG,QAAQ,CAAC,OAAO,CAAC,IAAI;QACxB,MAAM,EAAE,KAAK;KACd,CAAC;IACF,uCAAuC;IACvC,QAAQ,CAAC,OAAO,CAAC,YAAY,CAAC,QAAQ,GAAG,OAAO,CAAC,CAAC,gBAAgB;IAElE,wEAAwE;IACxE,8KAA8K;IAC9K,QAAQ,CAAC,OAAO,CAAC,YAAY,CAAC,WAAW,GAAG,KAAK,CAAC;AACpD,CAAC;AAdD,wEAcC"}
@@ -0,0 +1,18 @@
1
+ import type { ModuleFederationPluginOptions, NextFederationPluginExtraOptions, NextFederationPluginOptions } from '@module-federation/utilities';
2
+ import type { Compiler } from 'webpack';
3
+ /**
4
+ * NextFederationPlugin is a webpack plugin that handles Next.js application
5
+ * federation using Module Federation.
6
+ */
7
+ export declare class NextFederationPlugin {
8
+ _options: ModuleFederationPluginOptions;
9
+ _extraOptions: NextFederationPluginExtraOptions;
10
+ /**
11
+ * Constructs the NextFederationPlugin with the provided options.
12
+ *
13
+ * @param options The options to configure the plugin.
14
+ */
15
+ constructor(options: NextFederationPluginOptions);
16
+ apply(compiler: Compiler): void;
17
+ }
18
+ export default NextFederationPlugin;
@@ -0,0 +1,133 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Zackary Jackson @ScriptedAlchemy
4
+ */
5
+ 'use strict';
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.NextFederationPlugin = void 0;
8
+ const tslib_1 = require("tslib");
9
+ const utilities_1 = require("@module-federation/utilities");
10
+ const CopyFederationPlugin_1 = tslib_1.__importDefault(require("../CopyFederationPlugin"));
11
+ const next_fragments_1 = require("./next-fragments");
12
+ const internal_1 = require("../../internal");
13
+ const AddRuntimeRequirementToPromiseExternalPlugin_1 = tslib_1.__importDefault(require("../AddRuntimeRequirementToPromiseExternalPlugin"));
14
+ const nextPageMapLoader_1 = require("../../loaders/nextPageMapLoader");
15
+ const remove_unnecessary_shared_keys_1 = require("./remove-unnecessary-shared-keys");
16
+ const set_options_1 = require("./set-options");
17
+ const validate_options_1 = require("./validate-options");
18
+ const apply_automatic_async_boundary_1 = require("./apply-automatic-async-boundary");
19
+ const apply_server_plugins_1 = require("./apply-server-plugins");
20
+ const apply_client_plugins_1 = require("./apply-client-plugins");
21
+ /**
22
+ * NextFederationPlugin is a webpack plugin that handles Next.js application
23
+ * federation using Module Federation.
24
+ */
25
+ class NextFederationPlugin {
26
+ /**
27
+ * Constructs the NextFederationPlugin with the provided options.
28
+ *
29
+ * @param options The options to configure the plugin.
30
+ */
31
+ constructor(options) {
32
+ const { mainOptions, extraOptions } = (0, set_options_1.setOptions)(options);
33
+ this._options = mainOptions;
34
+ this._extraOptions = extraOptions;
35
+ }
36
+ apply(compiler) {
37
+ // Validate the compiler options
38
+ const validCompile = (0, validate_options_1.validateCompilerOptions)(compiler);
39
+ if (!validCompile)
40
+ return;
41
+ // Validate the NextFederationPlugin options
42
+ (0, validate_options_1.validatePluginOptions)(this._options);
43
+ // Check if the compiler is for the server or client
44
+ const isServer = compiler.options.name === 'server';
45
+ const { webpack } = compiler;
46
+ // Apply the CopyFederationPlugin
47
+ new CopyFederationPlugin_1.default(isServer).apply(compiler);
48
+ // If remotes are provided, parse them
49
+ if (this._options.remotes) {
50
+ this._options.remotes = (0, internal_1.parseRemotes)(this._options.remotes);
51
+ }
52
+ // If shared modules are provided, remove unnecessary shared keys from the default share scope
53
+ if (this._options.shared) {
54
+ (0, remove_unnecessary_shared_keys_1.removeUnnecessarySharedKeys)(this._options.shared);
55
+ }
56
+ const ModuleFederationPlugin = (0, next_fragments_1.getModuleFederationPluginConstructor)(isServer, compiler);
57
+ const defaultShared = (0, next_fragments_1.retrieveDefaultShared)(isServer);
58
+ console.log(compiler.options.name);
59
+ if (isServer) {
60
+ // Refactored server condition
61
+ (0, apply_server_plugins_1.configureServerCompilerOptions)(compiler);
62
+ (0, apply_server_plugins_1.configureServerLibraryAndFilename)(this._options);
63
+ (0, apply_server_plugins_1.applyServerPlugins)(compiler, this._options);
64
+ (0, apply_server_plugins_1.handleServerExternals)(compiler, {
65
+ ...this._options,
66
+ shared: { ...defaultShared, ...this._options.shared },
67
+ });
68
+ }
69
+ else {
70
+ (0, apply_client_plugins_1.applyClientPlugins)(compiler, this._options, this._extraOptions);
71
+ }
72
+ // @ts-ignore
73
+ const hostFederationPluginOptions = {
74
+ ...this._options,
75
+ runtime: false,
76
+ exposes: {
77
+ // __hoist: require.resolve('../../delegate-hoist-container'),
78
+ ...(this._extraOptions.exposePages
79
+ ? (0, nextPageMapLoader_1.exposeNextjsPages)(compiler.options.context)
80
+ : {}),
81
+ ...this._options.exposes,
82
+ },
83
+ remotes: {
84
+ //@ts-ignore
85
+ ...this._options.remotes,
86
+ },
87
+ shared: {
88
+ ...defaultShared,
89
+ ...this._options.shared,
90
+ },
91
+ };
92
+ compiler.options.devtool = 'source-map';
93
+ compiler.options.output.uniqueName = this._options.name;
94
+ // inject module hoisting system
95
+ (0, next_fragments_1.applyRemoteDelegates)(this._options, compiler);
96
+ if (this._extraOptions.automaticAsyncBoundary) {
97
+ (0, apply_automatic_async_boundary_1.applyAutomaticAsyncBoundary)(this._options, this._extraOptions, compiler);
98
+ }
99
+ (0, next_fragments_1.injectModuleHoistingSystem)(isServer, this._options, compiler);
100
+ //todo runtime variable creation needs to be applied for server as well. this is just for client
101
+ // TODO: this needs to be refactored into something more comprehensive. this is just a quick fix
102
+ new webpack.DefinePlugin({
103
+ 'process.env.REMOTES': (0, utilities_1.createRuntimeVariables)(this._options.remotes),
104
+ 'process.env.CURRENT_HOST': JSON.stringify(this._options.name),
105
+ }).apply(compiler);
106
+ // @ts-ignore
107
+ new ModuleFederationPlugin(hostFederationPluginOptions).apply(compiler);
108
+ if (!isServer &&
109
+ this._options.remotes &&
110
+ Object.keys(this._options.remotes).length > 0) {
111
+ // single runtime chunk if host or circular remote uses remote of current host.
112
+ // @ts-ignore
113
+ new ModuleFederationPlugin({
114
+ ...hostFederationPluginOptions,
115
+ filename: undefined,
116
+ runtime: undefined,
117
+ name: this._options.name + '_single',
118
+ library: {
119
+ ...hostFederationPluginOptions.library,
120
+ name: this._options.name + '_single',
121
+ },
122
+ shared: {
123
+ ...hostFederationPluginOptions.shared,
124
+ ...defaultShared,
125
+ },
126
+ }).apply(compiler);
127
+ }
128
+ new AddRuntimeRequirementToPromiseExternalPlugin_1.default().apply(compiler);
129
+ }
130
+ }
131
+ exports.NextFederationPlugin = NextFederationPlugin;
132
+ exports.default = NextFederationPlugin;
133
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/nextjs-mf/src/plugins/NextFederationPlugin/index.ts"],"names":[],"mappings":"AAAA;;;EAGE;AACF,YAAY,CAAC;;;;AAQb,4DAAsE;AAEtE,2FAA2D;AAC3D,qDAK0B;AAE1B,6CAA8C;AAC9C,2IAAqG;AACrG,uEAAoE;AACpE,qFAA+E;AAC/E,+CAA2C;AAC3C,yDAG4B;AAC5B,qFAA+E;AAC/E,iEAKgC;AAChC,iEAA4D;AAE5D;;;GAGG;AACH,MAAa,oBAAoB;IAI/B;;;;OAIG;IACH,YAAY,OAAoC;QAC9C,MAAM,EAAE,WAAW,EAAE,YAAY,EAAE,GAAG,IAAA,wBAAU,EAAC,OAAO,CAAC,CAAC;QAC1D,IAAI,CAAC,QAAQ,GAAG,WAAW,CAAC;QAC5B,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;IACpC,CAAC;IAED,KAAK,CAAC,QAAkB;QACtB,gCAAgC;QAChC,MAAM,YAAY,GAAG,IAAA,0CAAuB,EAAC,QAAQ,CAAC,CAAC;QACvD,IAAI,CAAC,YAAY;YAAE,O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CAAC,OAAO,CAAC;YACpE,0BAA0B,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;SAC/D,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QAEnB,aAAa;QACb,IAAI,sBAAsB,CAAC,2BAA2B,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QAExE,IACE,CAAC,QAAQ;YACT,IAAI,CAAC,QAAQ,CAAC,OAAO;YACrB,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,MAAM,GAAG,CAAC,EAC7C;YACA,+EAA+E;YAC/E,aAAa;YACb,IAAI,sBAAsB,CAAC;gBACzB,GAAG,2BAA2B;gBAC9B,QAAQ,EAAE,SAAS;gBACnB,OAAO,EAAE,SAAS;gBAClB,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,GAAG,SAAS;gBACpC,OAAO,EAAE;oBACP,GAAG,2BAA2B,CAAC,OAAO;oBACtC,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,GAAG,SAAS;iBACrC;gBACD,MAAM,EAAE;oBACN,GAAG,2BAA2B,CAAC,MAAM;oBACrC,GAAG,aAAa;iBACjB;aACF,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;SACpB;QAED,IAAI,sDAAsC,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC/D,CAAC;CACF;AAhID,oDAgIC;AAED,kBAAe,oBAAoB,CAAC"}
@@ -0,0 +1,44 @@
1
+ import type { Compiler } from 'webpack';
2
+ import { container } from 'webpack';
3
+ import type { ModuleFederationPluginOptions, SharedObject } from '@module-federation/utilities';
4
+ type ConstructableModuleFederationPlugin = new (options: ModuleFederationPluginOptions) => container.ModuleFederationPlugin;
5
+ /**
6
+ * Gets the appropriate ModuleFederationPlugin based on the environment.
7
+ * @param {boolean} isServer - A flag to indicate if the environment is server-side or not.
8
+ * @param {Compiler} compiler - The Webpack compiler instance.
9
+ * @returns {ModuleFederationPlugin | undefined} The ModuleFederationPlugin or undefined if not applicable.
10
+ */
11
+ export declare function getModuleFederationPluginConstructor(isServer: boolean, compiler: Compiler): ConstructableModuleFederationPlugin;
12
+ /**
13
+
14
+ Set up default shared values based on the environment.
15
+ @param isServer - Boolean indicating if the code is running on the server.
16
+ @returns The default share scope based on the environment.
17
+ */
18
+ export declare const retrieveDefaultShared: (isServer: boolean) => SharedObject;
19
+ /**
20
+
21
+ Inject module hoisting system.
22
+ This function injects the module hoisting system into the webpack build process. The module hoisting system is a way to
23
+ optimize the build process by hoisting dependencies into specific files that are hoisted into the webpack runtimes. This
24
+ function is used by the NextFederationPlugin to optimize the build process when using module federation with Next.js.
25
+ @param {boolean} isServer - A boolean indicating whether the code is running on the server.
26
+ @param {ModuleFederationPluginOptions} options - The options for the ModuleFederationPlugin.
27
+ @param {Compiler} compiler - The webpack compiler instance.
28
+ */
29
+ export declare function injectModuleHoistingSystem(isServer: boolean, options: ModuleFederationPluginOptions, compiler: Compiler): void;
30
+ /**
31
+
32
+ Apply remote delegates.
33
+
34
+ This function adds the remote delegates feature by configuring and injecting the appropriate loader that will look
35
+ for internal delegate hoist or delegate hoist container and load it using a custom delegateLoader.
36
+ Once loaded, it will then look for the available delegates that will be used to configure the remote
37
+ that the hoisted module will be dependent upon.
38
+
39
+ @param {ModuleFederationPluginOptions} options - The ModuleFederationPluginOptions instance.
40
+
41
+ @param {Compiler} compiler - The Webpack compiler instance.
42
+ */
43
+ export declare function applyRemoteDelegates(options: ModuleFederationPluginOptions, compiler: Compiler): void;
44
+ export {};