@module-federation/modern-js 0.0.0-next-20250219103339 → 0.0.0-next-20250220101307

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.
@@ -12,7 +12,6 @@ function setEnv() {
12
12
  process.env["MF_DISABLE_EMIT_STATS"] = "true";
13
13
  process.env["MF_SSR_PRJ"] = "true";
14
14
  }
15
- var CHAIN_MF_PLUGIN_ID = "plugin-module-federation-server";
16
15
  var moduleFederationSSRPlugin = function(pluginOptions) {
17
16
  return {
18
17
  name: "@modern-js/plugin-module-federation-ssr",
@@ -26,8 +25,6 @@ var moduleFederationSSRPlugin = function(pluginOptions) {
26
25
  return _ts_generator(this, function(_state) {
27
26
  modernjsConfig = api.getConfig();
28
27
  enableSSR = ((_pluginOptions_userConfig = pluginOptions.userConfig) === null || _pluginOptions_userConfig === void 0 ? void 0 : _pluginOptions_userConfig.ssr) === false ? false : Boolean(modernjsConfig === null || modernjsConfig === void 0 ? void 0 : (_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
29
- console.log("enableSSR: ", enableSSR);
30
- console.log("isDev: ", isDev);
31
28
  if (!enableSSR) {
32
29
  return [
33
30
  2
@@ -52,37 +49,35 @@ var moduleFederationSSRPlugin = function(pluginOptions) {
52
49
  plugins
53
50
  };
54
51
  });
55
- api.modifyBundlerChain(function(chain, param) {
56
- var isServer = param.isServer;
57
- var bundlerType = api.getAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
58
- console.log("ssrPlugin bundlerType: ", bundlerType);
59
- console.log("ssrPlugin isServer: ", isServer);
60
- var MFPlugin = bundlerType === "webpack" ? ModuleFederationPlugin : RspackModuleFederationPlugin;
61
- if (isServer) {
62
- if (!chain.plugins.has(CHAIN_MF_PLUGIN_ID)) {
63
- chain.plugin(CHAIN_MF_PLUGIN_ID).use(MFPlugin, [
64
- pluginOptions.ssrConfig
65
- ]).init(function(Plugin, args) {
66
- pluginOptions.nodePlugin = new Plugin(args[0]);
67
- return pluginOptions.nodePlugin;
68
- });
69
- }
70
- }
71
- if (isServer) {
72
- chain.target("async-node");
73
- if (isDev) {
74
- chain.plugin("UniverseEntryChunkTrackerPlugin").use(UniverseEntryChunkTrackerPlugin);
75
- }
76
- }
77
- if (isDev && !isServer) {
78
- chain.externals({
79
- "@module-federation/node/utils": "NOT_USED_IN_BROWSER"
80
- });
81
- }
82
- });
83
52
  api.config(function() {
84
53
  return {
85
54
  tools: {
55
+ rspack: function rspack(config, param) {
56
+ var isServer = param.isServer;
57
+ if (isServer) {
58
+ if (!pluginOptions.nodePlugin) {
59
+ var _config_plugins;
60
+ pluginOptions.nodePlugin = new RspackModuleFederationPlugin(pluginOptions.ssrConfig);
61
+ (_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(pluginOptions.nodePlugin);
62
+ }
63
+ } else {
64
+ var _config_output;
65
+ pluginOptions.distOutputDir = pluginOptions.distOutputDir || ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.path) || path.resolve(process.cwd(), "dist");
66
+ }
67
+ },
68
+ webpack: function webpack(config, param) {
69
+ var isServer = param.isServer;
70
+ if (isServer) {
71
+ if (!pluginOptions.nodePlugin) {
72
+ var _config_plugins;
73
+ pluginOptions.nodePlugin = new ModuleFederationPlugin(pluginOptions.ssrConfig);
74
+ (_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(pluginOptions.nodePlugin);
75
+ }
76
+ } else {
77
+ var _config_output;
78
+ pluginOptions.distOutputDir = pluginOptions.distOutputDir || ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.path) || path.resolve(process.cwd(), "dist");
79
+ }
80
+ },
86
81
  devServer: {
87
82
  before: [
88
83
  function(req, res, next) {
@@ -108,6 +103,20 @@ var moduleFederationSSRPlugin = function(pluginOptions) {
108
103
  }
109
104
  }
110
105
  ]
106
+ },
107
+ bundlerChain: function bundlerChain(chain, param) {
108
+ var isServer = param.isServer;
109
+ if (isServer) {
110
+ chain.target("async-node");
111
+ if (isDev) {
112
+ chain.plugin("UniverseEntryChunkTrackerPlugin").use(UniverseEntryChunkTrackerPlugin);
113
+ }
114
+ }
115
+ if (isDev && !isServer) {
116
+ chain.externals({
117
+ "@module-federation/node/utils": "NOT_USED_IN_BROWSER"
118
+ });
119
+ }
111
120
  }
112
121
  }
113
122
  };
@@ -133,7 +142,6 @@ var moduleFederationSSRPlugin = function(pluginOptions) {
133
142
  };
134
143
  var ssrPlugin_default = moduleFederationSSRPlugin;
135
144
  export {
136
- CHAIN_MF_PLUGIN_ID,
137
145
  ssrPlugin_default as default,
138
146
  moduleFederationSSRPlugin,
139
147
  setEnv
@@ -166,14 +166,14 @@ var patchMFConfig = function(mfConfig, isServer, remoteIpStrategy) {
166
166
  mfConfig.dev = false;
167
167
  return mfConfig;
168
168
  };
169
- function patchIgnoreWarning(chain) {
170
- var ignoreWarnings = chain.get("ignoreWarnings") || [];
169
+ function patchIgnoreWarning(bundlerConfig) {
170
+ bundlerConfig.ignoreWarnings = bundlerConfig.ignoreWarnings || [];
171
171
  var ignoredMsgs = [
172
172
  "external script",
173
173
  "process.env.WS_NO_BUFFER_UTIL",
174
174
  "Can't resolve 'utf-8-validate"
175
175
  ];
176
- ignoreWarnings.push(function(warning) {
176
+ bundlerConfig.ignoreWarnings.push(function(warning) {
177
177
  if (ignoredMsgs.some(function(msg) {
178
178
  return warning.message.includes(msg);
179
179
  })) {
@@ -181,7 +181,6 @@ function patchIgnoreWarning(chain) {
181
181
  }
182
182
  return false;
183
183
  });
184
- chain.ignoreWarnings(ignoreWarnings);
185
184
  }
186
185
  function addMyTypes2Ignored(chain, mfConfig) {
187
186
  var watchOptions = chain.get("watchOptions");
@@ -216,43 +215,54 @@ function addMyTypes2Ignored(chain, mfConfig) {
216
215
  }));
217
216
  }
218
217
  function patchBundlerConfig(options) {
219
- var _modernjsConfig_server, _modernjsConfig_deploy;
220
- var chain = options.chain, modernjsConfig = options.modernjsConfig, isServer = options.isServer, mfConfig = options.mfConfig;
218
+ var _modernjsConfig_server, _bundlerConfig_optimization, _bundlerConfig_optimization1, _bundlerConfig_output, _modernjsConfig_deploy;
219
+ var bundlerConfig = options.bundlerConfig, modernjsConfig = options.modernjsConfig, isServer = options.isServer, mfConfig = options.mfConfig, bundlerType = options.bundlerType;
221
220
  var enableSSR = Boolean((_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
222
- chain.optimization.delete("runtimeChunk");
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);
221
+ (_bundlerConfig_optimization = bundlerConfig.optimization) === null || _bundlerConfig_optimization === void 0 ? true : delete _bundlerConfig_optimization.runtimeChunk;
222
+ patchIgnoreWarning(bundlerConfig);
223
+ if (bundlerConfig.output) {
224
+ var _bundlerConfig_output1, _bundlerConfig_output2;
225
+ if (!((_bundlerConfig_output1 = bundlerConfig.output) === null || _bundlerConfig_output1 === void 0 ? void 0 : _bundlerConfig_output1.chunkLoadingGlobal)) {
226
+ bundlerConfig.output.chunkLoadingGlobal = "chunk_".concat(mfConfig.name);
227
+ }
228
+ if (!((_bundlerConfig_output2 = bundlerConfig.output) === null || _bundlerConfig_output2 === void 0 ? void 0 : _bundlerConfig_output2.uniqueName)) {
229
+ bundlerConfig.output.uniqueName = mfConfig.name;
230
+ }
228
231
  }
229
- var splitChunkConfig = chain.optimization.splitChunks.entries();
230
232
  if (!isServer) {
231
- autoDeleteSplitChunkCacheGroups(mfConfig, splitChunkConfig);
233
+ autoDeleteSplitChunkCacheGroups(mfConfig, bundlerConfig);
232
234
  }
233
- if (!isServer && enableSSR && splitChunkConfig && (typeof splitChunkConfig === "undefined" ? "undefined" : _type_of(splitChunkConfig)) === "object" && splitChunkConfig.cacheGroups) {
234
- splitChunkConfig.chunks = "async";
235
+ if (!isServer && enableSSR && _type_of((_bundlerConfig_optimization1 = bundlerConfig.optimization) === null || _bundlerConfig_optimization1 === void 0 ? void 0 : _bundlerConfig_optimization1.splitChunks) === "object" && bundlerConfig.optimization.splitChunks.cacheGroups) {
236
+ bundlerConfig.optimization.splitChunks.chunks = "async";
235
237
  logger.warn('splitChunks.chunks = async is not allowed with stream SSR mode, it will auto changed to "async"');
236
238
  }
237
- if (isDev && chain.output.get("publicPath") === "auto") {
239
+ if (isDev && ((_bundlerConfig_output = bundlerConfig.output) === null || _bundlerConfig_output === void 0 ? void 0 : _bundlerConfig_output.publicPath) === "auto") {
238
240
  var _modernjsConfig_dev, _modernjsConfig_server1;
239
241
  var port = ((_modernjsConfig_dev = modernjsConfig.dev) === null || _modernjsConfig_dev === void 0 ? void 0 : _modernjsConfig_dev.port) || ((_modernjsConfig_server1 = modernjsConfig.server) === null || _modernjsConfig_server1 === void 0 ? void 0 : _modernjsConfig_server1.port) || 8080;
240
242
  var publicPath = "http://localhost:".concat(port, "/");
241
- chain.output.publicPath(publicPath);
243
+ bundlerConfig.output.publicPath = publicPath;
242
244
  }
243
245
  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)) {
246
+ var output = bundlerConfig.output;
247
+ var uniqueName = mfConfig.name || (output === null || output === void 0 ? void 0 : output.uniqueName);
248
+ var chunkFileName = output === null || output === void 0 ? void 0 : output.chunkFilename;
249
+ if (output && typeof chunkFileName === "string" && uniqueName && !chunkFileName.includes(uniqueName)) {
247
250
  var suffix = "".concat(encodeName(uniqueName), "-[chunkhash].js");
248
- chain.output.chunkFilename(chunkFileName.replace(".js", suffix));
251
+ output.chunkFilename = chunkFileName.replace(".js", suffix);
249
252
  }
250
253
  }
251
254
  if (isDev && enableSSR && !isServer) {
252
- chain.resolve.fallback.set("crypto", false).set("stream", false).set("vm", false);
255
+ bundlerConfig.resolve.fallback = _object_spread_props(_object_spread({}, bundlerConfig.resolve.fallback), {
256
+ crypto: false,
257
+ stream: false,
258
+ vm: false
259
+ });
253
260
  }
254
261
  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);
262
+ if (!bundlerConfig.optimization) {
263
+ bundlerConfig.optimization = {};
264
+ }
265
+ bundlerConfig.optimization.usedExports = false;
256
266
  }
257
267
  }
258
268
  var localIpv4 = "127.0.0.1";
@@ -280,10 +290,33 @@ var getIPV4 = function() {
280
290
  };
281
291
  return ipv4Interface.address;
282
292
  };
293
+ var SPLIT_CHUNK_MAP = {
294
+ REACT: "react",
295
+ ROUTER: "router",
296
+ LODASH: "lib-lodash",
297
+ ANTD: "lib-antd",
298
+ ARCO: "lib-arco",
299
+ SEMI: "lib-semi",
300
+ AXIOS: "lib-axios"
301
+ };
302
+ var SHARED_SPLIT_CHUNK_MAP = {
303
+ react: SPLIT_CHUNK_MAP.REACT,
304
+ "react-dom": SPLIT_CHUNK_MAP.REACT,
305
+ "react-router": SPLIT_CHUNK_MAP.ROUTER,
306
+ "react-router-dom": SPLIT_CHUNK_MAP.ROUTER,
307
+ "@remix-run/router": SPLIT_CHUNK_MAP.ROUTER,
308
+ lodash: SPLIT_CHUNK_MAP.LODASH,
309
+ "lodash-es": SPLIT_CHUNK_MAP.LODASH,
310
+ antd: SPLIT_CHUNK_MAP.ANTD,
311
+ "@arco-design/web-react": SPLIT_CHUNK_MAP.ARCO,
312
+ "@douyinfe/semi-ui": SPLIT_CHUNK_MAP.SEMI,
313
+ axios: SPLIT_CHUNK_MAP.AXIOS
314
+ };
283
315
  export {
284
316
  addMyTypes2Ignored,
285
317
  getIPV4,
286
318
  getMFConfig,
287
319
  patchBundlerConfig,
320
+ patchIgnoreWarning,
288
321
  patchMFConfig
289
322
  };
@@ -1,7 +1,7 @@
1
1
  import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
2
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
3
  import { it, expect, describe } from "vitest";
4
- import { patchMFConfig, getIPV4 } from "./utils";
4
+ import { patchMFConfig, patchBundlerConfig, getIPV4 } from "./utils";
5
5
  var mfConfig = {
6
6
  name: "host",
7
7
  filename: "remoteEntry.js",
@@ -105,3 +105,80 @@ describe("patchMFConfig", /* @__PURE__ */ _async_to_generator(function() {
105
105
  ];
106
106
  });
107
107
  }));
108
+ describe("patchBundlerConfig", /* @__PURE__ */ _async_to_generator(function() {
109
+ return _ts_generator(this, function(_state) {
110
+ it("patchBundlerConfig: server", /* @__PURE__ */ _async_to_generator(function() {
111
+ var bundlerConfig, expectedConfig;
112
+ return _ts_generator(this, function(_state2) {
113
+ bundlerConfig = {
114
+ output: {
115
+ publicPath: "auto"
116
+ }
117
+ };
118
+ patchBundlerConfig({
119
+ bundlerType: "webpack",
120
+ bundlerConfig,
121
+ isServer: true,
122
+ modernjsConfig: {
123
+ server: {
124
+ ssr: {
125
+ mode: "stream"
126
+ }
127
+ }
128
+ },
129
+ mfConfig
130
+ });
131
+ expectedConfig = {
132
+ output: {
133
+ chunkLoadingGlobal: "chunk_host",
134
+ publicPath: "auto",
135
+ uniqueName: "host"
136
+ }
137
+ };
138
+ bundlerConfig === null || bundlerConfig === void 0 ? true : delete bundlerConfig.ignoreWarnings;
139
+ expect(bundlerConfig).toStrictEqual(expectedConfig);
140
+ return [
141
+ 2
142
+ ];
143
+ });
144
+ }));
145
+ it("patchBundlerConfig: client", /* @__PURE__ */ _async_to_generator(function() {
146
+ var bundlerConfig, expectedConfig;
147
+ return _ts_generator(this, function(_state2) {
148
+ bundlerConfig = {
149
+ output: {
150
+ publicPath: "auto"
151
+ }
152
+ };
153
+ patchBundlerConfig({
154
+ bundlerType: "webpack",
155
+ bundlerConfig,
156
+ isServer: false,
157
+ modernjsConfig: {
158
+ server: {
159
+ ssr: {
160
+ mode: "stream"
161
+ }
162
+ }
163
+ },
164
+ mfConfig
165
+ });
166
+ expectedConfig = {
167
+ output: {
168
+ chunkLoadingGlobal: "chunk_host",
169
+ publicPath: "auto",
170
+ uniqueName: "host"
171
+ }
172
+ };
173
+ bundlerConfig === null || bundlerConfig === void 0 ? true : delete bundlerConfig.ignoreWarnings;
174
+ expect(bundlerConfig).toStrictEqual(expectedConfig);
175
+ return [
176
+ 2
177
+ ];
178
+ });
179
+ }));
180
+ return [
181
+ 2
182
+ ];
183
+ });
184
+ }));
@@ -6,6 +6,17 @@ function setEnv(enableSSR) {
6
6
  process.env["MF_SSR_PRJ"] = "true";
7
7
  }
8
8
  }
9
+ function modifyBundlerConfig(options) {
10
+ const { mfConfig, config, isServer, modernjsConfig, remoteIpStrategy = "ipv4", bundlerType } = options;
11
+ patchMFConfig(mfConfig, isServer, remoteIpStrategy);
12
+ patchBundlerConfig({
13
+ bundlerType,
14
+ bundlerConfig: config,
15
+ isServer,
16
+ modernjsConfig,
17
+ mfConfig
18
+ });
19
+ }
9
20
  const moduleFederationConfigPlugin = (userConfig) => ({
10
21
  name: "@modern-js/plugin-module-federation-config",
11
22
  pre: [
@@ -21,19 +32,6 @@ const moduleFederationConfigPlugin = (userConfig) => ({
21
32
  const ssrConfig = userConfig.ssrConfig || JSON.parse(JSON.stringify(mfConfig));
22
33
  userConfig.ssrConfig = ssrConfig;
23
34
  userConfig.csrConfig = csrConfig;
24
- api.modifyBundlerChain((chain, { isProd, isServer }) => {
25
- addMyTypes2Ignored(chain, isServer ? ssrConfig : csrConfig);
26
- const targetMFConfig = isServer ? ssrConfig : csrConfig;
27
- patchMFConfig(targetMFConfig, isServer, userConfig.remoteIpStrategy || "ipv4");
28
- patchBundlerConfig({
29
- // @ts-expect-error chain type is not correct
30
- chain,
31
- isServer,
32
- modernjsConfig,
33
- mfConfig
34
- });
35
- userConfig.distOutputDir = chain.output.get("path") || path.resolve(process.cwd(), "dist");
36
- });
37
35
  api.config(() => {
38
36
  var _userConfig_userConfig, _modernjsConfig_server, _modernjsConfig_source, _modernjsConfig_source1, _modernjsConfig_dev;
39
37
  const bundlerType = api.getAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
@@ -49,6 +47,33 @@ const moduleFederationConfigPlugin = (userConfig) => ({
49
47
  var _modernjsConfig_source_enableAsyncEntry;
50
48
  return {
51
49
  tools: {
50
+ bundlerChain(chain, { isServer }) {
51
+ addMyTypes2Ignored(chain, isServer ? ssrConfig : csrConfig);
52
+ },
53
+ rspack(config, { isServer }) {
54
+ var _config_output;
55
+ modifyBundlerConfig({
56
+ bundlerType,
57
+ mfConfig: isServer ? ssrConfig : csrConfig,
58
+ config,
59
+ isServer,
60
+ modernjsConfig,
61
+ remoteIpStrategy: userConfig.remoteIpStrategy
62
+ });
63
+ userConfig.distOutputDir = ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.path) || path.resolve(process.cwd(), "dist");
64
+ },
65
+ webpack(config, { isServer }) {
66
+ var _config_output;
67
+ modifyBundlerConfig({
68
+ bundlerType,
69
+ mfConfig: isServer ? ssrConfig : csrConfig,
70
+ config,
71
+ isServer,
72
+ modernjsConfig,
73
+ remoteIpStrategy: userConfig.remoteIpStrategy
74
+ });
75
+ userConfig.distOutputDir = ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.path) || path.resolve(process.cwd(), "dist");
76
+ },
52
77
  devServer: {
53
78
  headers: {
54
79
  "Access-Control-Allow-Origin": "*",
@@ -77,6 +102,7 @@ const moduleFederationConfigPlugin = (userConfig) => ({
77
102
  var configPlugin_default = moduleFederationConfigPlugin;
78
103
  export {
79
104
  configPlugin_default as default,
105
+ modifyBundlerConfig,
80
106
  moduleFederationConfigPlugin,
81
107
  setEnv
82
108
  };
@@ -17,33 +17,37 @@ const moduleFederationPlugin = (userConfig = {}) => {
17
17
  name: "@modern-js/plugin-module-federation",
18
18
  setup: async (api) => {
19
19
  const modernjsConfig = api.getConfig();
20
- api.modifyBundlerChain((chain, { isServer }) => {
21
- const bundlerType = api.getAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
22
- console.log("index bundlerType", bundlerType);
23
- console.log("index isServer", isServer);
24
- const browserPluginOptions = internalModernPluginOptions.csrConfig;
25
- const MFPlugin = bundlerType === "webpack" ? WebpackModuleFederationPlugin : RspackModuleFederationPlugin;
26
- if (!isServer) {
27
- chain.plugin("plugin-module-federation").use(MFPlugin, [
28
- browserPluginOptions
29
- ]).init((Plugin, args) => {
30
- internalModernPluginOptions.browserPlugin = new Plugin(args[0]);
31
- return internalModernPluginOptions.browserPlugin;
32
- });
33
- }
34
- if (bundlerType === "webpack") {
35
- var _modernjsConfig_source;
36
- const enableAsyncEntry = (_modernjsConfig_source = modernjsConfig.source) === null || _modernjsConfig_source === void 0 ? void 0 : _modernjsConfig_source.enableAsyncEntry;
37
- if (!enableAsyncEntry && browserPluginOptions.async !== false) {
38
- const asyncBoundaryPluginOptions = typeof browserPluginOptions.async === "object" ? browserPluginOptions.async : {
39
- eager: (module) => module && /\.federation/.test((module === null || module === void 0 ? void 0 : module.request) || ""),
40
- excludeChunk: (chunk) => chunk.name === browserPluginOptions.name
41
- };
42
- chain.plugin("async-boundary-plugin").use(AsyncBoundaryPlugin, [
43
- asyncBoundaryPluginOptions
44
- ]);
20
+ api.config(() => {
21
+ return {
22
+ tools: {
23
+ rspack(config, { isServer }) {
24
+ const browserPluginOptions = internalModernPluginOptions.csrConfig;
25
+ if (!isServer) {
26
+ var _config_plugins;
27
+ internalModernPluginOptions.browserPlugin = new RspackModuleFederationPlugin(browserPluginOptions);
28
+ (_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(internalModernPluginOptions.browserPlugin);
29
+ }
30
+ },
31
+ webpack(config, { isServer }) {
32
+ var _modernjsConfig_source;
33
+ const browserPluginOptions = internalModernPluginOptions.csrConfig;
34
+ if (!isServer) {
35
+ var _config_plugins;
36
+ internalModernPluginOptions.browserPlugin = new WebpackModuleFederationPlugin(browserPluginOptions);
37
+ (_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(internalModernPluginOptions.browserPlugin);
38
+ }
39
+ const enableAsyncEntry = (_modernjsConfig_source = modernjsConfig.source) === null || _modernjsConfig_source === void 0 ? void 0 : _modernjsConfig_source.enableAsyncEntry;
40
+ if (!enableAsyncEntry && browserPluginOptions.async !== false) {
41
+ var _config_plugins1;
42
+ const asyncBoundaryPluginOptions = typeof browserPluginOptions.async === "object" ? browserPluginOptions.async : {
43
+ eager: (module) => module && /\.federation/.test((module === null || module === void 0 ? void 0 : module.request) || ""),
44
+ excludeChunk: (chunk) => chunk.name === browserPluginOptions.name
45
+ };
46
+ (_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(new AsyncBoundaryPlugin(asyncBoundaryPluginOptions));
47
+ }
48
+ }
45
49
  }
46
- }
50
+ };
47
51
  });
48
52
  },
49
53
  usePlugins: [
@@ -10,7 +10,6 @@ function setEnv() {
10
10
  process.env["MF_DISABLE_EMIT_STATS"] = "true";
11
11
  process.env["MF_SSR_PRJ"] = "true";
12
12
  }
13
- const CHAIN_MF_PLUGIN_ID = "plugin-module-federation-server";
14
13
  const moduleFederationSSRPlugin = (pluginOptions) => ({
15
14
  name: "@modern-js/plugin-module-federation-ssr",
16
15
  pre: [
@@ -21,8 +20,6 @@ const moduleFederationSSRPlugin = (pluginOptions) => ({
21
20
  var _pluginOptions_userConfig, _modernjsConfig_server;
22
21
  const modernjsConfig = api.getConfig();
23
22
  const enableSSR = ((_pluginOptions_userConfig = pluginOptions.userConfig) === null || _pluginOptions_userConfig === void 0 ? void 0 : _pluginOptions_userConfig.ssr) === false ? false : Boolean(modernjsConfig === null || modernjsConfig === void 0 ? void 0 : (_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
24
- console.log("enableSSR: ", enableSSR);
25
- console.log("isDev: ", isDev);
26
23
  if (!enableSSR) {
27
24
  return;
28
25
  }
@@ -44,36 +41,33 @@ const moduleFederationSSRPlugin = (pluginOptions) => ({
44
41
  plugins
45
42
  };
46
43
  });
47
- api.modifyBundlerChain((chain, { isServer }) => {
48
- const bundlerType = api.getAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
49
- console.log("ssrPlugin bundlerType: ", bundlerType);
50
- console.log("ssrPlugin isServer: ", isServer);
51
- const MFPlugin = bundlerType === "webpack" ? ModuleFederationPlugin : RspackModuleFederationPlugin;
52
- if (isServer) {
53
- if (!chain.plugins.has(CHAIN_MF_PLUGIN_ID)) {
54
- chain.plugin(CHAIN_MF_PLUGIN_ID).use(MFPlugin, [
55
- pluginOptions.ssrConfig
56
- ]).init((Plugin, args) => {
57
- pluginOptions.nodePlugin = new Plugin(args[0]);
58
- return pluginOptions.nodePlugin;
59
- });
60
- }
61
- }
62
- if (isServer) {
63
- chain.target("async-node");
64
- if (isDev) {
65
- chain.plugin("UniverseEntryChunkTrackerPlugin").use(UniverseEntryChunkTrackerPlugin);
66
- }
67
- }
68
- if (isDev && !isServer) {
69
- chain.externals({
70
- "@module-federation/node/utils": "NOT_USED_IN_BROWSER"
71
- });
72
- }
73
- });
74
44
  api.config(() => {
75
45
  return {
76
46
  tools: {
47
+ rspack(config, { isServer }) {
48
+ if (isServer) {
49
+ if (!pluginOptions.nodePlugin) {
50
+ var _config_plugins;
51
+ pluginOptions.nodePlugin = new RspackModuleFederationPlugin(pluginOptions.ssrConfig);
52
+ (_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(pluginOptions.nodePlugin);
53
+ }
54
+ } else {
55
+ var _config_output;
56
+ pluginOptions.distOutputDir = pluginOptions.distOutputDir || ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.path) || path.resolve(process.cwd(), "dist");
57
+ }
58
+ },
59
+ webpack(config, { isServer }) {
60
+ if (isServer) {
61
+ if (!pluginOptions.nodePlugin) {
62
+ var _config_plugins;
63
+ pluginOptions.nodePlugin = new ModuleFederationPlugin(pluginOptions.ssrConfig);
64
+ (_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(pluginOptions.nodePlugin);
65
+ }
66
+ } else {
67
+ var _config_output;
68
+ pluginOptions.distOutputDir = pluginOptions.distOutputDir || ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.path) || path.resolve(process.cwd(), "dist");
69
+ }
70
+ },
77
71
  devServer: {
78
72
  before: [
79
73
  (req, res, next) => {
@@ -99,6 +93,19 @@ const moduleFederationSSRPlugin = (pluginOptions) => ({
99
93
  }
100
94
  }
101
95
  ]
96
+ },
97
+ bundlerChain(chain, { isServer }) {
98
+ if (isServer) {
99
+ chain.target("async-node");
100
+ if (isDev) {
101
+ chain.plugin("UniverseEntryChunkTrackerPlugin").use(UniverseEntryChunkTrackerPlugin);
102
+ }
103
+ }
104
+ if (isDev && !isServer) {
105
+ chain.externals({
106
+ "@module-federation/node/utils": "NOT_USED_IN_BROWSER"
107
+ });
108
+ }
102
109
  }
103
110
  }
104
111
  };
@@ -115,7 +122,6 @@ const moduleFederationSSRPlugin = (pluginOptions) => ({
115
122
  });
116
123
  var ssrPlugin_default = moduleFederationSSRPlugin;
117
124
  export {
118
- CHAIN_MF_PLUGIN_ID,
119
125
  ssrPlugin_default as default,
120
126
  moduleFederationSSRPlugin,
121
127
  setEnv