@module-federation/modern-js 0.0.0-next-20250926024003 → 0.0.0-perf-devtools-20260107043700

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