@module-federation/modern-js 0.0.0-docs-remove-invalid-lark-link-20251205062649

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 (100) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +5 -0
  3. package/dist/LICENSE +21 -0
  4. package/dist/cjs/cli/configPlugin.js +325 -0
  5. package/dist/cjs/cli/index.js +105 -0
  6. package/dist/cjs/cli/mfRuntimePlugins/inject-node-fetch.js +54 -0
  7. package/dist/cjs/cli/mfRuntimePlugins/resolve-entry-ipv4.js +80 -0
  8. package/dist/cjs/cli/mfRuntimePlugins/shared-strategy.js +53 -0
  9. package/dist/cjs/cli/server/data-fetch-server-plugin.js +59 -0
  10. package/dist/cjs/cli/ssrPlugin.js +287 -0
  11. package/dist/cjs/cli/utils.js +93 -0
  12. package/dist/cjs/constant.js +40 -0
  13. package/dist/cjs/interfaces/bundler.js +18 -0
  14. package/dist/cjs/logger.js +39 -0
  15. package/dist/cjs/react/index.js +60 -0
  16. package/dist/cjs/react/plugin.js +67 -0
  17. package/dist/cjs/react/v18.js +60 -0
  18. package/dist/cjs/react/v19.js +60 -0
  19. package/dist/cjs/runtime/index.js +60 -0
  20. package/dist/cjs/server/fileCache.js +84 -0
  21. package/dist/cjs/server/index.js +71 -0
  22. package/dist/cjs/server/staticMiddleware.js +90 -0
  23. package/dist/cjs/ssr-runtime/SSRLiveReload.js +48 -0
  24. package/dist/cjs/ssr-runtime/devPlugin.js +59 -0
  25. package/dist/cjs/ssr-runtime/injectDataFetchFunctionPlugin.js +48 -0
  26. package/dist/cjs/types/index.js +18 -0
  27. package/dist/esm/cli/configPlugin.mjs +298 -0
  28. package/dist/esm/cli/index.mjs +82 -0
  29. package/dist/esm/cli/mfRuntimePlugins/inject-node-fetch.mjs +12 -0
  30. package/dist/esm/cli/mfRuntimePlugins/resolve-entry-ipv4.mjs +58 -0
  31. package/dist/esm/cli/mfRuntimePlugins/shared-strategy.mjs +21 -0
  32. package/dist/esm/cli/server/data-fetch-server-plugin.mjs +17 -0
  33. package/dist/esm/cli/ssrPlugin.mjs +257 -0
  34. package/dist/esm/cli/utils.mjs +40 -0
  35. package/dist/esm/constant.mjs +3 -0
  36. package/dist/esm/interfaces/bundler.mjs +0 -0
  37. package/dist/esm/logger.mjs +5 -0
  38. package/dist/esm/react/index.mjs +1 -0
  39. package/dist/esm/react/plugin.mjs +3 -0
  40. package/dist/esm/react/v18.mjs +1 -0
  41. package/dist/esm/react/v19.mjs +1 -0
  42. package/dist/esm/runtime/index.mjs +1 -0
  43. package/dist/esm/server/fileCache.mjs +90 -0
  44. package/dist/esm/server/index.mjs +36 -0
  45. package/dist/esm/server/staticMiddleware.mjs +87 -0
  46. package/dist/esm/ssr-runtime/SSRLiveReload.mjs +21 -0
  47. package/dist/esm/ssr-runtime/devPlugin.mjs +63 -0
  48. package/dist/esm/ssr-runtime/injectDataFetchFunctionPlugin.mjs +34 -0
  49. package/dist/esm/types/index.mjs +0 -0
  50. package/dist/esm-node/cli/configPlugin.mjs +256 -0
  51. package/dist/esm-node/cli/index.mjs +65 -0
  52. package/dist/esm-node/cli/mfRuntimePlugins/inject-node-fetch.mjs +10 -0
  53. package/dist/esm-node/cli/mfRuntimePlugins/resolve-entry-ipv4.mjs +46 -0
  54. package/dist/esm-node/cli/mfRuntimePlugins/shared-strategy.mjs +19 -0
  55. package/dist/esm-node/cli/server/data-fetch-server-plugin.mjs +15 -0
  56. package/dist/esm-node/cli/ssrPlugin.mjs +231 -0
  57. package/dist/esm-node/cli/utils.mjs +40 -0
  58. package/dist/esm-node/constant.mjs +3 -0
  59. package/dist/esm-node/interfaces/bundler.mjs +0 -0
  60. package/dist/esm-node/logger.mjs +5 -0
  61. package/dist/esm-node/react/index.mjs +1 -0
  62. package/dist/esm-node/react/plugin.mjs +3 -0
  63. package/dist/esm-node/react/v18.mjs +1 -0
  64. package/dist/esm-node/react/v19.mjs +1 -0
  65. package/dist/esm-node/runtime/index.mjs +1 -0
  66. package/dist/esm-node/server/fileCache.mjs +37 -0
  67. package/dist/esm-node/server/index.mjs +34 -0
  68. package/dist/esm-node/server/staticMiddleware.mjs +42 -0
  69. package/dist/esm-node/ssr-runtime/SSRLiveReload.mjs +14 -0
  70. package/dist/esm-node/ssr-runtime/devPlugin.mjs +25 -0
  71. package/dist/esm-node/ssr-runtime/injectDataFetchFunctionPlugin.mjs +14 -0
  72. package/dist/esm-node/types/index.mjs +0 -0
  73. package/dist/types/cli/configPlugin.d.ts +21 -0
  74. package/dist/types/cli/configPlugin.spec.d.ts +1 -0
  75. package/dist/types/cli/index.d.ts +6 -0
  76. package/dist/types/cli/mfRuntimePlugins/inject-node-fetch.d.ts +3 -0
  77. package/dist/types/cli/mfRuntimePlugins/resolve-entry-ipv4.d.ts +3 -0
  78. package/dist/types/cli/mfRuntimePlugins/shared-strategy.d.ts +3 -0
  79. package/dist/types/cli/server/data-fetch-server-plugin.d.ts +3 -0
  80. package/dist/types/cli/ssrPlugin.d.ts +6 -0
  81. package/dist/types/cli/utils.d.ts +6 -0
  82. package/dist/types/constant.d.ts +2 -0
  83. package/dist/types/interfaces/bundler.d.ts +18 -0
  84. package/dist/types/logger.d.ts +2 -0
  85. package/dist/types/react/index.d.ts +1 -0
  86. package/dist/types/react/plugin.d.ts +2 -0
  87. package/dist/types/react/v18.d.ts +1 -0
  88. package/dist/types/react/v19.d.ts +1 -0
  89. package/dist/types/runtime/index.d.ts +1 -0
  90. package/dist/types/server/fileCache.d.ts +14 -0
  91. package/dist/types/server/fileCache.spec.d.ts +1 -0
  92. package/dist/types/server/index.d.ts +4 -0
  93. package/dist/types/server/staticMiddleware.d.ts +7 -0
  94. package/dist/types/server/staticMiddleware.spec.d.ts +1 -0
  95. package/dist/types/ssr-runtime/SSRLiveReload.d.ts +1 -0
  96. package/dist/types/ssr-runtime/devPlugin.d.ts +2 -0
  97. package/dist/types/ssr-runtime/injectDataFetchFunctionPlugin.d.ts +4 -0
  98. package/dist/types/types/index.d.ts +35 -0
  99. package/package.json +189 -0
  100. package/types.d.ts +6 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024-present zhanghang(2heal1)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # @module-federation/modern-js
2
+
3
+ This plugin provides Module Federation supporting functions for Modern.js
4
+
5
+ See [documentation](https://module-federation.io/guide/framework/modernjs.html) for more details .
package/dist/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024-present zhanghang(2heal1)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,325 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.n = (module)=>{
5
+ var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
6
+ __webpack_require__.d(getter, {
7
+ a: getter
8
+ });
9
+ return getter;
10
+ };
11
+ })();
12
+ (()=>{
13
+ __webpack_require__.d = (exports1, definition)=>{
14
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
15
+ enumerable: true,
16
+ get: definition[key]
17
+ });
18
+ };
19
+ })();
20
+ (()=>{
21
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
22
+ })();
23
+ (()=>{
24
+ __webpack_require__.r = (exports1)=>{
25
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
26
+ value: 'Module'
27
+ });
28
+ Object.defineProperty(exports1, '__esModule', {
29
+ value: true
30
+ });
31
+ };
32
+ })();
33
+ var __webpack_exports__ = {};
34
+ __webpack_require__.r(__webpack_exports__);
35
+ __webpack_require__.d(__webpack_exports__, {
36
+ patchMFConfig: ()=>patchMFConfig,
37
+ default: ()=>configPlugin,
38
+ getMFConfig: ()=>getMFConfig,
39
+ isWebTarget: ()=>external_utils_js_namespaceObject.isWebTarget,
40
+ moduleFederationConfigPlugin: ()=>moduleFederationConfigPlugin,
41
+ addMyTypes2Ignored: ()=>addMyTypes2Ignored,
42
+ skipByTarget: ()=>external_utils_js_namespaceObject.skipByTarget,
43
+ setEnv: ()=>setEnv,
44
+ patchBundlerConfig: ()=>patchBundlerConfig
45
+ });
46
+ const external_path_namespaceObject = require("path");
47
+ var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
48
+ const external_utils_js_namespaceObject = require("./utils.js");
49
+ const sdk_namespaceObject = require("@module-federation/sdk");
50
+ const node_bundle_require_namespaceObject = require("@modern-js/node-bundle-require");
51
+ const external_constant_js_namespaceObject = require("../constant.js");
52
+ const utils_namespaceObject = require("@module-federation/rsbuild-plugin/utils");
53
+ const external_logger_js_namespaceObject = require("../logger.js");
54
+ var external_logger_js_default = /*#__PURE__*/ __webpack_require__.n(external_logger_js_namespaceObject);
55
+ const defaultPath = external_path_default().resolve(process.cwd(), 'module-federation.config.ts');
56
+ function setEnv(enableSSR) {
57
+ if (enableSSR) process.env['MF_SSR_PRJ'] = 'true';
58
+ }
59
+ const getMFConfig = async (userConfig)=>{
60
+ const { config, configPath } = userConfig;
61
+ if (config) return config;
62
+ const mfConfigPath = configPath ? configPath : defaultPath;
63
+ const preBundlePath = await (0, node_bundle_require_namespaceObject.bundle)(mfConfigPath);
64
+ const mfConfig = (await import(preBundlePath)).default;
65
+ return mfConfig;
66
+ };
67
+ const injectRuntimePlugins = (runtimePlugin, runtimePlugins)=>{
68
+ const pluginName = 'string' == typeof runtimePlugin ? runtimePlugin : runtimePlugin[0];
69
+ const hasPlugin = runtimePlugins.some((existingPlugin)=>{
70
+ if ('string' == typeof existingPlugin) return existingPlugin === pluginName;
71
+ return existingPlugin[0] === pluginName;
72
+ });
73
+ if (!hasPlugin) runtimePlugins.push(runtimePlugin);
74
+ };
75
+ const replaceRemoteUrl = (mfConfig, remoteIpStrategy)=>{
76
+ if (remoteIpStrategy && 'inherit' === remoteIpStrategy) return;
77
+ if (!mfConfig.remotes) return;
78
+ const ipv4 = (0, external_utils_js_namespaceObject.getIPV4)();
79
+ const handleRemoteObject = (remoteObject)=>{
80
+ Object.keys(remoteObject).forEach((remoteKey)=>{
81
+ const remote = remoteObject[remoteKey];
82
+ if (Array.isArray(remote)) return;
83
+ if ('string' == typeof remote && remote.includes(external_constant_js_namespaceObject.LOCALHOST)) remoteObject[remoteKey] = remote.replace(external_constant_js_namespaceObject.LOCALHOST, ipv4);
84
+ if ('object' == typeof remote && !Array.isArray(remote.external) && remote.external.includes(external_constant_js_namespaceObject.LOCALHOST)) remote.external = remote.external.replace(external_constant_js_namespaceObject.LOCALHOST, ipv4);
85
+ });
86
+ };
87
+ if (Array.isArray(mfConfig.remotes)) mfConfig.remotes.forEach((remoteObject)=>{
88
+ if ('string' == typeof remoteObject) return;
89
+ handleRemoteObject(remoteObject);
90
+ });
91
+ else if ('string' != typeof mfConfig.remotes) handleRemoteObject(mfConfig.remotes);
92
+ };
93
+ const patchDTSConfig = (mfConfig, isServer)=>{
94
+ if (isServer) return;
95
+ const ModernJSRuntime = '@module-federation/modern-js/runtime';
96
+ if (false !== mfConfig.dts) {
97
+ var _mfConfig_dts, _mfConfig_dts1;
98
+ if ('boolean' == typeof mfConfig.dts || void 0 === mfConfig.dts) mfConfig.dts = {
99
+ consumeTypes: {
100
+ runtimePkgs: [
101
+ ModernJSRuntime
102
+ ]
103
+ }
104
+ };
105
+ else if ((null == (_mfConfig_dts = mfConfig.dts) ? void 0 : _mfConfig_dts.consumeTypes) || (null == (_mfConfig_dts1 = mfConfig.dts) ? void 0 : _mfConfig_dts1.consumeTypes) === void 0) {
106
+ var _mfConfig_dts2;
107
+ if ('boolean' == typeof mfConfig.dts.consumeTypes || (null == (_mfConfig_dts2 = mfConfig.dts) ? void 0 : _mfConfig_dts2.consumeTypes) === void 0) mfConfig.dts.consumeTypes = {
108
+ runtimePkgs: [
109
+ ModernJSRuntime
110
+ ]
111
+ };
112
+ else {
113
+ mfConfig.dts.consumeTypes.runtimePkgs = mfConfig.dts.consumeTypes.runtimePkgs || [];
114
+ if (!mfConfig.dts.consumeTypes.runtimePkgs.includes(ModernJSRuntime)) mfConfig.dts.consumeTypes.runtimePkgs.push(ModernJSRuntime);
115
+ }
116
+ }
117
+ }
118
+ };
119
+ const patchMFConfig = (mfConfig, isServer, remoteIpStrategy, enableSSR)=>{
120
+ replaceRemoteUrl(mfConfig, remoteIpStrategy);
121
+ (0, utils_namespaceObject.addDataFetchExposes)(mfConfig.exposes, isServer);
122
+ if (void 0 === mfConfig.remoteType) mfConfig.remoteType = "script";
123
+ if (!mfConfig.name) throw new Error(`${external_constant_js_namespaceObject.PLUGIN_IDENTIFIER} mfConfig.name can not be empty!`);
124
+ const runtimePlugins = [
125
+ ...mfConfig.runtimePlugins || []
126
+ ];
127
+ patchDTSConfig(mfConfig, isServer);
128
+ injectRuntimePlugins(require.resolve('@module-federation/modern-js/shared-strategy'), runtimePlugins);
129
+ if (enableSSR && (0, external_utils_js_namespaceObject.isDev)()) injectRuntimePlugins(require.resolve('@module-federation/modern-js/resolve-entry-ipv4'), runtimePlugins);
130
+ if (isServer) {
131
+ injectRuntimePlugins(require.resolve('@module-federation/node/runtimePlugin'), runtimePlugins);
132
+ if ((0, external_utils_js_namespaceObject.isDev)()) injectRuntimePlugins(require.resolve('@module-federation/node/record-dynamic-remote-entry-hash-plugin'), runtimePlugins);
133
+ injectRuntimePlugins(require.resolve('@module-federation/modern-js/inject-node-fetch'), runtimePlugins);
134
+ if (mfConfig.library) {
135
+ if (!mfConfig.library.type) mfConfig.library.type = 'commonjs-module';
136
+ if (!mfConfig.library.name) mfConfig.library.name = mfConfig.name;
137
+ } else mfConfig.library = {
138
+ type: 'commonjs-module',
139
+ name: mfConfig.name
140
+ };
141
+ }
142
+ mfConfig.runtimePlugins = runtimePlugins;
143
+ if (!isServer) {
144
+ var _mfConfig_library;
145
+ if ((null == (_mfConfig_library = mfConfig.library) ? void 0 : _mfConfig_library.type) === 'commonjs-module') mfConfig.library.type = 'global';
146
+ return mfConfig;
147
+ }
148
+ mfConfig.dts = false;
149
+ mfConfig.dev = false;
150
+ return mfConfig;
151
+ };
152
+ function patchIgnoreWarning(chain) {
153
+ const ignoreWarnings = chain.get('ignoreWarnings') || [];
154
+ const ignoredMsgs = [
155
+ "external script",
156
+ 'process.env.WS_NO_BUFFER_UTIL',
157
+ "Can't resolve 'utf-8-validate"
158
+ ];
159
+ ignoreWarnings.push((warning)=>{
160
+ if (ignoredMsgs.some((msg)=>warning.message.includes(msg))) return true;
161
+ return false;
162
+ });
163
+ chain.ignoreWarnings(ignoreWarnings);
164
+ }
165
+ function addMyTypes2Ignored(chain, mfConfig) {
166
+ const watchOptions = chain.get('watchOptions');
167
+ if (!watchOptions || !watchOptions.ignored) return void chain.watchOptions({
168
+ ignored: /[\\/](?:\.git|node_modules|@mf-types)[\\/]/
169
+ });
170
+ const ignored = watchOptions.ignored;
171
+ const DEFAULT_IGNORED_GLOB = '**/@mf-types/**';
172
+ if (Array.isArray(ignored)) {
173
+ if (false !== mfConfig.dts && 'object' == typeof mfConfig.dts && 'object' == typeof mfConfig.dts.consumeTypes && mfConfig.dts.consumeTypes.remoteTypesFolder) chain.watchOptions({
174
+ ...watchOptions,
175
+ ignored: ignored.concat(`**/${mfConfig.dts.consumeTypes.remoteTypesFolder}/**`)
176
+ });
177
+ else chain.watchOptions({
178
+ ...watchOptions,
179
+ ignored: ignored.concat(DEFAULT_IGNORED_GLOB)
180
+ });
181
+ return;
182
+ }
183
+ if ('string' != typeof ignored) return void chain.watchOptions({
184
+ ...watchOptions,
185
+ ignored: /[\\/](?:\.git|node_modules|@mf-types)[\\/]/
186
+ });
187
+ chain.watchOptions({
188
+ ...watchOptions,
189
+ ignored: ignored.concat(DEFAULT_IGNORED_GLOB)
190
+ });
191
+ }
192
+ function patchBundlerConfig(options) {
193
+ var _modernjsConfig_deploy;
194
+ const { chain, modernjsConfig, isServer, mfConfig, enableSSR } = options;
195
+ chain.optimization.delete('runtimeChunk');
196
+ patchIgnoreWarning(chain);
197
+ if (!chain.output.get('chunkLoadingGlobal')) chain.output.chunkLoadingGlobal(`chunk_${mfConfig.name}`);
198
+ if (!chain.output.get('uniqueName')) chain.output.uniqueName(mfConfig.name);
199
+ const splitChunkConfig = chain.optimization.splitChunks.entries();
200
+ if (!isServer) (0, utils_namespaceObject.autoDeleteSplitChunkCacheGroups)(mfConfig, splitChunkConfig);
201
+ if (!isServer && enableSSR && splitChunkConfig && 'object' == typeof splitChunkConfig && splitChunkConfig.cacheGroups) {
202
+ splitChunkConfig.chunks = 'async';
203
+ external_logger_js_default().warn('splitChunks.chunks = async is not allowed with stream SSR mode, it will auto changed to "async"');
204
+ }
205
+ if ((0, external_utils_js_namespaceObject.isDev)() && 'auto' === chain.output.get('publicPath')) {
206
+ var _modernjsConfig_dev, _modernjsConfig_server;
207
+ const port = (null == (_modernjsConfig_dev = modernjsConfig.dev) ? void 0 : _modernjsConfig_dev.port) || (null == (_modernjsConfig_server = modernjsConfig.server) ? void 0 : _modernjsConfig_server.port) || 8080;
208
+ const publicPath = `http://localhost:${port}/`;
209
+ chain.output.publicPath(publicPath);
210
+ }
211
+ if (isServer && enableSSR) {
212
+ const uniqueName = mfConfig.name || chain.output.get('uniqueName');
213
+ const chunkFileName = chain.output.get('chunkFilename');
214
+ if ('string' == typeof chunkFileName && uniqueName && !chunkFileName.includes(uniqueName)) {
215
+ const suffix = `${(0, sdk_namespaceObject.encodeName)(uniqueName)}-[contenthash].js`;
216
+ chain.output.chunkFilename(chunkFileName.replace('.js', suffix));
217
+ }
218
+ }
219
+ if ((0, external_utils_js_namespaceObject.isDev)() && enableSSR && !isServer) chain.resolve.fallback.set('crypto', false).set('stream', false).set('vm', false);
220
+ if ((null == (_modernjsConfig_deploy = modernjsConfig.deploy) ? void 0 : _modernjsConfig_deploy.microFrontend) && Object.keys(mfConfig.exposes || {}).length) chain.optimization.usedExports(false);
221
+ }
222
+ const moduleFederationConfigPlugin = (userConfig)=>({
223
+ name: '@modern-js/plugin-module-federation-config',
224
+ pre: [
225
+ '@modern-js/plugin-initialize'
226
+ ],
227
+ post: [
228
+ '@modern-js/plugin-module-federation'
229
+ ],
230
+ setup: async (api)=>{
231
+ var _userConfig_userConfig, _modernjsConfig_server;
232
+ const modernjsConfig = api.getConfig();
233
+ const mfConfig = await getMFConfig(userConfig.originPluginOptions);
234
+ const csrConfig = userConfig.csrConfig || JSON.parse(JSON.stringify(mfConfig));
235
+ const ssrConfig = userConfig.ssrConfig || JSON.parse(JSON.stringify(mfConfig));
236
+ userConfig.ssrConfig = ssrConfig;
237
+ userConfig.csrConfig = csrConfig;
238
+ var _userConfig_userConfig_ssr;
239
+ const enableSSR = Boolean(null != (_userConfig_userConfig_ssr = null == (_userConfig_userConfig = userConfig.userConfig) ? void 0 : _userConfig_userConfig.ssr) ? _userConfig_userConfig_ssr : Boolean(null == modernjsConfig ? void 0 : null == (_modernjsConfig_server = modernjsConfig.server) ? void 0 : _modernjsConfig_server.ssr));
240
+ api.modifyBundlerChain((chain)=>{
241
+ const target = chain.get('target');
242
+ if ((0, external_utils_js_namespaceObject.skipByTarget)(target)) return;
243
+ const isWeb = (0, external_utils_js_namespaceObject.isWebTarget)(target);
244
+ addMyTypes2Ignored(chain, isWeb ? csrConfig : ssrConfig);
245
+ const targetMFConfig = isWeb ? csrConfig : ssrConfig;
246
+ patchMFConfig(targetMFConfig, !isWeb, userConfig.remoteIpStrategy || 'ipv4', enableSSR);
247
+ patchBundlerConfig({
248
+ chain,
249
+ isServer: !isWeb,
250
+ modernjsConfig,
251
+ mfConfig,
252
+ enableSSR
253
+ });
254
+ userConfig.distOutputDir = chain.output.get('path') || external_path_default().resolve(process.cwd(), 'dist');
255
+ });
256
+ api.config(()=>{
257
+ var _modernjsConfig_tools, _userConfig_csrConfig, _modernjsConfig_source, _modernjsConfig_source1, _modernjsConfig_dev;
258
+ const bundlerType = 'rspack' === api.getAppContext().bundlerType ? 'rspack' : 'webpack';
259
+ const ipv4 = (0, external_utils_js_namespaceObject.getIPV4)();
260
+ if (void 0 === userConfig.remoteIpStrategy) if (enableSSR) userConfig.remoteIpStrategy = 'ipv4';
261
+ else userConfig.remoteIpStrategy = 'inherit';
262
+ const devServerConfig = null == (_modernjsConfig_tools = modernjsConfig.tools) ? void 0 : _modernjsConfig_tools.devServer;
263
+ const corsWarnMsgs = [
264
+ 'View https://module-federation.io/guide/troubleshooting/other.html#cors-warn for more details.'
265
+ ];
266
+ 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.');
267
+ const exposes = null == (_userConfig_csrConfig = userConfig.csrConfig) ? void 0 : _userConfig_csrConfig.exposes;
268
+ const hasExposes = exposes && Array.isArray(exposes) ? exposes.length : Object.keys(null != exposes ? exposes : {}).length;
269
+ if (corsWarnMsgs.length > 1 && hasExposes) external_logger_js_default().warn(corsWarnMsgs.join('\n'));
270
+ const corsHeaders = hasExposes ? {
271
+ 'Access-Control-Allow-Origin': '*',
272
+ 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS',
273
+ 'Access-Control-Allow-Headers': '*'
274
+ } : void 0;
275
+ const defineConfig = {
276
+ REMOTE_IP_STRATEGY: JSON.stringify(userConfig.remoteIpStrategy)
277
+ };
278
+ if (enableSSR && (0, external_utils_js_namespaceObject.isDev)()) defineConfig['FEDERATION_IPV4'] = JSON.stringify(ipv4);
279
+ var _modernjsConfig_source_enableAsyncEntry;
280
+ return {
281
+ tools: {
282
+ devServer: {
283
+ headers: corsHeaders
284
+ }
285
+ },
286
+ resolve: {
287
+ alias: {
288
+ '@modern-js/runtime/mf': require.resolve('@module-federation/modern-js/runtime')
289
+ }
290
+ },
291
+ source: {
292
+ define: defineConfig,
293
+ enableAsyncEntry: 'rspack' === bundlerType ? null != (_modernjsConfig_source_enableAsyncEntry = null == (_modernjsConfig_source = modernjsConfig.source) ? void 0 : _modernjsConfig_source.enableAsyncEntry) ? _modernjsConfig_source_enableAsyncEntry : true : null == (_modernjsConfig_source1 = modernjsConfig.source) ? void 0 : _modernjsConfig_source1.enableAsyncEntry
294
+ },
295
+ dev: {
296
+ assetPrefix: (null == modernjsConfig ? void 0 : null == (_modernjsConfig_dev = modernjsConfig.dev) ? void 0 : _modernjsConfig_dev.assetPrefix) ? modernjsConfig.dev.assetPrefix : true
297
+ }
298
+ };
299
+ });
300
+ }
301
+ });
302
+ const configPlugin = moduleFederationConfigPlugin;
303
+ exports.addMyTypes2Ignored = __webpack_exports__.addMyTypes2Ignored;
304
+ exports["default"] = __webpack_exports__["default"];
305
+ exports.getMFConfig = __webpack_exports__.getMFConfig;
306
+ exports.isWebTarget = __webpack_exports__.isWebTarget;
307
+ exports.moduleFederationConfigPlugin = __webpack_exports__.moduleFederationConfigPlugin;
308
+ exports.patchBundlerConfig = __webpack_exports__.patchBundlerConfig;
309
+ exports.patchMFConfig = __webpack_exports__.patchMFConfig;
310
+ exports.setEnv = __webpack_exports__.setEnv;
311
+ exports.skipByTarget = __webpack_exports__.skipByTarget;
312
+ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
313
+ "addMyTypes2Ignored",
314
+ "default",
315
+ "getMFConfig",
316
+ "isWebTarget",
317
+ "moduleFederationConfigPlugin",
318
+ "patchBundlerConfig",
319
+ "patchMFConfig",
320
+ "setEnv",
321
+ "skipByTarget"
322
+ ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
323
+ Object.defineProperty(exports, '__esModule', {
324
+ value: true
325
+ });
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, definition)=>{
5
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
+ enumerable: true,
7
+ get: definition[key]
8
+ });
9
+ };
10
+ })();
11
+ (()=>{
12
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
+ })();
14
+ (()=>{
15
+ __webpack_require__.r = (exports1)=>{
16
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
+ value: 'Module'
18
+ });
19
+ Object.defineProperty(exports1, '__esModule', {
20
+ value: true
21
+ });
22
+ };
23
+ })();
24
+ var __webpack_exports__ = {};
25
+ __webpack_require__.r(__webpack_exports__);
26
+ __webpack_require__.d(__webpack_exports__, {
27
+ moduleFederationPlugin: ()=>moduleFederationPlugin,
28
+ createModuleFederationConfig: ()=>enhanced_namespaceObject.createModuleFederationConfig,
29
+ default: ()=>cli
30
+ });
31
+ const enhanced_namespaceObject = require("@module-federation/enhanced");
32
+ const rspack_namespaceObject = require("@module-federation/enhanced/rspack");
33
+ const external_configPlugin_js_namespaceObject = require("./configPlugin.js");
34
+ const external_ssrPlugin_js_namespaceObject = require("./ssrPlugin.js");
35
+ const external_utils_js_namespaceObject = require("./utils.js");
36
+ const moduleFederationPlugin = (userConfig = {})=>{
37
+ var _userConfig_fetchServerQuery;
38
+ const internalModernPluginOptions = {
39
+ csrConfig: void 0,
40
+ ssrConfig: void 0,
41
+ browserPlugin: void 0,
42
+ nodePlugin: void 0,
43
+ assetResources: {},
44
+ distOutputDir: '',
45
+ originPluginOptions: userConfig,
46
+ remoteIpStrategy: null == userConfig ? void 0 : userConfig.remoteIpStrategy,
47
+ userConfig: userConfig || {},
48
+ assetFileNames: {},
49
+ fetchServerQuery: null != (_userConfig_fetchServerQuery = userConfig.fetchServerQuery) ? _userConfig_fetchServerQuery : void 0
50
+ };
51
+ return {
52
+ name: '@modern-js/plugin-module-federation',
53
+ setup: async (api)=>{
54
+ const modernjsConfig = api.getConfig();
55
+ api.modifyBundlerChain((chain)=>{
56
+ const bundlerType = 'rspack' === api.getAppContext().bundlerType ? 'rspack' : 'webpack';
57
+ const browserPluginOptions = internalModernPluginOptions.csrConfig;
58
+ const MFPlugin = 'webpack' === bundlerType ? enhanced_namespaceObject.ModuleFederationPlugin : rspack_namespaceObject.ModuleFederationPlugin;
59
+ if ((0, external_utils_js_namespaceObject.isWebTarget)(chain.get('target'))) chain.plugin('plugin-module-federation').use(MFPlugin, [
60
+ browserPluginOptions
61
+ ]).init((Plugin, args)=>{
62
+ internalModernPluginOptions.browserPlugin = new Plugin(args[0]);
63
+ return internalModernPluginOptions.browserPlugin;
64
+ });
65
+ if ('webpack' === bundlerType) {
66
+ var _modernjsConfig_source;
67
+ const enableAsyncEntry = null == (_modernjsConfig_source = modernjsConfig.source) ? void 0 : _modernjsConfig_source.enableAsyncEntry;
68
+ if (!enableAsyncEntry && false !== browserPluginOptions.async) {
69
+ const asyncBoundaryPluginOptions = 'object' == typeof browserPluginOptions.async ? browserPluginOptions.async : {
70
+ eager: (module)=>module && /\.federation/.test((null == module ? void 0 : module.request) || ''),
71
+ excludeChunk: (chunk)=>chunk.name === browserPluginOptions.name
72
+ };
73
+ chain.plugin('async-boundary-plugin').use(enhanced_namespaceObject.AsyncBoundaryPlugin, [
74
+ asyncBoundaryPluginOptions
75
+ ]);
76
+ }
77
+ }
78
+ });
79
+ api._internalServerPlugins(({ plugins })=>{
80
+ plugins.push({
81
+ name: '@module-federation/modern-js/server'
82
+ });
83
+ return {
84
+ plugins
85
+ };
86
+ });
87
+ },
88
+ usePlugins: [
89
+ (0, external_configPlugin_js_namespaceObject.moduleFederationConfigPlugin)(internalModernPluginOptions),
90
+ (0, external_ssrPlugin_js_namespaceObject.moduleFederationSSRPlugin)(internalModernPluginOptions)
91
+ ]
92
+ };
93
+ };
94
+ const cli = moduleFederationPlugin;
95
+ exports.createModuleFederationConfig = __webpack_exports__.createModuleFederationConfig;
96
+ exports["default"] = __webpack_exports__["default"];
97
+ exports.moduleFederationPlugin = __webpack_exports__.moduleFederationPlugin;
98
+ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
99
+ "createModuleFederationConfig",
100
+ "default",
101
+ "moduleFederationPlugin"
102
+ ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
103
+ Object.defineProperty(exports, '__esModule', {
104
+ value: true
105
+ });
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.n = (module)=>{
5
+ var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
6
+ __webpack_require__.d(getter, {
7
+ a: getter
8
+ });
9
+ return getter;
10
+ };
11
+ })();
12
+ (()=>{
13
+ __webpack_require__.d = (exports1, definition)=>{
14
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
15
+ enumerable: true,
16
+ get: definition[key]
17
+ });
18
+ };
19
+ })();
20
+ (()=>{
21
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
22
+ })();
23
+ (()=>{
24
+ __webpack_require__.r = (exports1)=>{
25
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
26
+ value: 'Module'
27
+ });
28
+ Object.defineProperty(exports1, '__esModule', {
29
+ value: true
30
+ });
31
+ };
32
+ })();
33
+ var __webpack_exports__ = {};
34
+ __webpack_require__.r(__webpack_exports__);
35
+ __webpack_require__.d(__webpack_exports__, {
36
+ default: ()=>inject_node_fetch
37
+ });
38
+ const external_node_fetch_namespaceObject = require("node-fetch");
39
+ var external_node_fetch_default = /*#__PURE__*/ __webpack_require__.n(external_node_fetch_namespaceObject);
40
+ const injectNodeFetchPlugin = ()=>({
41
+ name: 'inject-node-fetch-plugin',
42
+ beforeInit (args) {
43
+ if (!globalThis.fetch) globalThis.fetch = external_node_fetch_default();
44
+ return args;
45
+ }
46
+ });
47
+ const inject_node_fetch = injectNodeFetchPlugin;
48
+ exports["default"] = __webpack_exports__["default"];
49
+ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
50
+ "default"
51
+ ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
52
+ Object.defineProperty(exports, '__esModule', {
53
+ value: true
54
+ });
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, definition)=>{
5
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
+ enumerable: true,
7
+ get: definition[key]
8
+ });
9
+ };
10
+ })();
11
+ (()=>{
12
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
+ })();
14
+ (()=>{
15
+ __webpack_require__.r = (exports1)=>{
16
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
+ value: 'Module'
18
+ });
19
+ Object.defineProperty(exports1, '__esModule', {
20
+ value: true
21
+ });
22
+ };
23
+ })();
24
+ var __webpack_exports__ = {};
25
+ __webpack_require__.r(__webpack_exports__);
26
+ __webpack_require__.d(__webpack_exports__, {
27
+ default: ()=>resolve_entry_ipv4
28
+ });
29
+ const external_constant_js_namespaceObject = require("../../constant.js");
30
+ const ipv4 = 'undefined' != typeof FEDERATION_IPV4 ? FEDERATION_IPV4 : '127.0.0.1';
31
+ const remoteIpStrategy = 'undefined' != typeof REMOTE_IP_STRATEGY ? REMOTE_IP_STRATEGY : 'inherit';
32
+ function replaceObjectLocalhost(key, obj) {
33
+ if ('ipv4' !== remoteIpStrategy) return;
34
+ if (!(key in obj)) return;
35
+ const remote = obj[key];
36
+ if (remote && 'string' == typeof remote && remote.includes(external_constant_js_namespaceObject.LOCALHOST)) obj[key] = replaceLocalhost(remote);
37
+ }
38
+ function replaceLocalhost(url) {
39
+ return url.replace(external_constant_js_namespaceObject.LOCALHOST, ipv4);
40
+ }
41
+ const resolveEntryIpv4Plugin = ()=>({
42
+ name: 'resolve-entry-ipv4',
43
+ beforeRegisterRemote (args) {
44
+ const { remote } = args;
45
+ replaceObjectLocalhost('entry', remote);
46
+ return args;
47
+ },
48
+ async afterResolve (args) {
49
+ const { remoteInfo } = args;
50
+ replaceObjectLocalhost('entry', remoteInfo);
51
+ return args;
52
+ },
53
+ beforeLoadRemoteSnapshot (args) {
54
+ const { moduleInfo } = args;
55
+ if ('entry' in moduleInfo) {
56
+ replaceObjectLocalhost('entry', moduleInfo);
57
+ return args;
58
+ }
59
+ if ('version' in moduleInfo) replaceObjectLocalhost('version', moduleInfo);
60
+ return args;
61
+ },
62
+ loadRemoteSnapshot (args) {
63
+ const { remoteSnapshot } = args;
64
+ if ('publicPath' in remoteSnapshot) replaceObjectLocalhost('publicPath', remoteSnapshot);
65
+ if ('getPublicPath' in remoteSnapshot) replaceObjectLocalhost('getPublicPath', remoteSnapshot);
66
+ if (remoteSnapshot.remotesInfo) Object.keys(remoteSnapshot.remotesInfo).forEach((key)=>{
67
+ const remoteInfo = remoteSnapshot.remotesInfo[key];
68
+ replaceObjectLocalhost('matchedVersion', remoteInfo);
69
+ });
70
+ return args;
71
+ }
72
+ });
73
+ const resolve_entry_ipv4 = resolveEntryIpv4Plugin;
74
+ exports["default"] = __webpack_exports__["default"];
75
+ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
76
+ "default"
77
+ ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
78
+ Object.defineProperty(exports, '__esModule', {
79
+ value: true
80
+ });
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, definition)=>{
5
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
+ enumerable: true,
7
+ get: definition[key]
8
+ });
9
+ };
10
+ })();
11
+ (()=>{
12
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
+ })();
14
+ (()=>{
15
+ __webpack_require__.r = (exports1)=>{
16
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
+ value: 'Module'
18
+ });
19
+ Object.defineProperty(exports1, '__esModule', {
20
+ value: true
21
+ });
22
+ };
23
+ })();
24
+ var __webpack_exports__ = {};
25
+ __webpack_require__.r(__webpack_exports__);
26
+ __webpack_require__.d(__webpack_exports__, {
27
+ default: ()=>__WEBPACK_DEFAULT_EXPORT__
28
+ });
29
+ const sharedStrategy = ()=>({
30
+ name: 'shared-strategy-plugin',
31
+ beforeInit (args) {
32
+ const { userOptions } = args;
33
+ const shared = userOptions.shared;
34
+ if (shared) Object.keys(shared).forEach((sharedKey)=>{
35
+ const sharedConfigs = shared[sharedKey];
36
+ const arraySharedConfigs = Array.isArray(sharedConfigs) ? sharedConfigs : [
37
+ sharedConfigs
38
+ ];
39
+ arraySharedConfigs.forEach((s)=>{
40
+ s.strategy = 'loaded-first';
41
+ });
42
+ });
43
+ return args;
44
+ }
45
+ });
46
+ const __WEBPACK_DEFAULT_EXPORT__ = sharedStrategy;
47
+ exports["default"] = __webpack_exports__["default"];
48
+ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
49
+ "default"
50
+ ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
51
+ Object.defineProperty(exports, '__esModule', {
52
+ value: true
53
+ });