@module-federation/modern-js 0.0.0-next-20250401063000 → 0.0.0-next-20250402032411

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.
@@ -7,7 +7,6 @@ import { ModuleFederationPlugin as RspackModuleFederationPlugin } from "@module-
7
7
  import UniverseEntryChunkTrackerPlugin from "@module-federation/node/universe-entry-chunk-tracker-plugin";
8
8
  import { updateStatsAndManifest } from "./manifest";
9
9
  import { isDev } from "./constant";
10
- import { MODERN_JS_SERVER_DIR } from "../constant";
11
10
  import logger from "./logger";
12
11
  import { isWebTarget, skipByTarget } from "./utils";
13
12
  function setEnv() {
@@ -15,6 +14,53 @@ function setEnv() {
15
14
  process.env["MF_SSR_PRJ"] = "true";
16
15
  }
17
16
  var CHAIN_MF_PLUGIN_ID = "plugin-module-federation-server";
17
+ var ssrPublicPath = "";
18
+ var mfSSRRsbuildPlugin = function(pluginOptions) {
19
+ return {
20
+ name: "@modern-js/plugin-mf-post-config",
21
+ pre: [
22
+ "@modern-js/builder-plugin-ssr"
23
+ ],
24
+ setup: function setup(api) {
25
+ if (pluginOptions.csrConfig.getPublicPath) {
26
+ return;
27
+ }
28
+ var csrOutputPath = "";
29
+ var ssrOutputPath = "";
30
+ var ssrEnv = "";
31
+ api.modifyEnvironmentConfig(function(config, param) {
32
+ var name = param.name;
33
+ var target = config.output.target;
34
+ if (skipByTarget(target)) {
35
+ return config;
36
+ }
37
+ if (isWebTarget(target)) {
38
+ csrOutputPath = config.output.distPath.root;
39
+ } else {
40
+ ssrOutputPath = config.output.distPath.root;
41
+ ssrEnv = name;
42
+ }
43
+ return config;
44
+ });
45
+ var modifySSRPublicPath = function(config, utils) {
46
+ if (ssrEnv !== utils.environment.name) {
47
+ return config;
48
+ }
49
+ ssrPublicPath = "".concat(config.output.publicPath).concat(path.relative(csrOutputPath, ssrOutputPath), "/");
50
+ config.output.publicPath = ssrPublicPath;
51
+ return config;
52
+ };
53
+ api.modifyWebpackConfig(function(config, utils) {
54
+ modifySSRPublicPath(config, utils);
55
+ return config;
56
+ });
57
+ api.modifyRspackConfig(function(config, utils) {
58
+ modifySSRPublicPath(config, utils);
59
+ return config;
60
+ });
61
+ }
62
+ };
63
+ };
18
64
  var moduleFederationSSRPlugin = function(pluginOptions) {
19
65
  return {
20
66
  name: "@modern-js/plugin-module-federation-ssr",
@@ -24,12 +70,10 @@ var moduleFederationSSRPlugin = function(pluginOptions) {
24
70
  ],
25
71
  setup: function() {
26
72
  var _ref = _async_to_generator(function(api) {
27
- var _pluginOptions_userConfig, _modernjsConfig_server, modernjsConfig, _pluginOptions_userConfig_ssr, enableSSR, csrOutputPath, ssrOutputPath;
73
+ var _pluginOptions_userConfig, _modernjsConfig_server, modernjsConfig, _pluginOptions_userConfig_ssr, enableSSR;
28
74
  return _ts_generator(this, function(_state) {
29
75
  modernjsConfig = api.getConfig();
30
76
  enableSSR = (_pluginOptions_userConfig_ssr = (_pluginOptions_userConfig = pluginOptions.userConfig) === null || _pluginOptions_userConfig === void 0 ? void 0 : _pluginOptions_userConfig.ssr) !== null && _pluginOptions_userConfig_ssr !== void 0 ? _pluginOptions_userConfig_ssr : Boolean(modernjsConfig === null || modernjsConfig === void 0 ? void 0 : (_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
31
- csrOutputPath = "";
32
- ssrOutputPath = "";
33
77
  if (!enableSSR) {
34
78
  return [
35
79
  2
@@ -83,14 +127,12 @@ var moduleFederationSSRPlugin = function(pluginOptions) {
83
127
  "@module-federation/node/utils": "NOT_USED_IN_BROWSER"
84
128
  });
85
129
  }
86
- if (!isWeb) {
87
- ssrOutputPath = chain.output.get("path") || path.resolve(process.cwd(), "dist/".concat(MODERN_JS_SERVER_DIR));
88
- } else {
89
- csrOutputPath = chain.output.get("path") || path.resolve(process.cwd(), "dist");
90
- }
91
130
  });
92
131
  api.config(function() {
93
132
  return {
133
+ builderPlugins: [
134
+ mfSSRRsbuildPlugin(pluginOptions)
135
+ ],
94
136
  tools: {
95
137
  devServer: {
96
138
  before: [
@@ -123,11 +165,11 @@ var moduleFederationSSRPlugin = function(pluginOptions) {
123
165
  });
124
166
  api.onAfterBuild(function() {
125
167
  var nodePlugin = pluginOptions.nodePlugin, browserPlugin = pluginOptions.browserPlugin, distOutputDir = pluginOptions.distOutputDir;
126
- updateStatsAndManifest(nodePlugin, browserPlugin, distOutputDir, path.relative(csrOutputPath, ssrOutputPath));
168
+ updateStatsAndManifest(nodePlugin, browserPlugin, distOutputDir, ssrPublicPath);
127
169
  });
128
170
  api.onDevCompileDone(function() {
129
171
  var nodePlugin = pluginOptions.nodePlugin, browserPlugin = pluginOptions.browserPlugin, distOutputDir = pluginOptions.distOutputDir;
130
- updateStatsAndManifest(nodePlugin, browserPlugin, distOutputDir, path.relative(csrOutputPath, ssrOutputPath));
172
+ updateStatsAndManifest(nodePlugin, browserPlugin, distOutputDir, ssrPublicPath);
131
173
  });
132
174
  return [
133
175
  2
@@ -1,260 +1,4 @@
1
- import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
- import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
3
- import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
4
- import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
5
- import { _ as _type_of } from "@swc/helpers/_/_type_of";
6
- import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
7
1
  import os from "os";
8
- import path from "path";
9
- import { encodeName } from "@module-federation/sdk";
10
- import { bundle } from "@modern-js/node-bundle-require";
11
- import { LOCALHOST, PLUGIN_IDENTIFIER } from "../constant";
12
- import logger from "./logger";
13
- import { autoDeleteSplitChunkCacheGroups } from "@module-federation/rsbuild-plugin/utils";
14
- var defaultPath = path.resolve(process.cwd(), "module-federation.config.ts");
15
- var isDev = process.env.NODE_ENV === "development";
16
- var getMFConfig = function() {
17
- var _ref = _async_to_generator(function(userConfig) {
18
- var config, configPath, mfConfigPath, preBundlePath, mfConfig;
19
- return _ts_generator(this, function(_state) {
20
- switch (_state.label) {
21
- case 0:
22
- config = userConfig.config, configPath = userConfig.configPath;
23
- if (config) {
24
- return [
25
- 2,
26
- config
27
- ];
28
- }
29
- mfConfigPath = configPath ? configPath : defaultPath;
30
- return [
31
- 4,
32
- bundle(mfConfigPath)
33
- ];
34
- case 1:
35
- preBundlePath = _state.sent();
36
- return [
37
- 4,
38
- import(preBundlePath)
39
- ];
40
- case 2:
41
- mfConfig = _state.sent().default;
42
- return [
43
- 2,
44
- mfConfig
45
- ];
46
- }
47
- });
48
- });
49
- return function getMFConfig2(userConfig) {
50
- return _ref.apply(this, arguments);
51
- };
52
- }();
53
- var injectRuntimePlugins = function(runtimePlugin, runtimePlugins) {
54
- if (!runtimePlugins.includes(runtimePlugin)) {
55
- runtimePlugins.push(runtimePlugin);
56
- }
57
- };
58
- var replaceRemoteUrl = function(mfConfig, remoteIpStrategy) {
59
- if (remoteIpStrategy && remoteIpStrategy === "inherit") {
60
- return;
61
- }
62
- if (!mfConfig.remotes) {
63
- return;
64
- }
65
- var ipv4 = getIPV4();
66
- var handleRemoteObject = function(remoteObject) {
67
- Object.keys(remoteObject).forEach(function(remoteKey) {
68
- var remote = remoteObject[remoteKey];
69
- if (Array.isArray(remote)) {
70
- return;
71
- }
72
- if (typeof remote === "string" && remote.includes(LOCALHOST)) {
73
- remoteObject[remoteKey] = remote.replace(LOCALHOST, ipv4);
74
- }
75
- if ((typeof remote === "undefined" ? "undefined" : _type_of(remote)) === "object" && !Array.isArray(remote.external) && remote.external.includes(LOCALHOST)) {
76
- remote.external = remote.external.replace(LOCALHOST, ipv4);
77
- }
78
- });
79
- };
80
- if (Array.isArray(mfConfig.remotes)) {
81
- mfConfig.remotes.forEach(function(remoteObject) {
82
- if (typeof remoteObject === "string") {
83
- return;
84
- }
85
- handleRemoteObject(remoteObject);
86
- });
87
- } else if (typeof mfConfig.remotes !== "string") {
88
- handleRemoteObject(mfConfig.remotes);
89
- }
90
- };
91
- var patchDTSConfig = function(mfConfig, isServer) {
92
- if (isServer) {
93
- return;
94
- }
95
- var ModernJSRuntime = "@modern-js/runtime/mf";
96
- if (mfConfig.dts !== false) {
97
- var _mfConfig_dts, _mfConfig_dts1;
98
- if (typeof mfConfig.dts === "boolean" || mfConfig.dts === void 0) {
99
- mfConfig.dts = {
100
- consumeTypes: {
101
- runtimePkgs: [
102
- ModernJSRuntime
103
- ]
104
- }
105
- };
106
- } 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) {
107
- var _mfConfig_dts2;
108
- if (typeof mfConfig.dts.consumeTypes === "boolean" || ((_mfConfig_dts2 = mfConfig.dts) === null || _mfConfig_dts2 === void 0 ? void 0 : _mfConfig_dts2.consumeTypes) === void 0) {
109
- mfConfig.dts.consumeTypes = {
110
- runtimePkgs: [
111
- ModernJSRuntime
112
- ]
113
- };
114
- } else {
115
- mfConfig.dts.consumeTypes.runtimePkgs = mfConfig.dts.consumeTypes.runtimePkgs || [];
116
- if (!mfConfig.dts.consumeTypes.runtimePkgs.includes(ModernJSRuntime)) {
117
- mfConfig.dts.consumeTypes.runtimePkgs.push(ModernJSRuntime);
118
- }
119
- }
120
- }
121
- }
122
- };
123
- var patchMFConfig = function(mfConfig, isServer, remoteIpStrategy) {
124
- replaceRemoteUrl(mfConfig, remoteIpStrategy);
125
- if (mfConfig.remoteType === void 0) {
126
- mfConfig.remoteType = "script";
127
- }
128
- if (!mfConfig.name) {
129
- throw new Error("".concat(PLUGIN_IDENTIFIER, " mfConfig.name can not be empty!"));
130
- }
131
- var runtimePlugins = _to_consumable_array(mfConfig.runtimePlugins || []);
132
- patchDTSConfig(mfConfig, isServer);
133
- injectRuntimePlugins(require.resolve("@module-federation/modern-js/shared-strategy"), runtimePlugins);
134
- if (isDev) {
135
- injectRuntimePlugins(require.resolve("@module-federation/modern-js/resolve-entry-ipv4"), runtimePlugins);
136
- }
137
- if (isServer) {
138
- injectRuntimePlugins(require.resolve("@module-federation/node/runtimePlugin"), runtimePlugins);
139
- if (isDev) {
140
- injectRuntimePlugins(require.resolve("@module-federation/node/record-dynamic-remote-entry-hash-plugin"), runtimePlugins);
141
- }
142
- injectRuntimePlugins(require.resolve("@module-federation/modern-js/inject-node-fetch"), runtimePlugins);
143
- if (!mfConfig.library) {
144
- mfConfig.library = {
145
- type: "commonjs-module",
146
- name: mfConfig.name
147
- };
148
- } else {
149
- if (!mfConfig.library.type) {
150
- mfConfig.library.type = "commonjs-module";
151
- }
152
- if (!mfConfig.library.name) {
153
- mfConfig.library.name = mfConfig.name;
154
- }
155
- }
156
- }
157
- mfConfig.runtimePlugins = runtimePlugins;
158
- if (!isServer) {
159
- var _mfConfig_library;
160
- if (((_mfConfig_library = mfConfig.library) === null || _mfConfig_library === void 0 ? void 0 : _mfConfig_library.type) === "commonjs-module") {
161
- mfConfig.library.type = "global";
162
- }
163
- return mfConfig;
164
- }
165
- mfConfig.dts = false;
166
- mfConfig.dev = false;
167
- return mfConfig;
168
- };
169
- function patchIgnoreWarning(chain) {
170
- var ignoreWarnings = chain.get("ignoreWarnings") || [];
171
- var ignoredMsgs = [
172
- "external script",
173
- "process.env.WS_NO_BUFFER_UTIL",
174
- "Can't resolve 'utf-8-validate"
175
- ];
176
- ignoreWarnings.push(function(warning) {
177
- if (ignoredMsgs.some(function(msg) {
178
- return warning.message.includes(msg);
179
- })) {
180
- return true;
181
- }
182
- return false;
183
- });
184
- chain.ignoreWarnings(ignoreWarnings);
185
- }
186
- function addMyTypes2Ignored(chain, mfConfig) {
187
- var watchOptions = chain.get("watchOptions");
188
- if (!watchOptions || !watchOptions.ignored) {
189
- chain.watchOptions({
190
- ignored: /[\\/](?:\.git|node_modules|@mf-types)[\\/]/
191
- });
192
- return;
193
- }
194
- var ignored = watchOptions.ignored;
195
- var DEFAULT_IGNORED_GLOB = "**/@mf-types/**";
196
- if (Array.isArray(ignored)) {
197
- if (mfConfig.dts !== false && _type_of(mfConfig.dts) === "object" && _type_of(mfConfig.dts.consumeTypes) === "object" && mfConfig.dts.consumeTypes.remoteTypesFolder) {
198
- chain.watchOptions(_object_spread_props(_object_spread({}, watchOptions), {
199
- ignored: ignored.concat("**/".concat(mfConfig.dts.consumeTypes.remoteTypesFolder, "/**"))
200
- }));
201
- } else {
202
- chain.watchOptions(_object_spread_props(_object_spread({}, watchOptions), {
203
- ignored: ignored.concat(DEFAULT_IGNORED_GLOB)
204
- }));
205
- }
206
- return;
207
- }
208
- if (typeof ignored !== "string") {
209
- chain.watchOptions(_object_spread_props(_object_spread({}, watchOptions), {
210
- ignored: /[\\/](?:\.git|node_modules|@mf-types)[\\/]/
211
- }));
212
- return;
213
- }
214
- chain.watchOptions(_object_spread_props(_object_spread({}, watchOptions), {
215
- ignored: ignored.concat(DEFAULT_IGNORED_GLOB)
216
- }));
217
- }
218
- function patchBundlerConfig(options) {
219
- var _modernjsConfig_deploy;
220
- var chain = options.chain, modernjsConfig = options.modernjsConfig, isServer = options.isServer, mfConfig = options.mfConfig, enableSSR = options.enableSSR;
221
- chain.optimization.delete("runtimeChunk");
222
- patchIgnoreWarning(chain);
223
- if (!chain.output.get("chunkLoadingGlobal")) {
224
- chain.output.chunkLoadingGlobal("chunk_".concat(mfConfig.name));
225
- }
226
- if (!chain.output.get("uniqueName")) {
227
- chain.output.uniqueName(mfConfig.name);
228
- }
229
- var splitChunkConfig = chain.optimization.splitChunks.entries();
230
- if (!isServer) {
231
- autoDeleteSplitChunkCacheGroups(mfConfig, splitChunkConfig);
232
- }
233
- if (!isServer && enableSSR && splitChunkConfig && (typeof splitChunkConfig === "undefined" ? "undefined" : _type_of(splitChunkConfig)) === "object" && splitChunkConfig.cacheGroups) {
234
- splitChunkConfig.chunks = "async";
235
- logger.warn('splitChunks.chunks = async is not allowed with stream SSR mode, it will auto changed to "async"');
236
- }
237
- if (isDev && chain.output.get("publicPath") === "auto") {
238
- var _modernjsConfig_dev, _modernjsConfig_server;
239
- var 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;
240
- var publicPath = "http://localhost:".concat(port, "/");
241
- chain.output.publicPath(publicPath);
242
- }
243
- if (isServer && enableSSR) {
244
- var uniqueName = mfConfig.name || chain.output.get("uniqueName");
245
- var chunkFileName = chain.output.get("chunkFilename");
246
- if (typeof chunkFileName === "string" && uniqueName && !chunkFileName.includes(uniqueName)) {
247
- var suffix = "".concat(encodeName(uniqueName), "-[chunkhash].js");
248
- chain.output.chunkFilename(chunkFileName.replace(".js", suffix));
249
- }
250
- }
251
- if (isDev && enableSSR && !isServer) {
252
- chain.resolve.fallback.set("crypto", false).set("stream", false).set("vm", false);
253
- }
254
- if (((_modernjsConfig_deploy = modernjsConfig.deploy) === null || _modernjsConfig_deploy === void 0 ? void 0 : _modernjsConfig_deploy.microFrontend) && Object.keys(mfConfig.exposes || {}).length) {
255
- chain.optimization.usedExports(false);
256
- }
257
- }
258
2
  var localIpv4 = "127.0.0.1";
259
3
  var getIpv4Interfaces = function() {
260
4
  try {
@@ -299,11 +43,7 @@ var skipByTarget = function(target) {
299
43
  return false;
300
44
  };
301
45
  export {
302
- addMyTypes2Ignored,
303
46
  getIPV4,
304
- getMFConfig,
305
47
  isWebTarget,
306
- patchBundlerConfig,
307
- patchMFConfig,
308
48
  skipByTarget
309
49
  };
@@ -1,8 +1,6 @@
1
- var MODERN_JS_SERVER_DIR = "bundles";
2
1
  var LOCALHOST = "localhost";
3
2
  var PLUGIN_IDENTIFIER = "[ Modern.js Module Federation ]";
4
3
  export {
5
4
  LOCALHOST,
6
- MODERN_JS_SERVER_DIR,
7
5
  PLUGIN_IDENTIFIER
8
6
  };
@@ -1,11 +1,237 @@
1
1
  import path from "path";
2
- import { patchBundlerConfig, getIPV4, getMFConfig, patchMFConfig, addMyTypes2Ignored, isWebTarget, skipByTarget } from "./utils";
2
+ import { getIPV4, isWebTarget, skipByTarget } from "./utils";
3
+ import { encodeName } from "@module-federation/sdk";
4
+ import { bundle } from "@modern-js/node-bundle-require";
5
+ import { LOCALHOST, PLUGIN_IDENTIFIER } from "../constant";
6
+ import logger from "./logger";
7
+ import { autoDeleteSplitChunkCacheGroups } from "@module-federation/rsbuild-plugin/utils";
8
+ const defaultPath = path.resolve(process.cwd(), "module-federation.config.ts");
9
+ const isDev = process.env.NODE_ENV === "development";
3
10
  function setEnv(enableSSR) {
4
11
  if (enableSSR) {
5
12
  process.env["MF_DISABLE_EMIT_STATS"] = "true";
6
13
  process.env["MF_SSR_PRJ"] = "true";
7
14
  }
8
15
  }
16
+ const getMFConfig = async (userConfig) => {
17
+ const { config, configPath } = userConfig;
18
+ if (config) {
19
+ return config;
20
+ }
21
+ const mfConfigPath = configPath ? configPath : defaultPath;
22
+ const preBundlePath = await bundle(mfConfigPath);
23
+ const mfConfig = (await import(preBundlePath)).default;
24
+ return mfConfig;
25
+ };
26
+ const injectRuntimePlugins = (runtimePlugin, runtimePlugins) => {
27
+ if (!runtimePlugins.includes(runtimePlugin)) {
28
+ runtimePlugins.push(runtimePlugin);
29
+ }
30
+ };
31
+ const replaceRemoteUrl = (mfConfig, remoteIpStrategy) => {
32
+ if (remoteIpStrategy && remoteIpStrategy === "inherit") {
33
+ return;
34
+ }
35
+ if (!mfConfig.remotes) {
36
+ return;
37
+ }
38
+ const ipv4 = getIPV4();
39
+ const handleRemoteObject = (remoteObject) => {
40
+ Object.keys(remoteObject).forEach((remoteKey) => {
41
+ const remote = remoteObject[remoteKey];
42
+ if (Array.isArray(remote)) {
43
+ return;
44
+ }
45
+ if (typeof remote === "string" && remote.includes(LOCALHOST)) {
46
+ remoteObject[remoteKey] = remote.replace(LOCALHOST, ipv4);
47
+ }
48
+ if (typeof remote === "object" && !Array.isArray(remote.external) && remote.external.includes(LOCALHOST)) {
49
+ remote.external = remote.external.replace(LOCALHOST, ipv4);
50
+ }
51
+ });
52
+ };
53
+ if (Array.isArray(mfConfig.remotes)) {
54
+ mfConfig.remotes.forEach((remoteObject) => {
55
+ if (typeof remoteObject === "string") {
56
+ return;
57
+ }
58
+ handleRemoteObject(remoteObject);
59
+ });
60
+ } else if (typeof mfConfig.remotes !== "string") {
61
+ handleRemoteObject(mfConfig.remotes);
62
+ }
63
+ };
64
+ const patchDTSConfig = (mfConfig, isServer) => {
65
+ if (isServer) {
66
+ return;
67
+ }
68
+ const ModernJSRuntime = "@modern-js/runtime/mf";
69
+ if (mfConfig.dts !== false) {
70
+ var _mfConfig_dts, _mfConfig_dts1;
71
+ if (typeof mfConfig.dts === "boolean" || mfConfig.dts === void 0) {
72
+ mfConfig.dts = {
73
+ consumeTypes: {
74
+ runtimePkgs: [
75
+ ModernJSRuntime
76
+ ]
77
+ }
78
+ };
79
+ } 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) {
80
+ var _mfConfig_dts2;
81
+ if (typeof mfConfig.dts.consumeTypes === "boolean" || ((_mfConfig_dts2 = mfConfig.dts) === null || _mfConfig_dts2 === void 0 ? void 0 : _mfConfig_dts2.consumeTypes) === void 0) {
82
+ mfConfig.dts.consumeTypes = {
83
+ runtimePkgs: [
84
+ ModernJSRuntime
85
+ ]
86
+ };
87
+ } else {
88
+ mfConfig.dts.consumeTypes.runtimePkgs = mfConfig.dts.consumeTypes.runtimePkgs || [];
89
+ if (!mfConfig.dts.consumeTypes.runtimePkgs.includes(ModernJSRuntime)) {
90
+ mfConfig.dts.consumeTypes.runtimePkgs.push(ModernJSRuntime);
91
+ }
92
+ }
93
+ }
94
+ }
95
+ };
96
+ const patchMFConfig = (mfConfig, isServer, remoteIpStrategy) => {
97
+ replaceRemoteUrl(mfConfig, remoteIpStrategy);
98
+ if (mfConfig.remoteType === void 0) {
99
+ mfConfig.remoteType = "script";
100
+ }
101
+ if (!mfConfig.name) {
102
+ throw new Error(`${PLUGIN_IDENTIFIER} mfConfig.name can not be empty!`);
103
+ }
104
+ const runtimePlugins = [
105
+ ...mfConfig.runtimePlugins || []
106
+ ];
107
+ patchDTSConfig(mfConfig, isServer);
108
+ injectRuntimePlugins(require.resolve("@module-federation/modern-js/shared-strategy"), runtimePlugins);
109
+ if (isDev) {
110
+ injectRuntimePlugins(require.resolve("@module-federation/modern-js/resolve-entry-ipv4"), runtimePlugins);
111
+ }
112
+ if (isServer) {
113
+ injectRuntimePlugins(require.resolve("@module-federation/node/runtimePlugin"), runtimePlugins);
114
+ if (isDev) {
115
+ injectRuntimePlugins(require.resolve("@module-federation/node/record-dynamic-remote-entry-hash-plugin"), runtimePlugins);
116
+ }
117
+ injectRuntimePlugins(require.resolve("@module-federation/modern-js/inject-node-fetch"), runtimePlugins);
118
+ if (!mfConfig.library) {
119
+ mfConfig.library = {
120
+ type: "commonjs-module",
121
+ name: mfConfig.name
122
+ };
123
+ } else {
124
+ if (!mfConfig.library.type) {
125
+ mfConfig.library.type = "commonjs-module";
126
+ }
127
+ if (!mfConfig.library.name) {
128
+ mfConfig.library.name = mfConfig.name;
129
+ }
130
+ }
131
+ }
132
+ mfConfig.runtimePlugins = runtimePlugins;
133
+ if (!isServer) {
134
+ var _mfConfig_library;
135
+ if (((_mfConfig_library = mfConfig.library) === null || _mfConfig_library === void 0 ? void 0 : _mfConfig_library.type) === "commonjs-module") {
136
+ mfConfig.library.type = "global";
137
+ }
138
+ return mfConfig;
139
+ }
140
+ mfConfig.dts = false;
141
+ mfConfig.dev = false;
142
+ return mfConfig;
143
+ };
144
+ function patchIgnoreWarning(chain) {
145
+ const ignoreWarnings = chain.get("ignoreWarnings") || [];
146
+ const ignoredMsgs = [
147
+ "external script",
148
+ "process.env.WS_NO_BUFFER_UTIL",
149
+ `Can't resolve 'utf-8-validate`
150
+ ];
151
+ ignoreWarnings.push((warning) => {
152
+ if (ignoredMsgs.some((msg) => warning.message.includes(msg))) {
153
+ return true;
154
+ }
155
+ return false;
156
+ });
157
+ chain.ignoreWarnings(ignoreWarnings);
158
+ }
159
+ function addMyTypes2Ignored(chain, mfConfig) {
160
+ const watchOptions = chain.get("watchOptions");
161
+ if (!watchOptions || !watchOptions.ignored) {
162
+ chain.watchOptions({
163
+ ignored: /[\\/](?:\.git|node_modules|@mf-types)[\\/]/
164
+ });
165
+ return;
166
+ }
167
+ const ignored = watchOptions.ignored;
168
+ const DEFAULT_IGNORED_GLOB = "**/@mf-types/**";
169
+ if (Array.isArray(ignored)) {
170
+ if (mfConfig.dts !== false && typeof mfConfig.dts === "object" && typeof mfConfig.dts.consumeTypes === "object" && mfConfig.dts.consumeTypes.remoteTypesFolder) {
171
+ chain.watchOptions({
172
+ ...watchOptions,
173
+ ignored: ignored.concat(`**/${mfConfig.dts.consumeTypes.remoteTypesFolder}/**`)
174
+ });
175
+ } else {
176
+ chain.watchOptions({
177
+ ...watchOptions,
178
+ ignored: ignored.concat(DEFAULT_IGNORED_GLOB)
179
+ });
180
+ }
181
+ return;
182
+ }
183
+ if (typeof ignored !== "string") {
184
+ chain.watchOptions({
185
+ ...watchOptions,
186
+ ignored: /[\\/](?:\.git|node_modules|@mf-types)[\\/]/
187
+ });
188
+ return;
189
+ }
190
+ chain.watchOptions({
191
+ ...watchOptions,
192
+ ignored: ignored.concat(DEFAULT_IGNORED_GLOB)
193
+ });
194
+ }
195
+ function patchBundlerConfig(options) {
196
+ var _modernjsConfig_deploy;
197
+ const { chain, modernjsConfig, isServer, mfConfig, enableSSR } = options;
198
+ chain.optimization.delete("runtimeChunk");
199
+ patchIgnoreWarning(chain);
200
+ if (!chain.output.get("chunkLoadingGlobal")) {
201
+ chain.output.chunkLoadingGlobal(`chunk_${mfConfig.name}`);
202
+ }
203
+ if (!chain.output.get("uniqueName")) {
204
+ chain.output.uniqueName(mfConfig.name);
205
+ }
206
+ const splitChunkConfig = chain.optimization.splitChunks.entries();
207
+ if (!isServer) {
208
+ autoDeleteSplitChunkCacheGroups(mfConfig, splitChunkConfig);
209
+ }
210
+ if (!isServer && enableSSR && splitChunkConfig && typeof splitChunkConfig === "object" && splitChunkConfig.cacheGroups) {
211
+ splitChunkConfig.chunks = "async";
212
+ logger.warn(`splitChunks.chunks = async is not allowed with stream SSR mode, it will auto changed to "async"`);
213
+ }
214
+ if (isDev && chain.output.get("publicPath") === "auto") {
215
+ var _modernjsConfig_dev, _modernjsConfig_server;
216
+ 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;
217
+ const publicPath = `http://localhost:${port}/`;
218
+ chain.output.publicPath(publicPath);
219
+ }
220
+ if (isServer && enableSSR) {
221
+ const uniqueName = mfConfig.name || chain.output.get("uniqueName");
222
+ const chunkFileName = chain.output.get("chunkFilename");
223
+ if (typeof chunkFileName === "string" && uniqueName && !chunkFileName.includes(uniqueName)) {
224
+ const suffix = `${encodeName(uniqueName)}-[chunkhash].js`;
225
+ chain.output.chunkFilename(chunkFileName.replace(".js", suffix));
226
+ }
227
+ }
228
+ if (isDev && enableSSR && !isServer) {
229
+ chain.resolve.fallback.set("crypto", false).set("stream", false).set("vm", false);
230
+ }
231
+ if (((_modernjsConfig_deploy = modernjsConfig.deploy) === null || _modernjsConfig_deploy === void 0 ? void 0 : _modernjsConfig_deploy.microFrontend) && Object.keys(mfConfig.exposes || {}).length) {
232
+ chain.optimization.usedExports(false);
233
+ }
234
+ }
9
235
  const moduleFederationConfigPlugin = (userConfig) => ({
10
236
  name: "@modern-js/plugin-module-federation-config",
11
237
  pre: [
@@ -84,9 +310,13 @@ const moduleFederationConfigPlugin = (userConfig) => ({
84
310
  });
85
311
  var configPlugin_default = moduleFederationConfigPlugin;
86
312
  export {
313
+ addMyTypes2Ignored,
87
314
  configPlugin_default as default,
315
+ getMFConfig,
88
316
  isWebTarget,
89
317
  moduleFederationConfigPlugin,
318
+ patchBundlerConfig,
319
+ patchMFConfig,
90
320
  setEnv,
91
321
  skipByTarget
92
322
  };
@@ -1,5 +1,6 @@
1
1
  import { it, expect, describe } from "vitest";
2
- import { patchMFConfig, getIPV4 } from "./utils";
2
+ import { patchMFConfig } from "./configPlugin";
3
+ import { getIPV4 } from "./utils";
3
4
  const mfConfig = {
4
5
  name: "host",
5
6
  filename: "remoteEntry.js",