@module-federation/nextjs-mf 0.0.0-chore-bump-node-22-20260710161714

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 (110) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +5 -0
  3. package/dist/LICENSE +21 -0
  4. package/dist/_virtual/_rolldown/runtime.js +29 -0
  5. package/dist/_virtual/_rolldown/runtime.mjs +8 -0
  6. package/dist/client/UrlNode.js +92 -0
  7. package/dist/client/UrlNode.js.map +1 -0
  8. package/dist/client/UrlNode.mjs +91 -0
  9. package/dist/client/UrlNode.mjs.map +1 -0
  10. package/dist/src/federation-noop.d.mts +1 -0
  11. package/dist/src/federation-noop.d.ts +1 -0
  12. package/dist/src/federation-noop.js +17 -0
  13. package/dist/src/federation-noop.js.map +1 -0
  14. package/dist/src/federation-noop.mjs +23 -0
  15. package/dist/src/federation-noop.mjs.map +1 -0
  16. package/dist/src/index.d.mts +2 -0
  17. package/dist/src/index.d.ts +2 -0
  18. package/dist/src/index.js +14 -0
  19. package/dist/src/index.js.map +1 -0
  20. package/dist/src/index.mjs +8 -0
  21. package/dist/src/index.mjs.map +1 -0
  22. package/dist/src/internal.js +152 -0
  23. package/dist/src/internal.js.map +1 -0
  24. package/dist/src/internal.mjs +152 -0
  25. package/dist/src/internal.mjs.map +1 -0
  26. package/dist/src/loaders/fixImageLoader.d.mts +27 -0
  27. package/dist/src/loaders/fixImageLoader.d.ts +27 -0
  28. package/dist/src/loaders/fixImageLoader.js +104 -0
  29. package/dist/src/loaders/fixImageLoader.js.map +1 -0
  30. package/dist/src/loaders/fixImageLoader.mjs +101 -0
  31. package/dist/src/loaders/fixImageLoader.mjs.map +1 -0
  32. package/dist/src/loaders/fixUrlLoader.d.mts +16 -0
  33. package/dist/src/loaders/fixUrlLoader.d.ts +16 -0
  34. package/dist/src/loaders/fixUrlLoader.js +22 -0
  35. package/dist/src/loaders/fixUrlLoader.js.map +1 -0
  36. package/dist/src/loaders/fixUrlLoader.mjs +19 -0
  37. package/dist/src/loaders/fixUrlLoader.mjs.map +1 -0
  38. package/dist/src/loaders/helpers.js +82 -0
  39. package/dist/src/loaders/helpers.js.map +1 -0
  40. package/dist/src/loaders/helpers.mjs +79 -0
  41. package/dist/src/loaders/helpers.mjs.map +1 -0
  42. package/dist/src/loaders/nextPageMapLoader.d.mts +29 -0
  43. package/dist/src/loaders/nextPageMapLoader.d.ts +29 -0
  44. package/dist/src/loaders/nextPageMapLoader.js +148 -0
  45. package/dist/src/loaders/nextPageMapLoader.js.map +1 -0
  46. package/dist/src/loaders/nextPageMapLoader.mjs +143 -0
  47. package/dist/src/loaders/nextPageMapLoader.mjs.map +1 -0
  48. package/dist/src/logger.js +9 -0
  49. package/dist/src/logger.js.map +1 -0
  50. package/dist/src/logger.mjs +8 -0
  51. package/dist/src/logger.mjs.map +1 -0
  52. package/dist/src/plugins/CopyFederationPlugin.js +67 -0
  53. package/dist/src/plugins/CopyFederationPlugin.js.map +1 -0
  54. package/dist/src/plugins/CopyFederationPlugin.mjs +65 -0
  55. package/dist/src/plugins/CopyFederationPlugin.mjs.map +1 -0
  56. package/dist/src/plugins/NextFederationPlugin/apply-client-plugins.js +41 -0
  57. package/dist/src/plugins/NextFederationPlugin/apply-client-plugins.js.map +1 -0
  58. package/dist/src/plugins/NextFederationPlugin/apply-client-plugins.mjs +40 -0
  59. package/dist/src/plugins/NextFederationPlugin/apply-client-plugins.mjs.map +1 -0
  60. package/dist/src/plugins/NextFederationPlugin/apply-server-plugins.js +117 -0
  61. package/dist/src/plugins/NextFederationPlugin/apply-server-plugins.js.map +1 -0
  62. package/dist/src/plugins/NextFederationPlugin/apply-server-plugins.mjs +111 -0
  63. package/dist/src/plugins/NextFederationPlugin/apply-server-plugins.mjs.map +1 -0
  64. package/dist/src/plugins/NextFederationPlugin/index.d.mts +31 -0
  65. package/dist/src/plugins/NextFederationPlugin/index.d.ts +31 -0
  66. package/dist/src/plugins/NextFederationPlugin/index.js +156 -0
  67. package/dist/src/plugins/NextFederationPlugin/index.js.map +1 -0
  68. package/dist/src/plugins/NextFederationPlugin/index.mjs +153 -0
  69. package/dist/src/plugins/NextFederationPlugin/index.mjs.map +1 -0
  70. package/dist/src/plugins/NextFederationPlugin/next-fragments.d.mts +18 -0
  71. package/dist/src/plugins/NextFederationPlugin/next-fragments.d.ts +18 -0
  72. package/dist/src/plugins/NextFederationPlugin/next-fragments.js +65 -0
  73. package/dist/src/plugins/NextFederationPlugin/next-fragments.js.map +1 -0
  74. package/dist/src/plugins/NextFederationPlugin/next-fragments.mjs +63 -0
  75. package/dist/src/plugins/NextFederationPlugin/next-fragments.mjs.map +1 -0
  76. package/dist/src/plugins/NextFederationPlugin/set-options.js +20 -0
  77. package/dist/src/plugins/NextFederationPlugin/set-options.js.map +1 -0
  78. package/dist/src/plugins/NextFederationPlugin/set-options.mjs +19 -0
  79. package/dist/src/plugins/NextFederationPlugin/set-options.mjs.map +1 -0
  80. package/dist/src/plugins/NextFederationPlugin/validate-options.js +37 -0
  81. package/dist/src/plugins/NextFederationPlugin/validate-options.js.map +1 -0
  82. package/dist/src/plugins/NextFederationPlugin/validate-options.mjs +35 -0
  83. package/dist/src/plugins/NextFederationPlugin/validate-options.mjs.map +1 -0
  84. package/dist/src/plugins/container/InvertedContainerPlugin.js +26 -0
  85. package/dist/src/plugins/container/InvertedContainerPlugin.js.map +1 -0
  86. package/dist/src/plugins/container/InvertedContainerPlugin.mjs +27 -0
  87. package/dist/src/plugins/container/InvertedContainerPlugin.mjs.map +1 -0
  88. package/dist/src/plugins/container/InvertedContainerRuntimeModule.js +57 -0
  89. package/dist/src/plugins/container/InvertedContainerRuntimeModule.js.map +1 -0
  90. package/dist/src/plugins/container/InvertedContainerRuntimeModule.mjs +57 -0
  91. package/dist/src/plugins/container/InvertedContainerRuntimeModule.mjs.map +1 -0
  92. package/dist/src/plugins/container/runtimePlugin.d.mts +7 -0
  93. package/dist/src/plugins/container/runtimePlugin.d.ts +6 -0
  94. package/dist/src/plugins/container/runtimePlugin.js +168 -0
  95. package/dist/src/plugins/container/runtimePlugin.js.map +1 -0
  96. package/dist/src/plugins/container/runtimePlugin.mjs +167 -0
  97. package/dist/src/plugins/container/runtimePlugin.mjs.map +1 -0
  98. package/dist/utils/flushedChunks.d.mts +29 -0
  99. package/dist/utils/flushedChunks.d.ts +29 -0
  100. package/dist/utils/flushedChunks.js +37 -0
  101. package/dist/utils/flushedChunks.js.map +1 -0
  102. package/dist/utils/flushedChunks.mjs +35 -0
  103. package/dist/utils/flushedChunks.mjs.map +1 -0
  104. package/dist/utils/index.d.mts +14 -0
  105. package/dist/utils/index.d.ts +14 -0
  106. package/dist/utils/index.js +31 -0
  107. package/dist/utils/index.js.map +1 -0
  108. package/dist/utils/index.mjs +22 -0
  109. package/dist/utils/index.mjs.map +1 -0
  110. package/package.json +106 -0
@@ -0,0 +1,156 @@
1
+ 'use strict';
2
+
3
+ const require_runtime = require('../../../_virtual/_rolldown/runtime.js');
4
+ const require_logger = require('../../logger.js');
5
+ const require_CopyFederationPlugin = require('../CopyFederationPlugin.js');
6
+ const require_src_loaders_nextPageMapLoader = require('../../loaders/nextPageMapLoader.js');
7
+ const require_next_fragments = require('./next-fragments.js');
8
+ const require_set_options = require('./set-options.js');
9
+ const require_validate_options = require('./validate-options.js');
10
+ const require_apply_server_plugins = require('./apply-server-plugins.js');
11
+ const require_apply_client_plugins = require('./apply-client-plugins.js');
12
+ let path = require("path");
13
+ path = require_runtime.__toESM(path);
14
+ let _module_federation_sdk_normalize_webpack_path = require("@module-federation/sdk/normalize-webpack-path");
15
+ let _module_federation_sdk = require("@module-federation/sdk");
16
+ let _module_federation_enhanced_webpack = require("@module-federation/enhanced/webpack");
17
+
18
+ //#region src/plugins/NextFederationPlugin/index.ts
19
+ /**
20
+ * MIT License http://www.opensource.org/licenses/mit-license.php
21
+ * Author Zackary Jackson @ScriptedAlchemy
22
+ * This module contains the NextFederationPlugin class which is a webpack plugin that handles Next.js application federation using Module Federation.
23
+ */
24
+ const resolveRuntimePluginPath = () => require.resolve("@module-federation/nextjs-mf/dist/src/plugins/container/runtimePlugin.js");
25
+ const resolveNoopPath = () => require.resolve("@module-federation/nextjs-mf/dist/src/federation-noop.js");
26
+ const resolveNodeRuntimePluginPath = () => {
27
+ const nodePackageRoot = path.default.dirname(require.resolve("@module-federation/node/package.json"));
28
+ return require.resolve(path.default.join(nodePackageRoot, "dist/src/runtimePlugin.js"));
29
+ };
30
+ /**
31
+ * NextFederationPlugin is a webpack plugin that handles Next.js application federation using Module Federation.
32
+ */
33
+ var NextFederationPlugin = class {
34
+ /**
35
+ * Constructs the NextFederationPlugin with the provided options.
36
+ *
37
+ * @param options The options to configure the plugin.
38
+ */
39
+ constructor(options) {
40
+ const { mainOptions, extraOptions } = require_set_options.setOptions(options);
41
+ this._options = mainOptions;
42
+ this._extraOptions = extraOptions;
43
+ this.name = "ModuleFederationPlugin";
44
+ }
45
+ /**
46
+ * The apply method is called by the webpack compiler and allows the plugin to hook into the webpack process.
47
+ * @param compiler The webpack compiler object.
48
+ */
49
+ apply(compiler) {
50
+ (0, _module_federation_sdk.bindLoggerToCompiler)(require_logger.default, compiler, "NextFederationPlugin");
51
+ process.env["FEDERATION_WEBPACK_PATH"] = process.env["FEDERATION_WEBPACK_PATH"] || (0, _module_federation_sdk_normalize_webpack_path.getWebpackPath)(compiler, { framework: "nextjs" });
52
+ if (!this.validateOptions(compiler)) return;
53
+ const isServer = this.isServerCompiler(compiler);
54
+ new require_CopyFederationPlugin.default(isServer).apply(compiler);
55
+ const normalFederationPluginOptions = this.getNormalFederationPluginOptions(compiler, isServer);
56
+ this._options = normalFederationPluginOptions;
57
+ this.applyConditionalPlugins(compiler, isServer);
58
+ new _module_federation_enhanced_webpack.ModuleFederationPlugin(normalFederationPluginOptions).apply(compiler);
59
+ const noop = this.getNoopPath();
60
+ if (!this._extraOptions.skipSharingNextInternals) compiler.hooks.make.tapAsync("NextFederationPlugin", (compilation, callback) => {
61
+ const dep = compiler.webpack.EntryPlugin.createDependency(noop, "noop");
62
+ compilation.addEntry(compiler.context, dep, { name: "noop" }, (err, module) => {
63
+ if (err) return callback(err);
64
+ callback();
65
+ });
66
+ });
67
+ if (!compiler.options.ignoreWarnings) compiler.options.ignoreWarnings = [(message) => /your target environment does not appear/.test(message)];
68
+ }
69
+ validateOptions(compiler) {
70
+ const manifestPlugin = compiler.options.plugins.find((p) => p?.constructor?.name === "BuildManifestPlugin");
71
+ if (manifestPlugin) {
72
+ if (manifestPlugin?.appDirEnabled) throw new Error("App Directory is not supported by nextjs-mf. Use only pages directory, do not open git issues about this");
73
+ }
74
+ const compilerValid = require_validate_options.validateCompilerOptions(compiler);
75
+ const pluginValid = require_validate_options.validatePluginOptions(this._options);
76
+ const envValid = process.env["NEXT_PRIVATE_LOCAL_WEBPACK"];
77
+ if (compilerValid === void 0) require_logger.default.error("Compiler validation failed");
78
+ if (pluginValid === void 0) require_logger.default.error("Plugin validation failed");
79
+ const validCompilerTarget = compiler.options.name === "server" || compiler.options.name === "client";
80
+ if (!envValid) throw new Error("process.env.NEXT_PRIVATE_LOCAL_WEBPACK is not set to true, please set it to true, and \"npm install webpack\"");
81
+ return compilerValid !== void 0 && pluginValid !== void 0 && validCompilerTarget;
82
+ }
83
+ isServerCompiler(compiler) {
84
+ return compiler.options.name === "server";
85
+ }
86
+ applyConditionalPlugins(compiler, isServer) {
87
+ compiler.options.output.uniqueName = this._options.name;
88
+ compiler.options.output.environment = {
89
+ ...compiler.options.output.environment,
90
+ asyncFunction: true
91
+ };
92
+ if (!compiler.options.module.rules) compiler.options.module.rules = [];
93
+ compiler.options.module.rules.push({
94
+ resourceQuery: /\?rsc/,
95
+ layer: "rsc"
96
+ });
97
+ compiler.options.module.rules.push({
98
+ resourceQuery: /\?client/,
99
+ layer: "client"
100
+ });
101
+ compiler.options.module.rules.push({
102
+ resourceQuery: /\?ssr/,
103
+ layer: "ssr"
104
+ });
105
+ require_next_fragments.applyPathFixes(compiler, this._options, this._extraOptions);
106
+ if (this._extraOptions.debug) compiler.options.devtool = false;
107
+ if (isServer) {
108
+ require_apply_server_plugins.configureServerCompilerOptions(compiler);
109
+ require_apply_server_plugins.configureServerLibraryAndFilename(this._options);
110
+ require_apply_server_plugins.applyServerPlugins(compiler, this._options);
111
+ require_apply_server_plugins.handleServerExternals(compiler, {
112
+ ...this._options,
113
+ shared: {
114
+ ...require_next_fragments.retrieveDefaultShared(isServer),
115
+ ...this._options.shared
116
+ }
117
+ });
118
+ } else require_apply_client_plugins.applyClientPlugins(compiler, this._options, this._extraOptions);
119
+ }
120
+ getNormalFederationPluginOptions(compiler, isServer) {
121
+ const defaultShared = this._extraOptions.skipSharingNextInternals ? {} : require_next_fragments.retrieveDefaultShared(isServer);
122
+ return {
123
+ ...this._options,
124
+ runtime: false,
125
+ remoteType: "script",
126
+ runtimePlugins: [
127
+ ...isServer ? [resolveNodeRuntimePluginPath()] : [],
128
+ resolveRuntimePluginPath(),
129
+ ...this._options.runtimePlugins || []
130
+ ].map((plugin) => plugin + "?runtimePlugin"),
131
+ exposes: {
132
+ ...this._options.exposes,
133
+ ...this._extraOptions.exposePages ? require_src_loaders_nextPageMapLoader.exposeNextjsPages(compiler.options.context) : {}
134
+ },
135
+ remotes: { ...this._options.remotes },
136
+ shared: {
137
+ ...defaultShared,
138
+ ...this._options.shared
139
+ },
140
+ manifest: {
141
+ ...this._options.manifest ?? {},
142
+ filePath: isServer ? "" : "/static/chunks"
143
+ },
144
+ dts: this._options.dts ?? false,
145
+ shareStrategy: this._options.shareStrategy ?? "loaded-first",
146
+ experiments: { asyncStartup: true }
147
+ };
148
+ }
149
+ getNoopPath() {
150
+ return resolveNoopPath();
151
+ }
152
+ };
153
+
154
+ //#endregion
155
+ exports.default = NextFederationPlugin;
156
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["setOptions","logger","CopyFederationPlugin","ModuleFederationPlugin","validateCompilerOptions","validatePluginOptions","retrieveDefaultShared","exposeNextjsPages"],"sources":["../../../../src/plugins/NextFederationPlugin/index.ts"],"sourcesContent":["/**\n * MIT License http://www.opensource.org/licenses/mit-license.php\n * Author Zackary Jackson @ScriptedAlchemy\n * This module contains the NextFederationPlugin class which is a webpack plugin that handles Next.js application federation using Module Federation.\n */\n'use strict';\n\nimport type {\n NextFederationPluginExtraOptions,\n NextFederationPluginOptions,\n} from './next-fragments';\nimport type { Compiler, WebpackPluginInstance } from 'webpack';\nimport path from 'path';\nimport { getWebpackPath } from '@module-federation/sdk/normalize-webpack-path';\nimport CopyFederationPlugin from '../CopyFederationPlugin';\nimport { exposeNextjsPages } from '../../loaders/nextPageMapLoader';\nimport { retrieveDefaultShared, applyPathFixes } from './next-fragments';\nimport { setOptions } from './set-options';\nimport {\n validateCompilerOptions,\n validatePluginOptions,\n} from './validate-options';\nimport {\n applyServerPlugins,\n configureServerCompilerOptions,\n configureServerLibraryAndFilename,\n handleServerExternals,\n} from './apply-server-plugins';\nimport { applyClientPlugins } from './apply-client-plugins';\nimport { ModuleFederationPlugin } from '@module-federation/enhanced/webpack';\nimport { bindLoggerToCompiler } from '@module-federation/sdk';\nimport type { moduleFederationPlugin } from '@module-federation/sdk';\nimport logger from '../../logger';\n\nconst resolveRuntimePluginPath = (): string =>\n process.env.IS_ESM_BUILD === 'true'\n ? require.resolve('@module-federation/nextjs-mf/dist/src/plugins/container/runtimePlugin.mjs')\n : require.resolve('@module-federation/nextjs-mf/dist/src/plugins/container/runtimePlugin.js');\n\nconst resolveNoopPath = (): string =>\n process.env.IS_ESM_BUILD === 'true'\n ? require.resolve('@module-federation/nextjs-mf/dist/src/federation-noop.mjs')\n : require.resolve('@module-federation/nextjs-mf/dist/src/federation-noop.js');\n\nconst resolveNodeRuntimePluginPath = (): string => {\n const nodePackageRoot = path.dirname(\n require.resolve('@module-federation/node/package.json'),\n );\n\n return require.resolve(\n path.join(\n nodePackageRoot,\n process.env.IS_ESM_BUILD === 'true'\n ? 'dist/src/runtimePlugin.mjs'\n : 'dist/src/runtimePlugin.js',\n ),\n );\n};\n/**\n * NextFederationPlugin is a webpack plugin that handles Next.js application federation using Module Federation.\n */\nexport class NextFederationPlugin {\n private _options: moduleFederationPlugin.ModuleFederationPluginOptions;\n private _extraOptions: NextFederationPluginExtraOptions;\n public name: string;\n /**\n * Constructs the NextFederationPlugin with the provided options.\n *\n * @param options The options to configure the plugin.\n */\n constructor(options: NextFederationPluginOptions) {\n const { mainOptions, extraOptions } = setOptions(options);\n this._options = mainOptions;\n this._extraOptions = extraOptions;\n this.name = 'ModuleFederationPlugin';\n }\n\n /**\n * The apply method is called by the webpack compiler and allows the plugin to hook into the webpack process.\n * @param compiler The webpack compiler object.\n */\n apply(compiler: Compiler) {\n bindLoggerToCompiler(logger, compiler, 'NextFederationPlugin');\n process.env['FEDERATION_WEBPACK_PATH'] =\n process.env['FEDERATION_WEBPACK_PATH'] ||\n getWebpackPath(compiler, { framework: 'nextjs' });\n if (!this.validateOptions(compiler)) return;\n const isServer = this.isServerCompiler(compiler);\n new CopyFederationPlugin(isServer).apply(compiler);\n const normalFederationPluginOptions = this.getNormalFederationPluginOptions(\n compiler,\n isServer,\n );\n this._options = normalFederationPluginOptions;\n this.applyConditionalPlugins(compiler, isServer);\n\n new ModuleFederationPlugin(normalFederationPluginOptions).apply(compiler);\n\n const noop = this.getNoopPath();\n\n if (!this._extraOptions.skipSharingNextInternals) {\n compiler.hooks.make.tapAsync(\n 'NextFederationPlugin',\n (compilation, callback) => {\n const dep = compiler.webpack.EntryPlugin.createDependency(\n noop,\n 'noop',\n );\n compilation.addEntry(\n compiler.context,\n dep,\n { name: 'noop' },\n (err, module) => {\n if (err) {\n return callback(err);\n }\n callback();\n },\n );\n },\n );\n }\n\n if (!compiler.options.ignoreWarnings) {\n compiler.options.ignoreWarnings = [\n //@ts-ignore\n (message) => /your target environment does not appear/.test(message),\n ];\n }\n }\n\n private validateOptions(compiler: Compiler): boolean {\n const manifestPlugin = compiler.options.plugins.find(\n (p): p is WebpackPluginInstance =>\n p?.constructor?.name === 'BuildManifestPlugin',\n );\n\n if (manifestPlugin) {\n //@ts-ignore\n if (manifestPlugin?.appDirEnabled) {\n throw new Error(\n 'App Directory is not supported by nextjs-mf. Use only pages directory, do not open git issues about this',\n );\n }\n }\n\n const compilerValid = validateCompilerOptions(compiler);\n const pluginValid = validatePluginOptions(this._options);\n const envValid = process.env['NEXT_PRIVATE_LOCAL_WEBPACK'];\n if (compilerValid === undefined) logger.error('Compiler validation failed');\n if (pluginValid === undefined) logger.error('Plugin validation failed');\n const validCompilerTarget =\n compiler.options.name === 'server' || compiler.options.name === 'client';\n if (!envValid)\n throw new Error(\n 'process.env.NEXT_PRIVATE_LOCAL_WEBPACK is not set to true, please set it to true, and \"npm install webpack\"',\n );\n return (\n compilerValid !== undefined &&\n pluginValid !== undefined &&\n validCompilerTarget\n );\n }\n\n private isServerCompiler(compiler: Compiler): boolean {\n return compiler.options.name === 'server';\n }\n\n private applyConditionalPlugins(compiler: Compiler, isServer: boolean) {\n compiler.options.output.uniqueName = this._options.name;\n compiler.options.output.environment = {\n ...compiler.options.output.environment,\n asyncFunction: true,\n };\n\n // Add layer rules for resource queries\n if (!compiler.options.module.rules) {\n compiler.options.module.rules = [];\n }\n\n // Add layer rules for RSC, client and SSR\n compiler.options.module.rules.push({\n resourceQuery: /\\?rsc/,\n layer: 'rsc',\n });\n\n compiler.options.module.rules.push({\n resourceQuery: /\\?client/,\n layer: 'client',\n });\n\n compiler.options.module.rules.push({\n resourceQuery: /\\?ssr/,\n layer: 'ssr',\n });\n\n applyPathFixes(compiler, this._options, this._extraOptions);\n if (this._extraOptions.debug) {\n compiler.options.devtool = false;\n }\n\n if (isServer) {\n configureServerCompilerOptions(compiler);\n configureServerLibraryAndFilename(this._options);\n applyServerPlugins(compiler, this._options);\n handleServerExternals(compiler, {\n ...this._options,\n shared: { ...retrieveDefaultShared(isServer), ...this._options.shared },\n });\n } else {\n applyClientPlugins(compiler, this._options, this._extraOptions);\n }\n }\n\n private getNormalFederationPluginOptions(\n compiler: Compiler,\n isServer: boolean,\n ): moduleFederationPlugin.ModuleFederationPluginOptions {\n const defaultShared = this._extraOptions.skipSharingNextInternals\n ? {}\n : retrieveDefaultShared(isServer);\n\n return {\n ...this._options,\n runtime: false,\n remoteType: 'script',\n runtimePlugins: [\n ...(isServer ? [resolveNodeRuntimePluginPath()] : []),\n resolveRuntimePluginPath(),\n ...(this._options.runtimePlugins || []),\n ].map((plugin) => plugin + '?runtimePlugin'),\n //@ts-ignore\n exposes: {\n ...this._options.exposes,\n ...(this._extraOptions.exposePages\n ? exposeNextjsPages(compiler.options.context as string)\n : {}),\n },\n remotes: {\n ...this._options.remotes,\n },\n shared: {\n ...defaultShared,\n ...this._options.shared,\n },\n manifest: {\n ...(this._options.manifest ?? {}),\n filePath: isServer ? '' : '/static/chunks',\n },\n // nextjs project needs to add config.watchOptions = ['**/node_modules/**', '**/@mf-types/**'] to prevent loop types update\n dts: this._options.dts ?? false,\n shareStrategy: this._options.shareStrategy ?? 'loaded-first',\n experiments: {\n asyncStartup: true,\n },\n };\n }\n\n private getNoopPath(): string {\n return resolveNoopPath();\n }\n}\n\nexport default NextFederationPlugin;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAkCA,MAAM,iCAGA,QAAQ,QAAQ,2EAA2E;AAEjG,MAAM,wBAGA,QAAQ,QAAQ,2DAA2D;AAEjF,MAAM,qCAA6C;CACjD,MAAM,kBAAkB,aAAK,QAC3B,QAAQ,QAAQ,uCAAuC,CACxD;AAED,QAAO,QAAQ,QACb,aAAK,KACH,iBAGI,4BACL,CACF;;;;;AAKH,IAAa,uBAAb,MAAkC;;;;;;CAShC,YAAY,SAAsC;EAChD,MAAM,EAAE,aAAa,iBAAiBA,+BAAW,QAAQ;AACzD,OAAK,WAAW;AAChB,OAAK,gBAAgB;AACrB,OAAK,OAAO;;;;;;CAOd,MAAM,UAAoB;AACxB,mDAAqBC,wBAAQ,UAAU,uBAAuB;AAC9D,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G,KAAK,SAAS;IACjB,GAAI,KAAK,cAAc,cACnBC,wDAAkB,SAAS,QAAQ,QAAkB,GACrD,EAAE;IACP;GACD,SAAS,EACP,GAAG,KAAK,SAAS,SAClB;GACD,QAAQ;IACN,GAAG;IACH,GAAG,KAAK,SAAS;IAClB;GACD,UAAU;IACR,GAAI,KAAK,SAAS,YAAY,EAAE;IAChC,UAAU,WAAW,KAAK;IAC3B;GAED,KAAK,KAAK,SAAS,OAAO;GAC1B,eAAe,KAAK,SAAS,iBAAiB;GAC9C,aAAa,EACX,cAAc,MACf;GACF;;CAGH,AAAQ,cAAsB;AAC5B,SAAO,iBAAiB"}
@@ -0,0 +1,153 @@
1
+ import { __require } from "../../../_virtual/_rolldown/runtime.mjs";
2
+ import logger from "../../logger.mjs";
3
+ import CopyBuildOutputPlugin from "../CopyFederationPlugin.mjs";
4
+ import { exposeNextjsPages } from "../../loaders/nextPageMapLoader.mjs";
5
+ import { applyPathFixes, retrieveDefaultShared } from "./next-fragments.mjs";
6
+ import { setOptions } from "./set-options.mjs";
7
+ import { validateCompilerOptions, validatePluginOptions } from "./validate-options.mjs";
8
+ import { applyServerPlugins, configureServerCompilerOptions, configureServerLibraryAndFilename, handleServerExternals } from "./apply-server-plugins.mjs";
9
+ import { applyClientPlugins } from "./apply-client-plugins.mjs";
10
+ import path from "path";
11
+ import { getWebpackPath } from "@module-federation/sdk/normalize-webpack-path";
12
+ import { bindLoggerToCompiler } from "@module-federation/sdk";
13
+ import { ModuleFederationPlugin } from "@module-federation/enhanced/webpack";
14
+
15
+ //#region src/plugins/NextFederationPlugin/index.ts
16
+ /**
17
+ * MIT License http://www.opensource.org/licenses/mit-license.php
18
+ * Author Zackary Jackson @ScriptedAlchemy
19
+ * This module contains the NextFederationPlugin class which is a webpack plugin that handles Next.js application federation using Module Federation.
20
+ */
21
+ const resolveRuntimePluginPath = () => __require.resolve("@module-federation/nextjs-mf/dist/src/plugins/container/runtimePlugin.mjs");
22
+ const resolveNoopPath = () => __require.resolve("@module-federation/nextjs-mf/dist/src/federation-noop.mjs");
23
+ const resolveNodeRuntimePluginPath = () => {
24
+ const nodePackageRoot = path.dirname(__require.resolve("@module-federation/node/package.json"));
25
+ return __require.resolve(path.join(nodePackageRoot, "dist/src/runtimePlugin.mjs"));
26
+ };
27
+ /**
28
+ * NextFederationPlugin is a webpack plugin that handles Next.js application federation using Module Federation.
29
+ */
30
+ var NextFederationPlugin = class {
31
+ /**
32
+ * Constructs the NextFederationPlugin with the provided options.
33
+ *
34
+ * @param options The options to configure the plugin.
35
+ */
36
+ constructor(options) {
37
+ const { mainOptions, extraOptions } = setOptions(options);
38
+ this._options = mainOptions;
39
+ this._extraOptions = extraOptions;
40
+ this.name = "ModuleFederationPlugin";
41
+ }
42
+ /**
43
+ * The apply method is called by the webpack compiler and allows the plugin to hook into the webpack process.
44
+ * @param compiler The webpack compiler object.
45
+ */
46
+ apply(compiler) {
47
+ bindLoggerToCompiler(logger, compiler, "NextFederationPlugin");
48
+ process.env["FEDERATION_WEBPACK_PATH"] = process.env["FEDERATION_WEBPACK_PATH"] || getWebpackPath(compiler, { framework: "nextjs" });
49
+ if (!this.validateOptions(compiler)) return;
50
+ const isServer = this.isServerCompiler(compiler);
51
+ new CopyBuildOutputPlugin(isServer).apply(compiler);
52
+ const normalFederationPluginOptions = this.getNormalFederationPluginOptions(compiler, isServer);
53
+ this._options = normalFederationPluginOptions;
54
+ this.applyConditionalPlugins(compiler, isServer);
55
+ new ModuleFederationPlugin(normalFederationPluginOptions).apply(compiler);
56
+ const noop = this.getNoopPath();
57
+ if (!this._extraOptions.skipSharingNextInternals) compiler.hooks.make.tapAsync("NextFederationPlugin", (compilation, callback) => {
58
+ const dep = compiler.webpack.EntryPlugin.createDependency(noop, "noop");
59
+ compilation.addEntry(compiler.context, dep, { name: "noop" }, (err, module) => {
60
+ if (err) return callback(err);
61
+ callback();
62
+ });
63
+ });
64
+ if (!compiler.options.ignoreWarnings) compiler.options.ignoreWarnings = [(message) => /your target environment does not appear/.test(message)];
65
+ }
66
+ validateOptions(compiler) {
67
+ const manifestPlugin = compiler.options.plugins.find((p) => p?.constructor?.name === "BuildManifestPlugin");
68
+ if (manifestPlugin) {
69
+ if (manifestPlugin?.appDirEnabled) throw new Error("App Directory is not supported by nextjs-mf. Use only pages directory, do not open git issues about this");
70
+ }
71
+ const compilerValid = validateCompilerOptions(compiler);
72
+ const pluginValid = validatePluginOptions(this._options);
73
+ const envValid = process.env["NEXT_PRIVATE_LOCAL_WEBPACK"];
74
+ if (compilerValid === void 0) logger.error("Compiler validation failed");
75
+ if (pluginValid === void 0) logger.error("Plugin validation failed");
76
+ const validCompilerTarget = compiler.options.name === "server" || compiler.options.name === "client";
77
+ if (!envValid) throw new Error("process.env.NEXT_PRIVATE_LOCAL_WEBPACK is not set to true, please set it to true, and \"npm install webpack\"");
78
+ return compilerValid !== void 0 && pluginValid !== void 0 && validCompilerTarget;
79
+ }
80
+ isServerCompiler(compiler) {
81
+ return compiler.options.name === "server";
82
+ }
83
+ applyConditionalPlugins(compiler, isServer) {
84
+ compiler.options.output.uniqueName = this._options.name;
85
+ compiler.options.output.environment = {
86
+ ...compiler.options.output.environment,
87
+ asyncFunction: true
88
+ };
89
+ if (!compiler.options.module.rules) compiler.options.module.rules = [];
90
+ compiler.options.module.rules.push({
91
+ resourceQuery: /\?rsc/,
92
+ layer: "rsc"
93
+ });
94
+ compiler.options.module.rules.push({
95
+ resourceQuery: /\?client/,
96
+ layer: "client"
97
+ });
98
+ compiler.options.module.rules.push({
99
+ resourceQuery: /\?ssr/,
100
+ layer: "ssr"
101
+ });
102
+ applyPathFixes(compiler, this._options, this._extraOptions);
103
+ if (this._extraOptions.debug) compiler.options.devtool = false;
104
+ if (isServer) {
105
+ configureServerCompilerOptions(compiler);
106
+ configureServerLibraryAndFilename(this._options);
107
+ applyServerPlugins(compiler, this._options);
108
+ handleServerExternals(compiler, {
109
+ ...this._options,
110
+ shared: {
111
+ ...retrieveDefaultShared(isServer),
112
+ ...this._options.shared
113
+ }
114
+ });
115
+ } else applyClientPlugins(compiler, this._options, this._extraOptions);
116
+ }
117
+ getNormalFederationPluginOptions(compiler, isServer) {
118
+ const defaultShared = this._extraOptions.skipSharingNextInternals ? {} : retrieveDefaultShared(isServer);
119
+ return {
120
+ ...this._options,
121
+ runtime: false,
122
+ remoteType: "script",
123
+ runtimePlugins: [
124
+ ...isServer ? [resolveNodeRuntimePluginPath()] : [],
125
+ resolveRuntimePluginPath(),
126
+ ...this._options.runtimePlugins || []
127
+ ].map((plugin) => plugin + "?runtimePlugin"),
128
+ exposes: {
129
+ ...this._options.exposes,
130
+ ...this._extraOptions.exposePages ? exposeNextjsPages(compiler.options.context) : {}
131
+ },
132
+ remotes: { ...this._options.remotes },
133
+ shared: {
134
+ ...defaultShared,
135
+ ...this._options.shared
136
+ },
137
+ manifest: {
138
+ ...this._options.manifest ?? {},
139
+ filePath: isServer ? "" : "/static/chunks"
140
+ },
141
+ dts: this._options.dts ?? false,
142
+ shareStrategy: this._options.shareStrategy ?? "loaded-first",
143
+ experiments: { asyncStartup: true }
144
+ };
145
+ }
146
+ getNoopPath() {
147
+ return resolveNoopPath();
148
+ }
149
+ };
150
+
151
+ //#endregion
152
+ export { NextFederationPlugin as default };
153
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":["CopyFederationPlugin"],"sources":["../../../../src/plugins/NextFederationPlugin/index.ts"],"sourcesContent":["/**\n * MIT License http://www.opensource.org/licenses/mit-license.php\n * Author Zackary Jackson @ScriptedAlchemy\n * This module contains the NextFederationPlugin class which is a webpack plugin that handles Next.js application federation using Module Federation.\n */\n'use strict';\n\nimport type {\n NextFederationPluginExtraOptions,\n NextFederationPluginOptions,\n} from './next-fragments';\nimport type { Compiler, WebpackPluginInstance } from 'webpack';\nimport path from 'path';\nimport { getWebpackPath } from '@module-federation/sdk/normalize-webpack-path';\nimport CopyFederationPlugin from '../CopyFederationPlugin';\nimport { exposeNextjsPages } from '../../loaders/nextPageMapLoader';\nimport { retrieveDefaultShared, applyPathFixes } from './next-fragments';\nimport { setOptions } from './set-options';\nimport {\n validateCompilerOptions,\n validatePluginOptions,\n} from './validate-options';\nimport {\n applyServerPlugins,\n configureServerCompilerOptions,\n configureServerLibraryAndFilename,\n handleServerExternals,\n} from './apply-server-plugins';\nimport { applyClientPlugins } from './apply-client-plugins';\nimport { ModuleFederationPlugin } from '@module-federation/enhanced/webpack';\nimport { bindLoggerToCompiler } from '@module-federation/sdk';\nimport type { moduleFederationPlugin } from '@module-federation/sdk';\nimport logger from '../../logger';\n\nconst resolveRuntimePluginPath = (): string =>\n process.env.IS_ESM_BUILD === 'true'\n ? require.resolve('@module-federation/nextjs-mf/dist/src/plugins/container/runtimePlugin.mjs')\n : require.resolve('@module-federation/nextjs-mf/dist/src/plugins/container/runtimePlugin.js');\n\nconst resolveNoopPath = (): string =>\n process.env.IS_ESM_BUILD === 'true'\n ? require.resolve('@module-federation/nextjs-mf/dist/src/federation-noop.mjs')\n : require.resolve('@module-federation/nextjs-mf/dist/src/federation-noop.js');\n\nconst resolveNodeRuntimePluginPath = (): string => {\n const nodePackageRoot = path.dirname(\n require.resolve('@module-federation/node/package.json'),\n );\n\n return require.resolve(\n path.join(\n nodePackageRoot,\n process.env.IS_ESM_BUILD === 'true'\n ? 'dist/src/runtimePlugin.mjs'\n : 'dist/src/runtimePlugin.js',\n ),\n );\n};\n/**\n * NextFederationPlugin is a webpack plugin that handles Next.js application federation using Module Federation.\n */\nexport class NextFederationPlugin {\n private _options: moduleFederationPlugin.ModuleFederationPluginOptions;\n private _extraOptions: NextFederationPluginExtraOptions;\n public name: string;\n /**\n * Constructs the NextFederationPlugin with the provided options.\n *\n * @param options The options to configure the plugin.\n */\n constructor(options: NextFederationPluginOptions) {\n const { mainOptions, extraOptions } = setOptions(options);\n this._options = mainOptions;\n this._extraOptions = extraOptions;\n this.name = 'ModuleFederationPlugin';\n }\n\n /**\n * The apply method is called by the webpack compiler and allows the plugin to hook into the webpack process.\n * @param compiler The webpack compiler object.\n */\n apply(compiler: Compiler) {\n bindLoggerToCompiler(logger, compiler, 'NextFederationPlugin');\n process.env['FEDERATION_WEBPACK_PATH'] =\n process.env['FEDERATION_WEBPACK_PATH'] ||\n getWebpackPath(compiler, { framework: 'nextjs' });\n if (!this.validateOptions(compiler)) return;\n const isServer = this.isServerCompiler(compiler);\n new CopyFederationPlugin(isServer).apply(compiler);\n const normalFederationPluginOptions = this.getNormalFederationPluginOptions(\n compiler,\n isServer,\n );\n this._options = normalFederationPluginOptions;\n this.applyConditionalPlugins(compiler, isServer);\n\n new ModuleFederationPlugin(normalFederationPluginOptions).apply(compiler);\n\n const noop = this.getNoopPath();\n\n if (!this._extraOptions.skipSharingNextInternals) {\n compiler.hooks.make.tapAsync(\n 'NextFederationPlugin',\n (compilation, callback) => {\n const dep = compiler.webpack.EntryPlugin.createDependency(\n noop,\n 'noop',\n );\n compilation.addEntry(\n compiler.context,\n dep,\n { name: 'noop' },\n (err, module) => {\n if (err) {\n return callback(err);\n }\n callback();\n },\n );\n },\n );\n }\n\n if (!compiler.options.ignoreWarnings) {\n compiler.options.ignoreWarnings = [\n //@ts-ignore\n (message) => /your target environment does not appear/.test(message),\n ];\n }\n }\n\n private validateOptions(compiler: Compiler): boolean {\n const manifestPlugin = compiler.options.plugins.find(\n (p): p is WebpackPluginInstance =>\n p?.constructor?.name === 'BuildManifestPlugin',\n );\n\n if (manifestPlugin) {\n //@ts-ignore\n if (manifestPlugin?.appDirEnabled) {\n throw new Error(\n 'App Directory is not supported by nextjs-mf. Use only pages directory, do not open git issues about this',\n );\n }\n }\n\n const compilerValid = validateCompilerOptions(compiler);\n const pluginValid = validatePluginOptions(this._options);\n const envValid = process.env['NEXT_PRIVATE_LOCAL_WEBPACK'];\n if (compilerValid === undefined) logger.error('Compiler validation failed');\n if (pluginValid === undefined) logger.error('Plugin validation failed');\n const validCompilerTarget =\n compiler.options.name === 'server' || compiler.options.name === 'client';\n if (!envValid)\n throw new Error(\n 'process.env.NEXT_PRIVATE_LOCAL_WEBPACK is not set to true, please set it to true, and \"npm install webpack\"',\n );\n return (\n compilerValid !== undefined &&\n pluginValid !== undefined &&\n validCompilerTarget\n );\n }\n\n private isServerCompiler(compiler: Compiler): boolean {\n return compiler.options.name === 'server';\n }\n\n private applyConditionalPlugins(compiler: Compiler, isServer: boolean) {\n compiler.options.output.uniqueName = this._options.name;\n compiler.options.output.environment = {\n ...compiler.options.output.environment,\n asyncFunction: true,\n };\n\n // Add layer rules for resource queries\n if (!compiler.options.module.rules) {\n compiler.options.module.rules = [];\n }\n\n // Add layer rules for RSC, client and SSR\n compiler.options.module.rules.push({\n resourceQuery: /\\?rsc/,\n layer: 'rsc',\n });\n\n compiler.options.module.rules.push({\n resourceQuery: /\\?client/,\n layer: 'client',\n });\n\n compiler.options.module.rules.push({\n resourceQuery: /\\?ssr/,\n layer: 'ssr',\n });\n\n applyPathFixes(compiler, this._options, this._extraOptions);\n if (this._extraOptions.debug) {\n compiler.options.devtool = false;\n }\n\n if (isServer) {\n configureServerCompilerOptions(compiler);\n configureServerLibraryAndFilename(this._options);\n applyServerPlugins(compiler, this._options);\n handleServerExternals(compiler, {\n ...this._options,\n shared: { ...retrieveDefaultShared(isServer), ...this._options.shared },\n });\n } else {\n applyClientPlugins(compiler, this._options, this._extraOptions);\n }\n }\n\n private getNormalFederationPluginOptions(\n compiler: Compiler,\n isServer: boolean,\n ): moduleFederationPlugin.ModuleFederationPluginOptions {\n const defaultShared = this._extraOptions.skipSharingNextInternals\n ? {}\n : retrieveDefaultShared(isServer);\n\n return {\n ...this._options,\n runtime: false,\n remoteType: 'script',\n runtimePlugins: [\n ...(isServer ? [resolveNodeRuntimePluginPath()] : []),\n resolveRuntimePluginPath(),\n ...(this._options.runtimePlugins || []),\n ].map((plugin) => plugin + '?runtimePlugin'),\n //@ts-ignore\n exposes: {\n ...this._options.exposes,\n ...(this._extraOptions.exposePages\n ? exposeNextjsPages(compiler.options.context as string)\n : {}),\n },\n remotes: {\n ...this._options.remotes,\n },\n shared: {\n ...defaultShared,\n ...this._options.shared,\n },\n manifest: {\n ...(this._options.manifest ?? {}),\n filePath: isServer ? '' : '/static/chunks',\n },\n // nextjs project needs to add config.watchOptions = ['**/node_modules/**', '**/@mf-types/**'] to prevent loop types update\n dts: this._options.dts ?? false,\n shareStrategy: this._options.shareStrategy ?? 'loaded-first',\n experiments: {\n asyncStartup: true,\n },\n };\n }\n\n private getNoopPath(): string {\n return resolveNoopPath();\n }\n}\n\nexport default NextFederationPlugin;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAkCA,MAAM,2CAEQ,QAAQ,4EAA4E;AAGlG,MAAM,kCAEQ,QAAQ,4DAA4D;AAGlF,MAAM,qCAA6C;CACjD,MAAM,kBAAkB,KAAK,kBACnB,QAAQ,uCAAuC,CACxD;AAED,kBAAe,QACb,KAAK,KACH,iBAEI,6BAEL,CACF;;;;;AAKH,IAAa,uBAAb,MAAkC;;;;;;CAShC,YAAY,SAAsC;EAChD,MAAM,EAAE,aAAa,iBAAiB,WAAW,QAAQ;AACzD,OAAK,WAAW;AAChB,OAAK,gBAAgB;AACrB,OAAK,OAAO;;;;;;CAOd,MAAM,UAAoB;AACxB,uBAAqB,QAAQ,UAAU,uBAAuB;AAC9D,UAAQ,IAAI,6BACV,QAAQ,IAAI,8BACZ,eAAe,UAAU,EAAE,WAAW,UAAU,CAAC;AACnD,MAAI,CAAC,KAAK,gBAAgB,SAAS,CAAE;EACrC,MAAM,WAAW,KAAK,iBAAiB,SAAS;AAChD,MAAIA,sBAAqB,SAAS,CAAC,MAAM,SAAS;EAClD,MAAM,gCAAgC,KAAK,iCACzC,UACA,SACD;AACD,OAAK,WAAW;AAChB,OAAK,wBAAwB,UAAU,SAAS;AAEhD,MAAI,uBAAuB,8BAA8B,CAAC,MAAM,SAAS;EAEzE,MAAM,OAAO,KAAK,aAAa;AAE/B,MAAI,CAAC,KAAK,cAAc,yBACtB,UAAS,M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 import { moduleFederationPlugin } from "@module-federation/sdk";
2
+ import { Compiler } from "webpack";
3
+
4
+ //#region src/plugins/NextFederationPlugin/next-fragments.d.ts
5
+ interface NextFederationPluginExtraOptions {
6
+ enableImageLoaderFix?: boolean;
7
+ enableUrlLoaderFix?: boolean;
8
+ exposePages?: boolean;
9
+ skipSharingNextInternals?: boolean;
10
+ automaticPageStitching?: boolean;
11
+ debug?: boolean;
12
+ }
13
+ interface NextFederationPluginOptions extends moduleFederationPlugin.ModuleFederationPluginOptions {
14
+ extraOptions: NextFederationPluginExtraOptions;
15
+ }
16
+ //#endregion
17
+ export { NextFederationPluginOptions };
18
+ //# sourceMappingURL=next-fragments.d.mts.map
@@ -0,0 +1,18 @@
1
+ import { Compiler } from "webpack";
2
+ import { moduleFederationPlugin } from "@module-federation/sdk";
3
+
4
+ //#region src/plugins/NextFederationPlugin/next-fragments.d.ts
5
+ interface NextFederationPluginExtraOptions {
6
+ enableImageLoaderFix?: boolean;
7
+ enableUrlLoaderFix?: boolean;
8
+ exposePages?: boolean;
9
+ skipSharingNextInternals?: boolean;
10
+ automaticPageStitching?: boolean;
11
+ debug?: boolean;
12
+ }
13
+ interface NextFederationPluginOptions extends moduleFederationPlugin.ModuleFederationPluginOptions {
14
+ extraOptions: NextFederationPluginExtraOptions;
15
+ }
16
+ //#endregion
17
+ export { NextFederationPluginOptions };
18
+ //# sourceMappingURL=next-fragments.d.ts.map
@@ -0,0 +1,65 @@
1
+ const require_runtime = require('../../../_virtual/_rolldown/runtime.js');
2
+ const require_internal = require('../../internal.js');
3
+ const require_helpers = require('../../loaders/helpers.js');
4
+ let path = require("path");
5
+ path = require_runtime.__toESM(path);
6
+
7
+ //#region src/plugins/NextFederationPlugin/next-fragments.ts
8
+ const resolveFixImageLoaderPath = () => require.resolve("@module-federation/nextjs-mf/dist/src/loaders/fixImageLoader.js");
9
+ const resolveFixUrlLoaderPath = () => require.resolve("@module-federation/nextjs-mf/dist/src/loaders/fixUrlLoader.js");
10
+ /**
11
+ * Set up default shared values based on the environment.
12
+ * @param {boolean} isServer - Boolean indicating if the code is running on the server.
13
+ * @returns {SharedObject} The default share scope based on the environment.
14
+ */
15
+ const retrieveDefaultShared = (isServer) => {
16
+ if (isServer) return require_internal.DEFAULT_SHARE_SCOPE;
17
+ return require_internal.DEFAULT_SHARE_SCOPE_BROWSER;
18
+ };
19
+ const applyPathFixes = (compiler, pluginOptions, options) => {
20
+ const match = require_helpers.findLoaderForResource(compiler.options.module.rules, {
21
+ path: path.default.join(compiler.context, "/something/thing.js"),
22
+ issuerLayer: void 0,
23
+ layer: void 0
24
+ });
25
+ compiler.options.module.rules.forEach((rule) => {
26
+ if (typeof rule === "object" && rule !== null) {
27
+ const typedRule = rule;
28
+ if (options.enableImageLoaderFix && require_helpers.hasLoader(typedRule, "next-image-loader")) require_helpers.injectRuleLoader(typedRule, { loader: resolveFixImageLoaderPath() });
29
+ if (options.enableUrlLoaderFix && require_helpers.hasLoader(typedRule, "url-loader")) require_helpers.injectRuleLoader(typedRule, { loader: resolveFixUrlLoaderPath() });
30
+ }
31
+ });
32
+ if (match) {
33
+ let matchCopy;
34
+ if (match.use) {
35
+ matchCopy = { ...match };
36
+ if (Array.isArray(match.use)) matchCopy.use = match.use.filter((loader) => {
37
+ return typeof loader === "object" && loader.loader && !loader.loader.includes("react");
38
+ });
39
+ else if (typeof match.use === "string") matchCopy.use = match.use.includes("react") ? "" : match.use;
40
+ else if (typeof match.use === "object" && match.use !== null) matchCopy.use = match.use.loader && match.use.loader.includes("react") ? {} : match.use;
41
+ } else matchCopy = { ...match };
42
+ const descriptionDataRule = {
43
+ ...matchCopy,
44
+ descriptionData: { name: /^(@module-federation)/ },
45
+ exclude: void 0,
46
+ include: void 0
47
+ };
48
+ const testRule = {
49
+ ...matchCopy,
50
+ resourceQuery: /runtimePlugin/,
51
+ exclude: void 0,
52
+ include: void 0
53
+ };
54
+ const oneOfRule = compiler.options.module.rules.find((rule) => {
55
+ return !!rule && typeof rule === "object" && "oneOf" in rule;
56
+ });
57
+ if (!oneOfRule) compiler.options.module.rules.unshift({ oneOf: [descriptionDataRule, testRule] });
58
+ else if (oneOfRule.oneOf) oneOfRule.oneOf.unshift(descriptionDataRule, testRule);
59
+ }
60
+ };
61
+
62
+ //#endregion
63
+ exports.applyPathFixes = applyPathFixes;
64
+ exports.retrieveDefaultShared = retrieveDefaultShared;
65
+ //# sourceMappingURL=next-fragments.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"next-fragments.js","names":["DEFAULT_SHARE_SCOPE","DEFAULT_SHARE_SCOPE_BROWSER","findLoaderForResource","hasLoader"],"sources":["../../../../src/plugins/NextFederationPlugin/next-fragments.ts"],"sourcesContent":["import type { Compiler, RuleSetRule } from 'webpack';\nimport type {\n moduleFederationPlugin,\n sharePlugin,\n} from '@module-federation/sdk';\nimport {\n DEFAULT_SHARE_SCOPE,\n DEFAULT_SHARE_SCOPE_BROWSER,\n} from '../../internal';\nimport {\n hasLoader,\n injectRuleLoader,\n findLoaderForResource,\n} from '../../loaders/helpers';\nimport path from 'path';\n\nconst resolveFixImageLoaderPath = (): string =>\n process.env.IS_ESM_BUILD === 'true'\n ? require.resolve('@module-federation/nextjs-mf/dist/src/loaders/fixImageLoader.mjs')\n : require.resolve('@module-federation/nextjs-mf/dist/src/loaders/fixImageLoader.js');\n\nconst resolveFixUrlLoaderPath = (): string =>\n process.env.IS_ESM_BUILD === 'true'\n ? require.resolve('@module-federation/nextjs-mf/dist/src/loaders/fixUrlLoader.mjs')\n : require.resolve('@module-federation/nextjs-mf/dist/src/loaders/fixUrlLoader.js');\n/**\n * Set up default shared values based on the environment.\n * @param {boolean} isServer - Boolean indicating if the code is running on the server.\n * @returns {SharedObject} The default share scope based on the environment.\n */\nexport const retrieveDefaultShared = (\n isServer: boolean,\n): moduleFederationPlugin.SharedObject => {\n // If the code is running on the server, treat some Next.js internals as import false to make them external\n // This is because they will be provided by the server environment and not by the remote container\n if (isServer) {\n return DEFAULT_SHARE_SCOPE;\n }\n // If the code is running on the client/browser, always bundle Next.js internals\n return DEFAULT_SHARE_SCOPE_BROWSER;\n};\nexport const applyPathFixes = (\n compiler: Compiler,\n pluginOptions: moduleFederationPlugin.ModuleFederationPluginOptions,\n options: any,\n) => {\n const match = findLoaderForResource(\n compiler.options.module.rules as RuleSetRule[],\n {\n path: path.join(compiler.context, '/something/thing.js'),\n issuerLayer: undefined,\n layer: undefined,\n },\n );\n\n compiler.options.module.rules.forEach((rule) => {\n if (typeof rule === 'object' && rule !== null) {\n const typedRule = rule as RuleSetRule;\n // next-image-loader fix which adds remote's hostname to the assets url\n if (\n options.enableImageLoaderFix &&\n hasLoader(typedRule, 'next-image-loader')\n ) {\n injectRuleLoader(typedRule, {\n loader: resolveFixImageLoaderPath(),\n });\n }\n\n if (options.enableUrlLoaderFix && hasLoader(typedRule, 'url-loader')) {\n injectRuleLoader(typedRule, {\n loader: resolveFixUrlLoaderPath(),\n });\n }\n }\n });\n\n if (match) {\n let matchCopy: RuleSetRule;\n if (match.use) {\n matchCopy = { ...match };\n if (Array.isArray(match.use)) {\n matchCopy.use = match.use.filter((loader: any) => {\n return (\n typeof loader === 'object' &&\n loader.loader &&\n !loader.loader.includes('react')\n );\n });\n } else if (typeof match.use === 'string') {\n matchCopy.use = match.use.includes('react') ? '' : match.use;\n } else if (typeof match.use === 'object' && match.use !== null) {\n matchCopy.use =\n match.use.loader && match.use.loader.includes('react')\n ? {}\n : match.use;\n }\n } else {\n matchCopy = { ...match };\n }\n\n const descriptionDataRule: RuleSetRule = {\n ...matchCopy,\n descriptionData: {\n name: /^(@module-federation)/,\n },\n exclude: undefined,\n include: undefined,\n };\n\n const testRule: RuleSetRule = {\n ...matchCopy,\n resourceQuery: /runtimePlugin/,\n exclude: undefined,\n include: undefined,\n };\n\n const oneOfRule = compiler.options.module.rules.find(\n (rule): rule is RuleSetRule => {\n return !!rule && typeof rule === 'object' && 'oneOf' in rule;\n },\n ) as RuleSetRule | undefined;\n\n if (!oneOfRule) {\n compiler.options.module.rules.unshift({\n oneOf: [descriptionDataRule, testRule],\n });\n } else if (oneOfRule.oneOf) {\n oneOfRule.oneOf.unshift(descriptionDataRule, testRule);\n }\n }\n};\n\nexport interface NextFederationPluginExtraOptions {\n enableImageLoaderFix?: boolean;\n enableUrlLoaderFix?: boolean;\n exposePages?: boolean;\n skipSharingNextInternals?: boolean;\n automaticPageStitching?: boolean;\n debug?: boolean;\n}\n\nexport interface NextFederationPluginOptions\n extends moduleFederationPlugin.ModuleFederationPluginOptions {\n extraOptions: NextFederationPluginExtraOptions;\n}\n"],"mappings":";;;;;;;AAgBA,MAAM,kCAGA,QAAQ,QAAQ,kEAAkE;AAExF,MAAM,gCAGA,QAAQ,QAAQ,gEAAgE;;;;;;AAMtF,MAAa,yBACX,aACwC;AAGxC,KAAI,SACF,QAAOA;AAGT,QAAOC;;AAET,MAAa,kBACX,UACA,eACA,YACG;CACH,MAAM,QAAQC,sCACZ,SAAS,QAAQ,OAAO,OACxB;EACE,MAAM,aAAK,KAAK,SAAS,SAAS,sBAAsB;EACxD,aAAa;EACb,OAAO;EACR,CACF;AAED,UAAS,QAAQ,OAAO,MAAM,SAAS,SAAS;AAC9C,MAAI,OAAO,SAAS,YAAY,SAAS,MAAM;GAC7C,MAAM,YAAY;AAElB,OACE,QAAQ,wBACRC,0BAAU,WAAW,oBAAoB,CAEzC,kCAAiB,WAAW,EAC1B,QAAQ,2BAA2B,EACpC,CAAC;AAGJ,OAAI,QAAQ,sBAAsBA,0BAAU,WAAW,aAAa,CAClE,kCAAiB,WAAW,EAC1B,QAAQ,yBAAyB,EAClC,CAAC;;GAGN;AAEF,KAAI,OAAO;EACT,IAAI;AACJ,MAAI,MAAM,KAAK;AACb,eAAY,EAAE,GAAG,OAAO;AACxB,OAAI,MAAM,QAAQ,MAAM,IAAI,CAC1B,WAAU,MAAM,MAAM,IAAI,QAAQ,WAAgB;AAChD,WACE,OAAO,WAAW,YAClB,OAAO,UACP,CAAC,OAAO,OAAO,SAAS,QAAQ;KAElC;YACO,OAAO,MAAM,QAAQ,SAC9B,WAAU,MAAM,MAAM,IAAI,SAAS,QAAQ,GAAG,KAAK,MAAM;YAChD,OAAO,MAAM,QAAQ,YAAY,MAAM,QAAQ,KACxD,WAAU,MACR,MAAM,IAAI,UAAU,MAAM,IAAI,OAAO,SAAS,QAAQ,GAClD,EAAE,GACF,MAAM;QAGd,aAAY,EAAE,GAAG,OAAO;EAG1B,MAAM,sBAAmC;GACvC,GAAG;GACH,iBAAiB,EACf,MAAM,yBACP;GACD,SAAS;GACT,SAAS;GACV;EAED,MAAM,WAAwB;GAC5B,GAAG;GACH,eAAe;GACf,SAAS;GACT,SAAS;GACV;EAED,MAAM,YAAY,SAAS,QAAQ,OAAO,MAAM,MAC7C,SAA8B;AAC7B,UAAO,CAAC,CAAC,QAAQ,OAAO,SAAS,YAAY,WAAW;IAE3D;AAED,MAAI,CAAC,UACH,UAAS,QAAQ,OAAO,MAAM,QAAQ,EACpC,OAAO,CAAC,qBAAqB,SAAS,EACvC,CAAC;WACO,UAAU,MACnB,WAAU,MAAM,QAAQ,qBAAqB,SAAS"}
@@ -0,0 +1,63 @@
1
+ import { __require } from "../../../_virtual/_rolldown/runtime.mjs";
2
+ import { DEFAULT_SHARE_SCOPE, DEFAULT_SHARE_SCOPE_BROWSER } from "../../internal.mjs";
3
+ import { findLoaderForResource, hasLoader, injectRuleLoader } from "../../loaders/helpers.mjs";
4
+ import path from "path";
5
+
6
+ //#region src/plugins/NextFederationPlugin/next-fragments.ts
7
+ const resolveFixImageLoaderPath = () => __require.resolve("@module-federation/nextjs-mf/dist/src/loaders/fixImageLoader.mjs");
8
+ const resolveFixUrlLoaderPath = () => __require.resolve("@module-federation/nextjs-mf/dist/src/loaders/fixUrlLoader.mjs");
9
+ /**
10
+ * Set up default shared values based on the environment.
11
+ * @param {boolean} isServer - Boolean indicating if the code is running on the server.
12
+ * @returns {SharedObject} The default share scope based on the environment.
13
+ */
14
+ const retrieveDefaultShared = (isServer) => {
15
+ if (isServer) return DEFAULT_SHARE_SCOPE;
16
+ return DEFAULT_SHARE_SCOPE_BROWSER;
17
+ };
18
+ const applyPathFixes = (compiler, pluginOptions, options) => {
19
+ const match = findLoaderForResource(compiler.options.module.rules, {
20
+ path: path.join(compiler.context, "/something/thing.js"),
21
+ issuerLayer: void 0,
22
+ layer: void 0
23
+ });
24
+ compiler.options.module.rules.forEach((rule) => {
25
+ if (typeof rule === "object" && rule !== null) {
26
+ const typedRule = rule;
27
+ if (options.enableImageLoaderFix && hasLoader(typedRule, "next-image-loader")) injectRuleLoader(typedRule, { loader: resolveFixImageLoaderPath() });
28
+ if (options.enableUrlLoaderFix && hasLoader(typedRule, "url-loader")) injectRuleLoader(typedRule, { loader: resolveFixUrlLoaderPath() });
29
+ }
30
+ });
31
+ if (match) {
32
+ let matchCopy;
33
+ if (match.use) {
34
+ matchCopy = { ...match };
35
+ if (Array.isArray(match.use)) matchCopy.use = match.use.filter((loader) => {
36
+ return typeof loader === "object" && loader.loader && !loader.loader.includes("react");
37
+ });
38
+ else if (typeof match.use === "string") matchCopy.use = match.use.includes("react") ? "" : match.use;
39
+ else if (typeof match.use === "object" && match.use !== null) matchCopy.use = match.use.loader && match.use.loader.includes("react") ? {} : match.use;
40
+ } else matchCopy = { ...match };
41
+ const descriptionDataRule = {
42
+ ...matchCopy,
43
+ descriptionData: { name: /^(@module-federation)/ },
44
+ exclude: void 0,
45
+ include: void 0
46
+ };
47
+ const testRule = {
48
+ ...matchCopy,
49
+ resourceQuery: /runtimePlugin/,
50
+ exclude: void 0,
51
+ include: void 0
52
+ };
53
+ const oneOfRule = compiler.options.module.rules.find((rule) => {
54
+ return !!rule && typeof rule === "object" && "oneOf" in rule;
55
+ });
56
+ if (!oneOfRule) compiler.options.module.rules.unshift({ oneOf: [descriptionDataRule, testRule] });
57
+ else if (oneOfRule.oneOf) oneOfRule.oneOf.unshift(descriptionDataRule, testRule);
58
+ }
59
+ };
60
+
61
+ //#endregion
62
+ export { applyPathFixes, retrieveDefaultShared };
63
+ //# sourceMappingURL=next-fragments.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"next-fragments.mjs","names":[],"sources":["../../../../src/plugins/NextFederationPlugin/next-fragments.ts"],"sourcesContent":["import type { Compiler, RuleSetRule } from 'webpack';\nimport type {\n moduleFederationPlugin,\n sharePlugin,\n} from '@module-federation/sdk';\nimport {\n DEFAULT_SHARE_SCOPE,\n DEFAULT_SHARE_SCOPE_BROWSER,\n} from '../../internal';\nimport {\n hasLoader,\n injectRuleLoader,\n findLoaderForResource,\n} from '../../loaders/helpers';\nimport path from 'path';\n\nconst resolveFixImageLoaderPath = (): string =>\n process.env.IS_ESM_BUILD === 'true'\n ? require.resolve('@module-federation/nextjs-mf/dist/src/loaders/fixImageLoader.mjs')\n : require.resolve('@module-federation/nextjs-mf/dist/src/loaders/fixImageLoader.js');\n\nconst resolveFixUrlLoaderPath = (): string =>\n process.env.IS_ESM_BUILD === 'true'\n ? require.resolve('@module-federation/nextjs-mf/dist/src/loaders/fixUrlLoader.mjs')\n : require.resolve('@module-federation/nextjs-mf/dist/src/loaders/fixUrlLoader.js');\n/**\n * Set up default shared values based on the environment.\n * @param {boolean} isServer - Boolean indicating if the code is running on the server.\n * @returns {SharedObject} The default share scope based on the environment.\n */\nexport const retrieveDefaultShared = (\n isServer: boolean,\n): moduleFederationPlugin.SharedObject => {\n // If the code is running on the server, treat some Next.js internals as import false to make them external\n // This is because they will be provided by the server environment and not by the remote container\n if (isServer) {\n return DEFAULT_SHARE_SCOPE;\n }\n // If the code is running on the client/browser, always bundle Next.js internals\n return DEFAULT_SHARE_SCOPE_BROWSER;\n};\nexport const applyPathFixes = (\n compiler: Compiler,\n pluginOptions: moduleFederationPlugin.ModuleFederationPluginOptions,\n options: any,\n) => {\n const match = findLoaderForResource(\n compiler.options.module.rules as RuleSetRule[],\n {\n path: path.join(compiler.context, '/something/thing.js'),\n issuerLayer: undefined,\n layer: undefined,\n },\n );\n\n compiler.options.module.rules.forEach((rule) => {\n if (typeof rule === 'object' && rule !== null) {\n const typedRule = rule as RuleSetRule;\n // next-image-loader fix which adds remote's hostname to the assets url\n if (\n options.enableImageLoaderFix &&\n hasLoader(typedRule, 'next-image-loader')\n ) {\n injectRuleLoader(typedRule, {\n loader: resolveFixImageLoaderPath(),\n });\n }\n\n if (options.enableUrlLoaderFix && hasLoader(typedRule, 'url-loader')) {\n injectRuleLoader(typedRule, {\n loader: resolveFixUrlLoaderPath(),\n });\n }\n }\n });\n\n if (match) {\n let matchCopy: RuleSetRule;\n if (match.use) {\n matchCopy = { ...match };\n if (Array.isArray(match.use)) {\n matchCopy.use = match.use.filter((loader: any) => {\n return (\n typeof loader === 'object' &&\n loader.loader &&\n !loader.loader.includes('react')\n );\n });\n } else if (typeof match.use === 'string') {\n matchCopy.use = match.use.includes('react') ? '' : match.use;\n } else if (typeof match.use === 'object' && match.use !== null) {\n matchCopy.use =\n match.use.loader && match.use.loader.includes('react')\n ? {}\n : match.use;\n }\n } else {\n matchCopy = { ...match };\n }\n\n const descriptionDataRule: RuleSetRule = {\n ...matchCopy,\n descriptionData: {\n name: /^(@module-federation)/,\n },\n exclude: undefined,\n include: undefined,\n };\n\n const testRule: RuleSetRule = {\n ...matchCopy,\n resourceQuery: /runtimePlugin/,\n exclude: undefined,\n include: undefined,\n };\n\n const oneOfRule = compiler.options.module.rules.find(\n (rule): rule is RuleSetRule => {\n return !!rule && typeof rule === 'object' && 'oneOf' in rule;\n },\n ) as RuleSetRule | undefined;\n\n if (!oneOfRule) {\n compiler.options.module.rules.unshift({\n oneOf: [descriptionDataRule, testRule],\n });\n } else if (oneOfRule.oneOf) {\n oneOfRule.oneOf.unshift(descriptionDataRule, testRule);\n }\n }\n};\n\nexport interface NextFederationPluginExtraOptions {\n enableImageLoaderFix?: boolean;\n enableUrlLoaderFix?: boolean;\n exposePages?: boolean;\n skipSharingNextInternals?: boolean;\n automaticPageStitching?: boolean;\n debug?: boolean;\n}\n\nexport interface NextFeder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G;GACH,iBAAiB,EACf,MAAM,yBACP;GACD,SAAS;GACT,SAAS;GACV;EAED,MAAM,WAAwB;GAC5B,GAAG;GACH,eAAe;GACf,SAAS;GACT,SAAS;GACV;EAED,MAAM,YAAY,SAAS,QAAQ,OAAO,MAAM,MAC7C,SAA8B;AAC7B,UAAO,CAAC,CAAC,QAAQ,OAAO,SAAS,YAAY,WAAW;IAE3D;AAED,MAAI,CAAC,UACH,UAAS,QAAQ,OAAO,MAAM,QAAQ,EACpC,OAAO,CAAC,qBAAqB,SAAS,EACvC,CAAC;WACO,UAAU,MACnB,WAAU,MAAM,QAAQ,qBAAqB,SAAS"}
@@ -0,0 +1,20 @@
1
+
2
+ //#region src/plugins/NextFederationPlugin/set-options.ts
3
+ function setOptions(options) {
4
+ const { extraOptions, ...mainOpts } = options;
5
+ return {
6
+ mainOptions: mainOpts,
7
+ extraOptions: {
8
+ automaticPageStitching: false,
9
+ enableImageLoaderFix: false,
10
+ enableUrlLoaderFix: false,
11
+ skipSharingNextInternals: false,
12
+ debug: false,
13
+ ...extraOptions
14
+ }
15
+ };
16
+ }
17
+
18
+ //#endregion
19
+ exports.setOptions = setOptions;
20
+ //# sourceMappingURL=set-options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"set-options.js","names":[],"sources":["../../../../src/plugins/NextFederationPlugin/set-options.ts"],"sourcesContent":["import type { moduleFederationPlugin } from '@module-federation/sdk';\n\nexport interface NextFederationPluginExtraOptions {\n enableImageLoaderFix?: boolean;\n enableUrlLoaderFix?: boolean;\n exposePages?: boolean;\n skipSharingNextInternals?: boolean;\n automaticPageStitching?: boolean;\n debug?: boolean;\n}\n\nexport interface NextFederationPluginOptions\n extends moduleFederationPlugin.ModuleFederationPluginOptions {\n extraOptions: NextFederationPluginExtraOptions;\n}\n\nexport function setOptions(options: NextFederationPluginOptions): {\n mainOptions: moduleFederationPlugin.ModuleFederationPluginOptions;\n extraOptions: NextFederationPluginExtraOptions;\n} {\n const { extraOptions, ...mainOpts } = options;\n\n /**\n * Default extra options for NextFederationPlugin.\n * @type {NextFederationPluginExtraOptions}\n */\n const defaultExtraOptions: NextFederationPluginExtraOptions = {\n automaticPageStitching: false,\n enableImageLoaderFix: false,\n enableUrlLoaderFix: false,\n skipSharingNextInternals: false,\n debug: false,\n };\n\n return {\n mainOptions: mainOpts,\n extraOptions: { ...defaultExtraOptions, ...extraOptions },\n };\n}\n"],"mappings":";;AAgBA,SAAgB,WAAW,SAGzB;CACA,MAAM,EAAE,cAAc,GAAG,aAAa;AActC,QAAO;EACL,aAAa;EACb,cAAc;GATd,wBAAwB;GACxB,sBAAsB;GACtB,oBAAoB;GACpB,0BAA0B;GAC1B,OAAO;GAKiC,GAAG;GAAc;EAC1D"}
@@ -0,0 +1,19 @@
1
+ //#region src/plugins/NextFederationPlugin/set-options.ts
2
+ function setOptions(options) {
3
+ const { extraOptions, ...mainOpts } = options;
4
+ return {
5
+ mainOptions: mainOpts,
6
+ extraOptions: {
7
+ automaticPageStitching: false,
8
+ enableImageLoaderFix: false,
9
+ enableUrlLoaderFix: false,
10
+ skipSharingNextInternals: false,
11
+ debug: false,
12
+ ...extraOptions
13
+ }
14
+ };
15
+ }
16
+
17
+ //#endregion
18
+ export { setOptions };
19
+ //# sourceMappingURL=set-options.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"set-options.mjs","names":[],"sources":["../../../../src/plugins/NextFederationPlugin/set-options.ts"],"sourcesContent":["import type { moduleFederationPlugin } from '@module-federation/sdk';\n\nexport interface NextFederationPluginExtraOptions {\n enableImageLoaderFix?: boolean;\n enableUrlLoaderFix?: boolean;\n exposePages?: boolean;\n skipSharingNextInternals?: boolean;\n automaticPageStitching?: boolean;\n debug?: boolean;\n}\n\nexport interface NextFederationPluginOptions\n extends moduleFederationPlugin.ModuleFederationPluginOptions {\n extraOptions: NextFederationPluginExtraOptions;\n}\n\nexport function setOptions(options: NextFederationPluginOptions): {\n mainOptions: moduleFederationPlugin.ModuleFederationPluginOptions;\n extraOptions: NextFederationPluginExtraOptions;\n} {\n const { extraOptions, ...mainOpts } = options;\n\n /**\n * Default extra options for NextFederationPlugin.\n * @type {NextFederationPluginExtraOptions}\n */\n const defaultExtraOptions: NextFederationPluginExtraOptions = {\n automaticPageStitching: false,\n enableImageLoaderFix: false,\n enableUrlLoaderFix: false,\n skipSharingNextInternals: false,\n debug: false,\n };\n\n return {\n mainOptions: mainOpts,\n extraOptions: { ...defaultExtraOptions, ...extraOptions },\n };\n}\n"],"mappings":";AAgBA,SAAgB,WAAW,SAGzB;CACA,MAAM,EAAE,cAAc,GAAG,aAAa;AActC,QAAO;EACL,aAAa;EACb,cAAc;GATd,wBAAwB;GACxB,sBAAsB;GACtB,oBAAoB;GACpB,0BAA0B;GAC1B,OAAO;GAKiC,GAAG;GAAc;EAC1D"}