@module-federation/modern-js 0.0.0-release-v0-21-5-20251120103315 → 0.0.0-release-v0-23-0-20260123023720

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 (113) hide show
  1. package/dist/cjs/cli/configPlugin.js +341 -377
  2. package/dist/cjs/cli/index.js +103 -93
  3. package/dist/cjs/cli/mfRuntimePlugins/inject-node-fetch.js +51 -41
  4. package/dist/cjs/cli/mfRuntimePlugins/resolve-entry-ipv4.js +73 -75
  5. package/dist/cjs/cli/mfRuntimePlugins/shared-strategy.js +50 -40
  6. package/dist/cjs/cli/server/data-fetch-server-plugin.js +55 -44
  7. package/dist/cjs/cli/ssrPlugin.js +266 -298
  8. package/dist/cjs/cli/utils.js +84 -81
  9. package/dist/cjs/constant.js +37 -28
  10. package/dist/cjs/interfaces/bundler.js +17 -15
  11. package/dist/cjs/logger.js +37 -25
  12. package/dist/cjs/react/index.js +55 -19
  13. package/dist/cjs/react/plugin.js +62 -37
  14. package/dist/cjs/react/v18.js +55 -19
  15. package/dist/cjs/react/v19.js +55 -19
  16. package/dist/cjs/runtime/index.js +55 -19
  17. package/dist/cjs/server/fileCache.js +76 -76
  18. package/dist/cjs/server/index.js +65 -57
  19. package/dist/cjs/server/staticMiddleware.js +84 -84
  20. package/dist/cjs/ssr-runtime/SSRLiveReload.js +40 -34
  21. package/dist/cjs/ssr-runtime/devPlugin.js +63 -67
  22. package/dist/cjs/ssr-runtime/injectDataFetchFunctionPlugin.js +44 -36
  23. package/dist/cjs/types/index.js +17 -15
  24. package/dist/esm/cli/configPlugin.mjs +320 -0
  25. package/dist/esm/cli/index.mjs +83 -0
  26. package/dist/esm/cli/mfRuntimePlugins/inject-node-fetch.mjs +12 -0
  27. package/dist/esm/cli/mfRuntimePlugins/resolve-entry-ipv4.mjs +58 -0
  28. package/dist/esm/cli/mfRuntimePlugins/shared-strategy.mjs +21 -0
  29. package/dist/esm/cli/server/data-fetch-server-plugin.mjs +17 -0
  30. package/dist/esm/cli/ssrPlugin.mjs +254 -0
  31. package/dist/esm/cli/utils.mjs +40 -0
  32. package/dist/esm/constant.mjs +3 -0
  33. package/dist/esm/logger.mjs +5 -0
  34. package/dist/esm/react/plugin.mjs +3 -0
  35. package/dist/esm/server/fileCache.mjs +90 -0
  36. package/dist/esm/server/index.mjs +36 -0
  37. package/dist/esm/server/staticMiddleware.mjs +87 -0
  38. package/dist/esm/ssr-runtime/SSRLiveReload.mjs +22 -0
  39. package/dist/esm/ssr-runtime/devPlugin.mjs +70 -0
  40. package/dist/esm/ssr-runtime/injectDataFetchFunctionPlugin.mjs +34 -0
  41. package/dist/esm-node/cli/configPlugin.mjs +283 -0
  42. package/dist/esm-node/cli/index.mjs +67 -0
  43. package/dist/esm-node/cli/mfRuntimePlugins/inject-node-fetch.mjs +10 -0
  44. package/dist/esm-node/cli/mfRuntimePlugins/resolve-entry-ipv4.mjs +46 -0
  45. package/dist/esm-node/cli/mfRuntimePlugins/shared-strategy.mjs +19 -0
  46. package/dist/esm-node/cli/server/data-fetch-server-plugin.mjs +15 -0
  47. package/dist/esm-node/cli/ssrPlugin.mjs +228 -0
  48. package/dist/esm-node/cli/utils.mjs +40 -0
  49. package/dist/esm-node/constant.mjs +3 -0
  50. package/dist/esm-node/logger.mjs +5 -0
  51. package/dist/esm-node/react/plugin.mjs +3 -0
  52. package/dist/esm-node/server/fileCache.mjs +37 -0
  53. package/dist/esm-node/server/index.mjs +34 -0
  54. package/dist/esm-node/server/staticMiddleware.mjs +42 -0
  55. package/dist/esm-node/ssr-runtime/SSRLiveReload.mjs +15 -0
  56. package/dist/esm-node/ssr-runtime/devPlugin.mjs +33 -0
  57. package/dist/esm-node/ssr-runtime/injectDataFetchFunctionPlugin.mjs +14 -0
  58. package/package.json +32 -31
  59. package/dist/cjs/cli/configPlugin.spec.js +0 -112
  60. package/dist/cjs/server/fileCache.spec.js +0 -28
  61. package/dist/cjs/server/staticMiddleware.spec.js +0 -185
  62. package/dist/esm/cli/configPlugin.js +0 -395
  63. package/dist/esm/cli/configPlugin.spec.js +0 -108
  64. package/dist/esm/cli/index.js +0 -92
  65. package/dist/esm/cli/mfRuntimePlugins/inject-node-fetch.js +0 -16
  66. package/dist/esm/cli/mfRuntimePlugins/resolve-entry-ipv4.js +0 -74
  67. package/dist/esm/cli/mfRuntimePlugins/shared-strategy.js +0 -25
  68. package/dist/esm/cli/server/data-fetch-server-plugin.js +0 -20
  69. package/dist/esm/cli/ssrPlugin.js +0 -305
  70. package/dist/esm/cli/utils.js +0 -53
  71. package/dist/esm/constant.js +0 -6
  72. package/dist/esm/logger.js +0 -7
  73. package/dist/esm/react/plugin.js +0 -5
  74. package/dist/esm/server/fileCache.js +0 -98
  75. package/dist/esm/server/fileCache.spec.js +0 -50
  76. package/dist/esm/server/index.js +0 -41
  77. package/dist/esm/server/staticMiddleware.js +0 -104
  78. package/dist/esm/server/staticMiddleware.spec.js +0 -328
  79. package/dist/esm/ssr-runtime/SSRLiveReload.js +0 -26
  80. package/dist/esm/ssr-runtime/devPlugin.js +0 -73
  81. package/dist/esm/ssr-runtime/injectDataFetchFunctionPlugin.js +0 -34
  82. package/dist/esm-node/cli/configPlugin.js +0 -347
  83. package/dist/esm-node/cli/configPlugin.spec.js +0 -89
  84. package/dist/esm-node/cli/index.js +0 -72
  85. package/dist/esm-node/cli/mfRuntimePlugins/inject-node-fetch.js +0 -14
  86. package/dist/esm-node/cli/mfRuntimePlugins/resolve-entry-ipv4.js +0 -62
  87. package/dist/esm-node/cli/mfRuntimePlugins/shared-strategy.js +0 -23
  88. package/dist/esm-node/cli/server/data-fetch-server-plugin.js +0 -18
  89. package/dist/esm-node/cli/ssrPlugin.js +0 -280
  90. package/dist/esm-node/cli/utils.js +0 -53
  91. package/dist/esm-node/constant.js +0 -6
  92. package/dist/esm-node/logger.js +0 -7
  93. package/dist/esm-node/react/plugin.js +0 -5
  94. package/dist/esm-node/server/fileCache.js +0 -49
  95. package/dist/esm-node/server/fileCache.spec.js +0 -27
  96. package/dist/esm-node/server/index.js +0 -39
  97. package/dist/esm-node/server/staticMiddleware.js +0 -55
  98. package/dist/esm-node/server/staticMiddleware.spec.js +0 -162
  99. package/dist/esm-node/ssr-runtime/SSRLiveReload.js +0 -19
  100. package/dist/esm-node/ssr-runtime/devPlugin.js +0 -37
  101. package/dist/esm-node/ssr-runtime/injectDataFetchFunctionPlugin.js +0 -16
  102. /package/dist/esm/interfaces/{bundler.js → bundler.mjs} +0 -0
  103. /package/dist/esm/react/{index.js → index.mjs} +0 -0
  104. /package/dist/esm/react/{v18.js → v18.mjs} +0 -0
  105. /package/dist/esm/react/{v19.js → v19.mjs} +0 -0
  106. /package/dist/esm/runtime/{index.js → index.mjs} +0 -0
  107. /package/dist/esm/types/{index.js → index.mjs} +0 -0
  108. /package/dist/esm-node/interfaces/{bundler.js → bundler.mjs} +0 -0
  109. /package/dist/esm-node/react/{index.js → index.mjs} +0 -0
  110. /package/dist/esm-node/react/{v18.js → v18.mjs} +0 -0
  111. /package/dist/esm-node/react/{v19.js → v19.mjs} +0 -0
  112. /package/dist/esm-node/runtime/{index.js → index.mjs} +0 -0
  113. /package/dist/esm-node/types/{index.js → index.mjs} +0 -0
@@ -0,0 +1,283 @@
1
+ import * as __rspack_external_jiti from "jiti";
2
+ import path from "path";
3
+ import { getIPV4, isDev, isWebTarget, skipByTarget } from "./utils.mjs";
4
+ import { encodeName } from "@module-federation/sdk";
5
+ import { LOCALHOST, PLUGIN_IDENTIFIER } from "../constant.mjs";
6
+ import { addDataFetchExposes, autoDeleteSplitChunkCacheGroups } from "@module-federation/rsbuild-plugin/utils";
7
+ import logger from "../logger.mjs";
8
+ var __webpack_modules__ = {
9
+ jiti (module) {
10
+ module.exports = __rspack_external_jiti;
11
+ }
12
+ };
13
+ var __webpack_module_cache__ = {};
14
+ function __webpack_require__(moduleId) {
15
+ var cachedModule = __webpack_module_cache__[moduleId];
16
+ if (void 0 !== cachedModule) return cachedModule.exports;
17
+ var module = __webpack_module_cache__[moduleId] = {
18
+ exports: {}
19
+ };
20
+ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
21
+ return module.exports;
22
+ }
23
+ const defaultPath = path.resolve(process.cwd(), 'module-federation.config.ts');
24
+ function setEnv(enableSSR) {
25
+ if (enableSSR) process.env['MF_SSR_PRJ'] = 'true';
26
+ }
27
+ const getMFConfig = async (userConfig)=>{
28
+ const { config, configPath } = userConfig;
29
+ if (config) return config;
30
+ const mfConfigPath = configPath ? configPath : defaultPath;
31
+ const { createJiti } = __webpack_require__("jiti");
32
+ const jit = createJiti(__filename, {
33
+ interopDefault: true,
34
+ esmResolve: true
35
+ });
36
+ const configModule = await jit(mfConfigPath);
37
+ const resolvedConfig = configModule && 'object' == typeof configModule && 'default' in configModule ? configModule.default : configModule;
38
+ return resolvedConfig;
39
+ };
40
+ const injectRuntimePlugins = (runtimePlugin, runtimePlugins)=>{
41
+ const pluginName = 'string' == typeof runtimePlugin ? runtimePlugin : runtimePlugin[0];
42
+ const hasPlugin = runtimePlugins.some((existingPlugin)=>{
43
+ if ('string' == typeof existingPlugin) return existingPlugin === pluginName;
44
+ return existingPlugin[0] === pluginName;
45
+ });
46
+ if (!hasPlugin) runtimePlugins.push(runtimePlugin);
47
+ };
48
+ const replaceRemoteUrl = (mfConfig, remoteIpStrategy)=>{
49
+ if (remoteIpStrategy && 'inherit' === remoteIpStrategy) return;
50
+ if (!mfConfig.remotes) return;
51
+ const ipv4 = getIPV4();
52
+ const handleRemoteObject = (remoteObject)=>{
53
+ Object.keys(remoteObject).forEach((remoteKey)=>{
54
+ const remote = remoteObject[remoteKey];
55
+ if (Array.isArray(remote)) return;
56
+ if ('string' == typeof remote && remote.includes(LOCALHOST)) remoteObject[remoteKey] = remote.replace(LOCALHOST, ipv4);
57
+ if ('object' == typeof remote && !Array.isArray(remote.external) && remote.external.includes(LOCALHOST)) remote.external = remote.external.replace(LOCALHOST, ipv4);
58
+ });
59
+ };
60
+ if (Array.isArray(mfConfig.remotes)) mfConfig.remotes.forEach((remoteObject)=>{
61
+ if ('string' == typeof remoteObject) return;
62
+ handleRemoteObject(remoteObject);
63
+ });
64
+ else if ('string' != typeof mfConfig.remotes) handleRemoteObject(mfConfig.remotes);
65
+ };
66
+ const patchDTSConfig = (mfConfig, isServer)=>{
67
+ if (isServer) return;
68
+ const ModernJSRuntime = '@module-federation/modern-js/runtime';
69
+ if (false !== mfConfig.dts) {
70
+ var _mfConfig_dts, _mfConfig_dts1;
71
+ if ('boolean' == typeof mfConfig.dts || void 0 === mfConfig.dts) mfConfig.dts = {
72
+ consumeTypes: {
73
+ runtimePkgs: [
74
+ ModernJSRuntime
75
+ ]
76
+ }
77
+ };
78
+ else if ((null == (_mfConfig_dts = mfConfig.dts) ? void 0 : _mfConfig_dts.consumeTypes) || (null == (_mfConfig_dts1 = mfConfig.dts) ? void 0 : _mfConfig_dts1.consumeTypes) === void 0) {
79
+ var _mfConfig_dts2;
80
+ if ('boolean' == typeof mfConfig.dts.consumeTypes || (null == (_mfConfig_dts2 = mfConfig.dts) ? void 0 : _mfConfig_dts2.consumeTypes) === void 0) mfConfig.dts.consumeTypes = {
81
+ runtimePkgs: [
82
+ ModernJSRuntime
83
+ ]
84
+ };
85
+ else {
86
+ mfConfig.dts.consumeTypes.runtimePkgs = mfConfig.dts.consumeTypes.runtimePkgs || [];
87
+ if (!mfConfig.dts.consumeTypes.runtimePkgs.includes(ModernJSRuntime)) mfConfig.dts.consumeTypes.runtimePkgs.push(ModernJSRuntime);
88
+ }
89
+ }
90
+ }
91
+ };
92
+ const patchMFConfig = (mfConfig, isServer, remoteIpStrategy, enableSSR)=>{
93
+ replaceRemoteUrl(mfConfig, remoteIpStrategy);
94
+ addDataFetchExposes(mfConfig.exposes, isServer);
95
+ if (void 0 === mfConfig.remoteType) mfConfig.remoteType = "script";
96
+ if (!mfConfig.name) throw new Error(`${PLUGIN_IDENTIFIER} mfConfig.name can not be empty!`);
97
+ const runtimePlugins = [
98
+ ...mfConfig.runtimePlugins || []
99
+ ];
100
+ patchDTSConfig(mfConfig, isServer);
101
+ injectRuntimePlugins(require.resolve('@module-federation/modern-js/shared-strategy'), runtimePlugins);
102
+ if (enableSSR && isDev()) injectRuntimePlugins(require.resolve('@module-federation/modern-js/resolve-entry-ipv4'), runtimePlugins);
103
+ if (isServer) {
104
+ injectRuntimePlugins(require.resolve('@module-federation/node/runtimePlugin'), runtimePlugins);
105
+ if (isDev()) injectRuntimePlugins(require.resolve('@module-federation/node/record-dynamic-remote-entry-hash-plugin'), runtimePlugins);
106
+ injectRuntimePlugins(require.resolve('@module-federation/modern-js/inject-node-fetch'), runtimePlugins);
107
+ if (mfConfig.library) {
108
+ if (!mfConfig.library.type) mfConfig.library.type = 'commonjs-module';
109
+ if (!mfConfig.library.name) mfConfig.library.name = mfConfig.name;
110
+ } else mfConfig.library = {
111
+ type: 'commonjs-module',
112
+ name: mfConfig.name
113
+ };
114
+ }
115
+ mfConfig.runtimePlugins = runtimePlugins;
116
+ if (!isServer) {
117
+ var _mfConfig_library;
118
+ if ((null == (_mfConfig_library = mfConfig.library) ? void 0 : _mfConfig_library.type) === 'commonjs-module') mfConfig.library.type = 'global';
119
+ return mfConfig;
120
+ }
121
+ mfConfig.dts = false;
122
+ mfConfig.dev = false;
123
+ return mfConfig;
124
+ };
125
+ function patchIgnoreWarning(chain) {
126
+ const ignoreWarnings = chain.get('ignoreWarnings') || [];
127
+ const ignoredMsgs = [
128
+ "external script",
129
+ 'process.env.WS_NO_BUFFER_UTIL',
130
+ "Can't resolve 'utf-8-validate"
131
+ ];
132
+ ignoreWarnings.push((warning)=>{
133
+ if (ignoredMsgs.some((msg)=>warning.message.includes(msg))) return true;
134
+ return false;
135
+ });
136
+ chain.ignoreWarnings(ignoreWarnings);
137
+ }
138
+ function addMyTypes2Ignored(chain, mfConfig) {
139
+ const watchOptions = chain.get('watchOptions');
140
+ if (!watchOptions || !watchOptions.ignored) return void chain.watchOptions({
141
+ ignored: /[\\/](?:\.git|node_modules|@mf-types)[\\/]/
142
+ });
143
+ const ignored = watchOptions.ignored;
144
+ const DEFAULT_IGNORED_GLOB = '**/@mf-types/**';
145
+ if (Array.isArray(ignored)) {
146
+ if (false !== mfConfig.dts && 'object' == typeof mfConfig.dts && 'object' == typeof mfConfig.dts.consumeTypes && mfConfig.dts.consumeTypes.remoteTypesFolder) chain.watchOptions({
147
+ ...watchOptions,
148
+ ignored: ignored.concat(`**/${mfConfig.dts.consumeTypes.remoteTypesFolder}/**`)
149
+ });
150
+ else chain.watchOptions({
151
+ ...watchOptions,
152
+ ignored: ignored.concat(DEFAULT_IGNORED_GLOB)
153
+ });
154
+ return;
155
+ }
156
+ if ('string' != typeof ignored) return void chain.watchOptions({
157
+ ...watchOptions,
158
+ ignored: /[\\/](?:\.git|node_modules|@mf-types)[\\/]/
159
+ });
160
+ chain.watchOptions({
161
+ ...watchOptions,
162
+ ignored: ignored.concat(DEFAULT_IGNORED_GLOB)
163
+ });
164
+ }
165
+ function patchBundlerConfig(options) {
166
+ var _modernjsConfig_deploy;
167
+ const { chain, modernjsConfig, isServer, mfConfig, enableSSR } = options;
168
+ chain.optimization.delete('runtimeChunk');
169
+ patchIgnoreWarning(chain);
170
+ if (!chain.output.get('chunkLoadingGlobal')) chain.output.chunkLoadingGlobal(`chunk_${mfConfig.name}`);
171
+ if (!chain.output.get('uniqueName')) chain.output.uniqueName(mfConfig.name);
172
+ const splitChunkConfig = chain.optimization.splitChunks.entries();
173
+ if (!isServer) autoDeleteSplitChunkCacheGroups(mfConfig, splitChunkConfig);
174
+ if (!isServer && enableSSR && splitChunkConfig && 'object' == typeof splitChunkConfig && splitChunkConfig.cacheGroups) {
175
+ splitChunkConfig.chunks = 'async';
176
+ logger.warn('splitChunks.chunks = async is not allowed with stream SSR mode, it will auto changed to "async"');
177
+ }
178
+ if (isDev() && 'auto' === chain.output.get('publicPath')) {
179
+ var _modernjsConfig_dev, _modernjsConfig_server;
180
+ const port = (null == (_modernjsConfig_dev = modernjsConfig.dev) ? void 0 : _modernjsConfig_dev.port) || (null == (_modernjsConfig_server = modernjsConfig.server) ? void 0 : _modernjsConfig_server.port) || 8080;
181
+ const publicPath = `http://localhost:${port}/`;
182
+ chain.output.publicPath(publicPath);
183
+ }
184
+ if (isServer && enableSSR) {
185
+ const uniqueName = mfConfig.name || chain.output.get('uniqueName');
186
+ const chunkFileName = chain.output.get('chunkFilename');
187
+ if ('string' == typeof chunkFileName && uniqueName && !chunkFileName.includes(uniqueName)) {
188
+ const suffix = `${encodeName(uniqueName)}-[contenthash].js`;
189
+ chain.output.chunkFilename(chunkFileName.replace('.js', suffix));
190
+ }
191
+ }
192
+ if (isDev() && enableSSR && !isServer) chain.resolve.fallback.set('crypto', false).set('stream', false).set('vm', false);
193
+ if ((null == (_modernjsConfig_deploy = modernjsConfig.deploy) ? void 0 : _modernjsConfig_deploy.microFrontend) && Object.keys(mfConfig.exposes || {}).length) chain.optimization.usedExports(false);
194
+ }
195
+ const moduleFederationConfigPlugin = (userConfig)=>({
196
+ name: '@modern-js/plugin-module-federation-config',
197
+ pre: [
198
+ '@modern-js/plugin-initialize'
199
+ ],
200
+ post: [
201
+ '@modern-js/plugin-module-federation'
202
+ ],
203
+ setup: async (api)=>{
204
+ var _userConfig_userConfig, _modernjsConfig_server;
205
+ const modernjsConfig = api.getConfig();
206
+ const mfConfig = await getMFConfig(userConfig.originPluginOptions);
207
+ const csrConfig = userConfig.csrConfig || JSON.parse(JSON.stringify(mfConfig));
208
+ const ssrConfig = userConfig.ssrConfig || JSON.parse(JSON.stringify(mfConfig));
209
+ userConfig.ssrConfig = ssrConfig;
210
+ userConfig.csrConfig = csrConfig;
211
+ var _ref;
212
+ const enableSSR = Boolean(null != (_ref = null == (_userConfig_userConfig = userConfig.userConfig) ? void 0 : _userConfig_userConfig.ssr) ? _ref : Boolean(null == modernjsConfig ? void 0 : null == (_modernjsConfig_server = modernjsConfig.server) ? void 0 : _modernjsConfig_server.ssr));
213
+ api.modifyBundlerChain((chain)=>{
214
+ const target = chain.get('target');
215
+ if (skipByTarget(target)) return;
216
+ const isWeb = isWebTarget(target);
217
+ addMyTypes2Ignored(chain, isWeb ? csrConfig : ssrConfig);
218
+ const targetMFConfig = isWeb ? csrConfig : ssrConfig;
219
+ patchMFConfig(targetMFConfig, !isWeb, userConfig.remoteIpStrategy || 'ipv4', enableSSR);
220
+ patchBundlerConfig({
221
+ chain,
222
+ isServer: !isWeb,
223
+ modernjsConfig,
224
+ mfConfig,
225
+ enableSSR
226
+ });
227
+ if (isWeb) userConfig.distOutputDir = chain.output.get('path') || path.resolve(process.cwd(), 'dist');
228
+ else if (enableSSR) {
229
+ var _userConfig, _userConfig_userConfig;
230
+ (_userConfig = userConfig).userConfig || (_userConfig.userConfig = {});
231
+ (_userConfig_userConfig = userConfig.userConfig).ssr || (_userConfig_userConfig.ssr = {});
232
+ if (true === userConfig.userConfig.ssr) userConfig.userConfig.ssr = {};
233
+ userConfig.userConfig.ssr.distOutputDir = chain.output.get('path') || path.resolve(process.cwd(), 'dist/bundles');
234
+ }
235
+ });
236
+ api.config(()=>{
237
+ var _modernjsConfig_tools, _userConfig_csrConfig, _modernjsConfig_source, _modernjsConfig_source1, _modernjsConfig_dev;
238
+ const bundlerType = 'rspack' === api.getAppContext().bundlerType ? 'rspack' : 'webpack';
239
+ const ipv4 = getIPV4();
240
+ if (void 0 === userConfig.remoteIpStrategy) if (enableSSR) userConfig.remoteIpStrategy = 'ipv4';
241
+ else userConfig.remoteIpStrategy = 'inherit';
242
+ const devServerConfig = null == (_modernjsConfig_tools = modernjsConfig.tools) ? void 0 : _modernjsConfig_tools.devServer;
243
+ const corsWarnMsgs = [
244
+ 'View https://module-federation.io/guide/troubleshooting/other.html#cors-warn for more details.'
245
+ ];
246
+ if ('object' != typeof devServerConfig || !('headers' in devServerConfig)) corsWarnMsgs.unshift('Detect devServer.headers is empty, mf modern plugin will add default cors header: devServer.headers["Access-Control-Allow-Headers"] = "*". It is recommended to specify an allowlist of trusted origins instead.');
247
+ const exposes = null == (_userConfig_csrConfig = userConfig.csrConfig) ? void 0 : _userConfig_csrConfig.exposes;
248
+ const hasExposes = exposes && Array.isArray(exposes) ? exposes.length : Object.keys(null != exposes ? exposes : {}).length;
249
+ if (corsWarnMsgs.length > 1 && hasExposes) logger.warn(corsWarnMsgs.join('\n'));
250
+ const corsHeaders = hasExposes ? {
251
+ 'Access-Control-Allow-Origin': '*',
252
+ 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS',
253
+ 'Access-Control-Allow-Headers': '*'
254
+ } : void 0;
255
+ const defineConfig = {
256
+ REMOTE_IP_STRATEGY: JSON.stringify(userConfig.remoteIpStrategy)
257
+ };
258
+ if (enableSSR && isDev()) defineConfig['FEDERATION_IPV4'] = JSON.stringify(ipv4);
259
+ var _ref;
260
+ return {
261
+ tools: {
262
+ devServer: {
263
+ headers: corsHeaders
264
+ }
265
+ },
266
+ resolve: {
267
+ alias: {
268
+ '@modern-js/runtime/mf': require.resolve('@module-federation/modern-js/runtime')
269
+ }
270
+ },
271
+ source: {
272
+ define: defineConfig,
273
+ enableAsyncEntry: 'rspack' === bundlerType ? null != (_ref = null == (_modernjsConfig_source = modernjsConfig.source) ? void 0 : _modernjsConfig_source.enableAsyncEntry) ? _ref : true : null == (_modernjsConfig_source1 = modernjsConfig.source) ? void 0 : _modernjsConfig_source1.enableAsyncEntry
274
+ },
275
+ dev: {
276
+ assetPrefix: (null == modernjsConfig ? void 0 : null == (_modernjsConfig_dev = modernjsConfig.dev) ? void 0 : _modernjsConfig_dev.assetPrefix) ? modernjsConfig.dev.assetPrefix : true
277
+ }
278
+ };
279
+ });
280
+ }
281
+ });
282
+ const configPlugin = moduleFederationConfigPlugin;
283
+ export { addMyTypes2Ignored, configPlugin as default, getMFConfig, isWebTarget, moduleFederationConfigPlugin, patchBundlerConfig, patchMFConfig, setEnv, skipByTarget };
@@ -0,0 +1,67 @@
1
+ import { AsyncBoundaryPlugin, ModuleFederationPlugin, createModuleFederationConfig } from "@module-federation/enhanced";
2
+ import { ModuleFederationPlugin as rspack_ModuleFederationPlugin } from "@module-federation/enhanced/rspack";
3
+ import { moduleFederationConfigPlugin } from "./configPlugin.mjs";
4
+ import { moduleFederationSSRPlugin } from "./ssrPlugin.mjs";
5
+ import { isWebTarget } from "./utils.mjs";
6
+ const moduleFederationPlugin = (userConfig = {})=>{
7
+ var _userConfig_fetchServerQuery;
8
+ const internalModernPluginOptions = {
9
+ csrConfig: void 0,
10
+ ssrConfig: void 0,
11
+ browserPlugin: void 0,
12
+ nodePlugin: void 0,
13
+ assetResources: {},
14
+ distOutputDir: '',
15
+ originPluginOptions: {
16
+ ...userConfig
17
+ },
18
+ remoteIpStrategy: null == userConfig ? void 0 : userConfig.remoteIpStrategy,
19
+ userConfig: userConfig || {},
20
+ assetFileNames: {},
21
+ fetchServerQuery: null != (_userConfig_fetchServerQuery = userConfig.fetchServerQuery) ? _userConfig_fetchServerQuery : void 0
22
+ };
23
+ return {
24
+ name: '@modern-js/plugin-module-federation',
25
+ setup: async (api)=>{
26
+ const modernjsConfig = api.getConfig();
27
+ api.modifyBundlerChain((chain)=>{
28
+ const bundlerType = 'rspack' === api.getAppContext().bundlerType ? 'rspack' : 'webpack';
29
+ const browserPluginOptions = internalModernPluginOptions.csrConfig;
30
+ const MFPlugin = 'webpack' === bundlerType ? ModuleFederationPlugin : rspack_ModuleFederationPlugin;
31
+ if (isWebTarget(chain.get('target'))) chain.plugin('plugin-module-federation').use(MFPlugin, [
32
+ browserPluginOptions
33
+ ]).init((Plugin, args)=>{
34
+ internalModernPluginOptions.browserPlugin = new Plugin(args[0]);
35
+ return internalModernPluginOptions.browserPlugin;
36
+ });
37
+ if ('webpack' === bundlerType) {
38
+ var _modernjsConfig_source;
39
+ const enableAsyncEntry = null == (_modernjsConfig_source = modernjsConfig.source) ? void 0 : _modernjsConfig_source.enableAsyncEntry;
40
+ if (!enableAsyncEntry && false !== browserPluginOptions.async) {
41
+ const asyncBoundaryPluginOptions = 'object' == typeof browserPluginOptions.async ? browserPluginOptions.async : {
42
+ eager: (module)=>module && /\.federation/.test((null == module ? void 0 : module.request) || ''),
43
+ excludeChunk: (chunk)=>chunk.name === browserPluginOptions.name
44
+ };
45
+ chain.plugin('async-boundary-plugin').use(AsyncBoundaryPlugin, [
46
+ asyncBoundaryPluginOptions
47
+ ]);
48
+ }
49
+ }
50
+ });
51
+ api._internalServerPlugins(({ plugins })=>{
52
+ plugins.push({
53
+ name: '@module-federation/modern-js/server'
54
+ });
55
+ return {
56
+ plugins
57
+ };
58
+ });
59
+ },
60
+ usePlugins: [
61
+ moduleFederationConfigPlugin(internalModernPluginOptions),
62
+ moduleFederationSSRPlugin(internalModernPluginOptions)
63
+ ]
64
+ };
65
+ };
66
+ const cli = moduleFederationPlugin;
67
+ export { createModuleFederationConfig, cli as default, moduleFederationPlugin };
@@ -0,0 +1,10 @@
1
+ import node_fetch from "node-fetch";
2
+ const injectNodeFetchPlugin = ()=>({
3
+ name: 'inject-node-fetch-plugin',
4
+ beforeInit (args) {
5
+ if (!globalThis.fetch) globalThis.fetch = node_fetch;
6
+ return args;
7
+ }
8
+ });
9
+ const inject_node_fetch = injectNodeFetchPlugin;
10
+ export { inject_node_fetch as default };
@@ -0,0 +1,46 @@
1
+ import { LOCALHOST } from "../../constant.mjs";
2
+ const ipv4 = "u" > typeof FEDERATION_IPV4 ? FEDERATION_IPV4 : '127.0.0.1';
3
+ const remoteIpStrategy = "u" > typeof REMOTE_IP_STRATEGY ? REMOTE_IP_STRATEGY : 'inherit';
4
+ function replaceObjectLocalhost(key, obj) {
5
+ if ('ipv4' !== remoteIpStrategy) return;
6
+ if (!(key in obj)) return;
7
+ const remote = obj[key];
8
+ if (remote && 'string' == typeof remote && remote.includes(LOCALHOST)) obj[key] = replaceLocalhost(remote);
9
+ }
10
+ function replaceLocalhost(url) {
11
+ return url.replace(LOCALHOST, ipv4);
12
+ }
13
+ const resolveEntryIpv4Plugin = ()=>({
14
+ name: 'resolve-entry-ipv4',
15
+ beforeRegisterRemote (args) {
16
+ const { remote } = args;
17
+ replaceObjectLocalhost('entry', remote);
18
+ return args;
19
+ },
20
+ async afterResolve (args) {
21
+ const { remoteInfo } = args;
22
+ replaceObjectLocalhost('entry', remoteInfo);
23
+ return args;
24
+ },
25
+ beforeLoadRemoteSnapshot (args) {
26
+ const { moduleInfo } = args;
27
+ if ('entry' in moduleInfo) {
28
+ replaceObjectLocalhost('entry', moduleInfo);
29
+ return args;
30
+ }
31
+ if ('version' in moduleInfo) replaceObjectLocalhost('version', moduleInfo);
32
+ return args;
33
+ },
34
+ loadRemoteSnapshot (args) {
35
+ const { remoteSnapshot } = args;
36
+ if ('publicPath' in remoteSnapshot) replaceObjectLocalhost('publicPath', remoteSnapshot);
37
+ if ('getPublicPath' in remoteSnapshot) replaceObjectLocalhost('getPublicPath', remoteSnapshot);
38
+ if (remoteSnapshot.remotesInfo) Object.keys(remoteSnapshot.remotesInfo).forEach((key)=>{
39
+ const remoteInfo = remoteSnapshot.remotesInfo[key];
40
+ replaceObjectLocalhost('matchedVersion', remoteInfo);
41
+ });
42
+ return args;
43
+ }
44
+ });
45
+ const resolve_entry_ipv4 = resolveEntryIpv4Plugin;
46
+ export { resolve_entry_ipv4 as default };
@@ -0,0 +1,19 @@
1
+ const sharedStrategy = ()=>({
2
+ name: 'shared-strategy-plugin',
3
+ beforeInit (args) {
4
+ const { userOptions } = args;
5
+ const shared = userOptions.shared;
6
+ if (shared) Object.keys(shared).forEach((sharedKey)=>{
7
+ const sharedConfigs = shared[sharedKey];
8
+ const arraySharedConfigs = Array.isArray(sharedConfigs) ? sharedConfigs : [
9
+ sharedConfigs
10
+ ];
11
+ arraySharedConfigs.forEach((s)=>{
12
+ s.strategy = 'loaded-first';
13
+ });
14
+ });
15
+ return args;
16
+ }
17
+ });
18
+ const shared_strategy = sharedStrategy;
19
+ export { shared_strategy as default };
@@ -0,0 +1,15 @@
1
+ import data_fetch_server_middleware from "@module-federation/bridge-react/data-fetch-server-middleware";
2
+ const dataFetchServePlugin = ()=>({
3
+ name: 'mf-data-fetch-server-plugin',
4
+ setup: (api)=>{
5
+ api.onPrepare(()=>{
6
+ const { middlewares } = api.getServerContext();
7
+ middlewares.push({
8
+ name: 'module-federation-serve-manifest',
9
+ handler: data_fetch_server_middleware
10
+ });
11
+ });
12
+ }
13
+ });
14
+ const data_fetch_server_plugin = dataFetchServePlugin;
15
+ export { data_fetch_server_plugin as default };