@module-federation/modern-js 0.0.0-next-20250221090527 → 0.0.0-next-20250221091229

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.
@@ -29,6 +29,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
29
29
  var configPlugin_exports = {};
30
30
  __export(configPlugin_exports, {
31
31
  default: () => configPlugin_default,
32
+ modifyBundlerConfig: () => modifyBundlerConfig,
32
33
  moduleFederationConfigPlugin: () => moduleFederationConfigPlugin,
33
34
  setEnv: () => setEnv
34
35
  });
@@ -41,6 +42,17 @@ function setEnv(enableSSR) {
41
42
  process.env["MF_SSR_PRJ"] = "true";
42
43
  }
43
44
  }
45
+ function modifyBundlerConfig(options) {
46
+ const { mfConfig, config, isServer, modernjsConfig, remoteIpStrategy = "ipv4", bundlerType } = options;
47
+ (0, import_utils.patchMFConfig)(mfConfig, isServer, remoteIpStrategy);
48
+ (0, import_utils.patchBundlerConfig)({
49
+ bundlerType,
50
+ bundlerConfig: config,
51
+ isServer,
52
+ modernjsConfig,
53
+ mfConfig
54
+ });
55
+ }
44
56
  const moduleFederationConfigPlugin = (userConfig) => ({
45
57
  name: "@modern-js/plugin-module-federation-config",
46
58
  pre: [
@@ -50,33 +62,17 @@ const moduleFederationConfigPlugin = (userConfig) => ({
50
62
  "@modern-js/plugin-module-federation"
51
63
  ],
52
64
  setup: async (api) => {
53
- var _userConfig_userConfig, _modernjsConfig_server;
54
65
  const modernjsConfig = api.getConfig();
55
66
  const mfConfig = await (0, import_utils.getMFConfig)(userConfig.originPluginOptions);
56
67
  const csrConfig = userConfig.csrConfig || JSON.parse(JSON.stringify(mfConfig));
57
68
  const ssrConfig = userConfig.ssrConfig || JSON.parse(JSON.stringify(mfConfig));
58
69
  userConfig.ssrConfig = ssrConfig;
59
70
  userConfig.csrConfig = csrConfig;
60
- var _userConfig_userConfig_ssr;
61
- const enableSSR = (_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);
62
- api.modifyBundlerChain((chain, { isProd, isServer }) => {
63
- (0, import_utils.addMyTypes2Ignored)(chain, isServer ? ssrConfig : csrConfig);
64
- const targetMFConfig = isServer ? ssrConfig : csrConfig;
65
- (0, import_utils.patchMFConfig)(targetMFConfig, isServer, userConfig.remoteIpStrategy || "ipv4");
66
- (0, import_utils.patchBundlerConfig)({
67
- // @ts-expect-error chain type is not correct
68
- chain,
69
- isServer,
70
- modernjsConfig,
71
- mfConfig,
72
- enableSSR
73
- });
74
- userConfig.distOutputDir = chain.output.get("path") || import_path.default.resolve(process.cwd(), "dist");
75
- });
76
71
  api.config(() => {
77
- var _modernjsConfig_source, _modernjsConfig_source1, _modernjsConfig_dev;
72
+ var _userConfig_userConfig, _modernjsConfig_server, _modernjsConfig_source, _modernjsConfig_source1, _modernjsConfig_dev;
78
73
  const bundlerType = api.getAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
79
74
  const ipv4 = (0, import_utils.getIPV4)();
75
+ const enableSSR = ((_userConfig_userConfig = userConfig.userConfig) === null || _userConfig_userConfig === void 0 ? void 0 : _userConfig_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);
80
76
  if (userConfig.remoteIpStrategy === void 0) {
81
77
  if (!enableSSR) {
82
78
  userConfig.remoteIpStrategy = "inherit";
@@ -87,6 +83,33 @@ const moduleFederationConfigPlugin = (userConfig) => ({
87
83
  var _modernjsConfig_source_enableAsyncEntry;
88
84
  return {
89
85
  tools: {
86
+ bundlerChain(chain, { isServer }) {
87
+ (0, import_utils.addMyTypes2Ignored)(chain, isServer ? ssrConfig : csrConfig);
88
+ },
89
+ rspack(config, { isServer }) {
90
+ var _config_output;
91
+ modifyBundlerConfig({
92
+ bundlerType,
93
+ mfConfig: isServer ? ssrConfig : csrConfig,
94
+ config,
95
+ isServer,
96
+ modernjsConfig,
97
+ remoteIpStrategy: userConfig.remoteIpStrategy
98
+ });
99
+ userConfig.distOutputDir = ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.path) || import_path.default.resolve(process.cwd(), "dist");
100
+ },
101
+ webpack(config, { isServer }) {
102
+ var _config_output;
103
+ modifyBundlerConfig({
104
+ bundlerType,
105
+ mfConfig: isServer ? ssrConfig : csrConfig,
106
+ config,
107
+ isServer,
108
+ modernjsConfig,
109
+ remoteIpStrategy: userConfig.remoteIpStrategy
110
+ });
111
+ userConfig.distOutputDir = ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.path) || import_path.default.resolve(process.cwd(), "dist");
112
+ },
90
113
  devServer: {
91
114
  headers: {
92
115
  "Access-Control-Allow-Origin": "*",
@@ -115,6 +138,7 @@ const moduleFederationConfigPlugin = (userConfig) => ({
115
138
  var configPlugin_default = moduleFederationConfigPlugin;
116
139
  // Annotate the CommonJS export names for ESM import in node:
117
140
  0 && (module.exports = {
141
+ modifyBundlerConfig,
118
142
  moduleFederationConfigPlugin,
119
143
  setEnv
120
144
  });
@@ -43,31 +43,37 @@ const moduleFederationPlugin = (userConfig = {}) => {
43
43
  name: "@modern-js/plugin-module-federation",
44
44
  setup: async (api) => {
45
45
  const modernjsConfig = api.getConfig();
46
- api.modifyBundlerChain((chain, { isServer }) => {
47
- const bundlerType = api.getAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
48
- const browserPluginOptions = internalModernPluginOptions.csrConfig;
49
- const MFPlugin = bundlerType === "webpack" ? import_enhanced.ModuleFederationPlugin : import_rspack.ModuleFederationPlugin;
50
- if (!isServer) {
51
- chain.plugin("plugin-module-federation").use(MFPlugin, [
52
- browserPluginOptions
53
- ]).init((Plugin, args) => {
54
- internalModernPluginOptions.browserPlugin = new Plugin(args[0]);
55
- return internalModernPluginOptions.browserPlugin;
56
- });
57
- }
58
- if (bundlerType === "webpack") {
59
- var _modernjsConfig_source;
60
- const enableAsyncEntry = (_modernjsConfig_source = modernjsConfig.source) === null || _modernjsConfig_source === void 0 ? void 0 : _modernjsConfig_source.enableAsyncEntry;
61
- if (!enableAsyncEntry && browserPluginOptions.async !== false) {
62
- const asyncBoundaryPluginOptions = typeof browserPluginOptions.async === "object" ? browserPluginOptions.async : {
63
- eager: (module2) => module2 && /\.federation/.test((module2 === null || module2 === void 0 ? void 0 : module2.request) || ""),
64
- excludeChunk: (chunk) => chunk.name === browserPluginOptions.name
65
- };
66
- chain.plugin("async-boundary-plugin").use(import_enhanced.AsyncBoundaryPlugin, [
67
- asyncBoundaryPluginOptions
68
- ]);
46
+ api.config(() => {
47
+ return {
48
+ tools: {
49
+ rspack(config, { isServer }) {
50
+ const browserPluginOptions = internalModernPluginOptions.csrConfig;
51
+ if (!isServer) {
52
+ var _config_plugins;
53
+ internalModernPluginOptions.browserPlugin = new import_rspack.ModuleFederationPlugin(browserPluginOptions);
54
+ (_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(internalModernPluginOptions.browserPlugin);
55
+ }
56
+ },
57
+ webpack(config, { isServer }) {
58
+ var _modernjsConfig_source;
59
+ const browserPluginOptions = internalModernPluginOptions.csrConfig;
60
+ if (!isServer) {
61
+ var _config_plugins;
62
+ internalModernPluginOptions.browserPlugin = new import_enhanced.ModuleFederationPlugin(browserPluginOptions);
63
+ (_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(internalModernPluginOptions.browserPlugin);
64
+ }
65
+ const enableAsyncEntry = (_modernjsConfig_source = modernjsConfig.source) === null || _modernjsConfig_source === void 0 ? void 0 : _modernjsConfig_source.enableAsyncEntry;
66
+ if (!enableAsyncEntry && browserPluginOptions.async !== false) {
67
+ var _config_plugins1;
68
+ const asyncBoundaryPluginOptions = typeof browserPluginOptions.async === "object" ? browserPluginOptions.async : {
69
+ eager: (module2) => module2 && /\.federation/.test((module2 === null || module2 === void 0 ? void 0 : module2.request) || ""),
70
+ excludeChunk: (chunk) => chunk.name === browserPluginOptions.name
71
+ };
72
+ (_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(new import_enhanced.AsyncBoundaryPlugin(asyncBoundaryPluginOptions));
73
+ }
74
+ }
69
75
  }
70
- }
76
+ };
71
77
  });
72
78
  },
73
79
  usePlugins: [
@@ -33,26 +33,27 @@ __export(manifest_exports, {
33
33
  module.exports = __toCommonJS(manifest_exports);
34
34
  var import_path = __toESM(require("path"));
35
35
  var import_utils = require("@modern-js/utils");
36
- function mergeStats(browserStats, nodeStats, ssrDir) {
36
+ var import_constant = require("../constant");
37
+ function mergeStats(browserStats, nodeStats) {
37
38
  const ssrRemoteEntry = nodeStats.metaData.remoteEntry;
38
- ssrRemoteEntry.path = ssrDir;
39
+ ssrRemoteEntry.path = import_constant.MODERN_JS_SERVER_DIR;
39
40
  browserStats.metaData.ssrRemoteEntry = ssrRemoteEntry;
40
41
  return browserStats;
41
42
  }
42
- function mergeManifest(browserManifest, nodeManifest, ssrDir) {
43
+ function mergeManifest(browserManifest, nodeManifest) {
43
44
  const ssrRemoteEntry = nodeManifest.metaData.remoteEntry;
44
- ssrRemoteEntry.path = ssrDir;
45
+ ssrRemoteEntry.path = import_constant.MODERN_JS_SERVER_DIR;
45
46
  browserManifest.metaData.ssrRemoteEntry = ssrRemoteEntry;
46
47
  return browserManifest;
47
48
  }
48
- function mergeStatsAndManifest(nodePlugin, browserPlugin, ssrDir) {
49
+ function mergeStatsAndManifest(nodePlugin, browserPlugin) {
49
50
  const nodeResourceInfo = nodePlugin.statsResourceInfo;
50
51
  const browserResourceInfo = browserPlugin.statsResourceInfo;
51
52
  if (!browserResourceInfo || !nodeResourceInfo || !browserResourceInfo.stats || !nodeResourceInfo.stats || !browserResourceInfo.manifest || !nodeResourceInfo.manifest) {
52
53
  throw new Error("can not get browserResourceInfo or nodeResourceInfo");
53
54
  }
54
- const mergedStats = mergeStats(browserResourceInfo.stats.stats, nodeResourceInfo.stats.stats, ssrDir);
55
- const mergedManifest = mergeManifest(browserResourceInfo.manifest.manifest, nodeResourceInfo.manifest.manifest, ssrDir);
55
+ const mergedStats = mergeStats(browserResourceInfo.stats.stats, nodeResourceInfo.stats.stats);
56
+ const mergedManifest = mergeManifest(browserResourceInfo.manifest.manifest, nodeResourceInfo.manifest.manifest);
56
57
  return {
57
58
  mergedStats,
58
59
  mergedStatsFilePath: browserResourceInfo.stats.filename,
@@ -60,8 +61,8 @@ function mergeStatsAndManifest(nodePlugin, browserPlugin, ssrDir) {
60
61
  mergedManifestFilePath: browserResourceInfo.manifest.filename
61
62
  };
62
63
  }
63
- function updateStatsAndManifest(nodePlugin, browserPlugin, outputDir, ssrDir) {
64
- const { mergedStats, mergedStatsFilePath, mergedManifest, mergedManifestFilePath } = mergeStatsAndManifest(nodePlugin, browserPlugin, ssrDir);
64
+ function updateStatsAndManifest(nodePlugin, browserPlugin, outputDir) {
65
+ const { mergedStats, mergedStatsFilePath, mergedManifest, mergedManifestFilePath } = mergeStatsAndManifest(nodePlugin, browserPlugin);
65
66
  import_utils.fs.writeFileSync(import_path.default.resolve(outputDir, mergedStatsFilePath), JSON.stringify(mergedStats, null, 2));
66
67
  import_utils.fs.writeFileSync(import_path.default.resolve(outputDir, mergedManifestFilePath), JSON.stringify(mergedManifest, null, 2));
67
68
  }
@@ -28,7 +28,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
  var ssrPlugin_exports = {};
30
30
  __export(ssrPlugin_exports, {
31
- CHAIN_MF_PLUGIN_ID: () => CHAIN_MF_PLUGIN_ID,
32
31
  default: () => ssrPlugin_default,
33
32
  moduleFederationSSRPlugin: () => moduleFederationSSRPlugin,
34
33
  setEnv: () => setEnv
@@ -41,13 +40,11 @@ var import_rspack = require("@module-federation/enhanced/rspack");
41
40
  var import_universe_entry_chunk_tracker_plugin = __toESM(require("@module-federation/node/universe-entry-chunk-tracker-plugin"));
42
41
  var import_manifest = require("./manifest");
43
42
  var import_constant = require("./constant");
44
- var import_constant2 = require("../constant");
45
43
  var import_logger = __toESM(require("./logger"));
46
44
  function setEnv() {
47
45
  process.env["MF_DISABLE_EMIT_STATS"] = "true";
48
46
  process.env["MF_SSR_PRJ"] = "true";
49
47
  }
50
- const CHAIN_MF_PLUGIN_ID = "plugin-module-federation-server";
51
48
  const moduleFederationSSRPlugin = (pluginOptions) => ({
52
49
  name: "@modern-js/plugin-module-federation-ssr",
53
50
  pre: [
@@ -57,10 +54,7 @@ const moduleFederationSSRPlugin = (pluginOptions) => ({
57
54
  setup: async (api) => {
58
55
  var _pluginOptions_userConfig, _modernjsConfig_server;
59
56
  const modernjsConfig = api.getConfig();
60
- var _pluginOptions_userConfig_ssr;
61
- const 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);
62
- let csrOutputPath = "";
63
- let ssrOutputPath = "";
57
+ 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);
64
58
  if (!enableSSR) {
65
59
  return;
66
60
  }
@@ -82,39 +76,33 @@ const moduleFederationSSRPlugin = (pluginOptions) => ({
82
76
  plugins
83
77
  };
84
78
  });
85
- api.modifyBundlerChain((chain, { isServer }) => {
86
- const bundlerType = api.getAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
87
- const MFPlugin = bundlerType === "webpack" ? import_webpack.ModuleFederationPlugin : import_rspack.ModuleFederationPlugin;
88
- if (isServer) {
89
- if (!chain.plugins.has(CHAIN_MF_PLUGIN_ID)) {
90
- chain.plugin(CHAIN_MF_PLUGIN_ID).use(MFPlugin, [
91
- pluginOptions.ssrConfig
92
- ]).init((Plugin, args) => {
93
- pluginOptions.nodePlugin = new Plugin(args[0]);
94
- return pluginOptions.nodePlugin;
95
- });
96
- }
97
- }
98
- if (isServer) {
99
- chain.target("async-node");
100
- if (import_constant.isDev) {
101
- chain.plugin("UniverseEntryChunkTrackerPlugin").use(import_universe_entry_chunk_tracker_plugin.default);
102
- }
103
- }
104
- if (import_constant.isDev && !isServer) {
105
- chain.externals({
106
- "@module-federation/node/utils": "NOT_USED_IN_BROWSER"
107
- });
108
- }
109
- if (isServer) {
110
- ssrOutputPath = chain.output.get("path") || import_path.default.resolve(process.cwd(), `dist/${import_constant2.MODERN_JS_SERVER_DIR}`);
111
- } else {
112
- csrOutputPath = chain.output.get("path") || import_path.default.resolve(process.cwd(), "dist");
113
- }
114
- });
115
79
  api.config(() => {
116
80
  return {
117
81
  tools: {
82
+ rspack(config, { isServer }) {
83
+ if (isServer) {
84
+ if (!pluginOptions.nodePlugin) {
85
+ var _config_plugins;
86
+ pluginOptions.nodePlugin = new import_rspack.ModuleFederationPlugin(pluginOptions.ssrConfig);
87
+ (_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(pluginOptions.nodePlugin);
88
+ }
89
+ } else {
90
+ var _config_output;
91
+ pluginOptions.distOutputDir = pluginOptions.distOutputDir || ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.path) || import_path.default.resolve(process.cwd(), "dist");
92
+ }
93
+ },
94
+ webpack(config, { isServer }) {
95
+ if (isServer) {
96
+ if (!pluginOptions.nodePlugin) {
97
+ var _config_plugins;
98
+ pluginOptions.nodePlugin = new import_webpack.ModuleFederationPlugin(pluginOptions.ssrConfig);
99
+ (_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(pluginOptions.nodePlugin);
100
+ }
101
+ } else {
102
+ var _config_output;
103
+ pluginOptions.distOutputDir = pluginOptions.distOutputDir || ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.path) || import_path.default.resolve(process.cwd(), "dist");
104
+ }
105
+ },
118
106
  devServer: {
119
107
  before: [
120
108
  (req, res, next) => {
@@ -140,24 +128,36 @@ const moduleFederationSSRPlugin = (pluginOptions) => ({
140
128
  }
141
129
  }
142
130
  ]
131
+ },
132
+ bundlerChain(chain, { isServer }) {
133
+ if (isServer) {
134
+ chain.target("async-node");
135
+ if (import_constant.isDev) {
136
+ chain.plugin("UniverseEntryChunkTrackerPlugin").use(import_universe_entry_chunk_tracker_plugin.default);
137
+ }
138
+ }
139
+ if (import_constant.isDev && !isServer) {
140
+ chain.externals({
141
+ "@module-federation/node/utils": "NOT_USED_IN_BROWSER"
142
+ });
143
+ }
143
144
  }
144
145
  }
145
146
  };
146
147
  });
147
148
  api.onAfterBuild(() => {
148
149
  const { nodePlugin, browserPlugin, distOutputDir } = pluginOptions;
149
- (0, import_manifest.updateStatsAndManifest)(nodePlugin, browserPlugin, distOutputDir, import_path.default.relative(csrOutputPath, ssrOutputPath));
150
+ (0, import_manifest.updateStatsAndManifest)(nodePlugin, browserPlugin, distOutputDir);
150
151
  });
151
152
  api.onDevCompileDone(() => {
152
153
  const { nodePlugin, browserPlugin, distOutputDir } = pluginOptions;
153
- (0, import_manifest.updateStatsAndManifest)(nodePlugin, browserPlugin, distOutputDir, import_path.default.relative(csrOutputPath, ssrOutputPath));
154
+ (0, import_manifest.updateStatsAndManifest)(nodePlugin, browserPlugin, distOutputDir);
154
155
  });
155
156
  }
156
157
  });
157
158
  var ssrPlugin_default = moduleFederationSSRPlugin;
158
159
  // Annotate the CommonJS export names for ESM import in node:
159
160
  0 && (module.exports = {
160
- CHAIN_MF_PLUGIN_ID,
161
161
  moduleFederationSSRPlugin,
162
162
  setEnv
163
163
  });
@@ -32,6 +32,7 @@ __export(utils_exports, {
32
32
  getIPV4: () => getIPV4,
33
33
  getMFConfig: () => getMFConfig,
34
34
  patchBundlerConfig: () => patchBundlerConfig,
35
+ patchIgnoreWarning: () => patchIgnoreWarning,
35
36
  patchMFConfig: () => patchMFConfig
36
37
  });
37
38
  module.exports = __toCommonJS(utils_exports);
@@ -172,20 +173,19 @@ const patchMFConfig = (mfConfig, isServer, remoteIpStrategy) => {
172
173
  mfConfig.dev = false;
173
174
  return mfConfig;
174
175
  };
175
- function patchIgnoreWarning(chain) {
176
- const ignoreWarnings = chain.get("ignoreWarnings") || [];
176
+ function patchIgnoreWarning(bundlerConfig) {
177
+ bundlerConfig.ignoreWarnings = bundlerConfig.ignoreWarnings || [];
177
178
  const ignoredMsgs = [
178
179
  "external script",
179
180
  "process.env.WS_NO_BUFFER_UTIL",
180
181
  `Can't resolve 'utf-8-validate`
181
182
  ];
182
- ignoreWarnings.push((warning) => {
183
+ bundlerConfig.ignoreWarnings.push((warning) => {
183
184
  if (ignoredMsgs.some((msg) => warning.message.includes(msg))) {
184
185
  return true;
185
186
  }
186
187
  return false;
187
188
  });
188
- chain.ignoreWarnings(ignoreWarnings);
189
189
  }
190
190
  function addMyTypes2Ignored(chain, mfConfig) {
191
191
  const watchOptions = chain.get("watchOptions");
@@ -224,43 +224,55 @@ function addMyTypes2Ignored(chain, mfConfig) {
224
224
  });
225
225
  }
226
226
  function patchBundlerConfig(options) {
227
- var _modernjsConfig_deploy;
228
- const { chain, modernjsConfig, isServer, mfConfig, enableSSR } = options;
229
- chain.optimization.delete("runtimeChunk");
230
- patchIgnoreWarning(chain);
231
- if (!chain.output.get("chunkLoadingGlobal")) {
232
- chain.output.chunkLoadingGlobal(`chunk_${mfConfig.name}`);
233
- }
234
- if (!chain.output.get("uniqueName")) {
235
- chain.output.uniqueName(mfConfig.name);
227
+ var _modernjsConfig_server, _bundlerConfig_optimization, _bundlerConfig_optimization1, _bundlerConfig_output, _modernjsConfig_deploy;
228
+ const { bundlerConfig, modernjsConfig, isServer, mfConfig, bundlerType } = options;
229
+ const enableSSR = Boolean((_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
230
+ (_bundlerConfig_optimization = bundlerConfig.optimization) === null || _bundlerConfig_optimization === void 0 ? true : delete _bundlerConfig_optimization.runtimeChunk;
231
+ patchIgnoreWarning(bundlerConfig);
232
+ if (bundlerConfig.output) {
233
+ var _bundlerConfig_output1, _bundlerConfig_output2;
234
+ if (!((_bundlerConfig_output1 = bundlerConfig.output) === null || _bundlerConfig_output1 === void 0 ? void 0 : _bundlerConfig_output1.chunkLoadingGlobal)) {
235
+ bundlerConfig.output.chunkLoadingGlobal = `chunk_${mfConfig.name}`;
236
+ }
237
+ if (!((_bundlerConfig_output2 = bundlerConfig.output) === null || _bundlerConfig_output2 === void 0 ? void 0 : _bundlerConfig_output2.uniqueName)) {
238
+ bundlerConfig.output.uniqueName = mfConfig.name;
239
+ }
236
240
  }
237
- const splitChunkConfig = chain.optimization.splitChunks.entries();
238
241
  if (!isServer) {
239
- (0, import_utils.autoDeleteSplitChunkCacheGroups)(mfConfig, splitChunkConfig);
242
+ (0, import_utils.autoDeleteSplitChunkCacheGroups)(mfConfig, bundlerConfig);
240
243
  }
241
- if (!isServer && enableSSR && splitChunkConfig && typeof splitChunkConfig === "object" && splitChunkConfig.cacheGroups) {
242
- splitChunkConfig.chunks = "async";
244
+ if (!isServer && enableSSR && typeof ((_bundlerConfig_optimization1 = bundlerConfig.optimization) === null || _bundlerConfig_optimization1 === void 0 ? void 0 : _bundlerConfig_optimization1.splitChunks) === "object" && bundlerConfig.optimization.splitChunks.cacheGroups) {
245
+ bundlerConfig.optimization.splitChunks.chunks = "async";
243
246
  import_logger.default.warn(`splitChunks.chunks = async is not allowed with stream SSR mode, it will auto changed to "async"`);
244
247
  }
245
- if (isDev && chain.output.get("publicPath") === "auto") {
246
- var _modernjsConfig_dev, _modernjsConfig_server;
247
- 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;
248
+ if (isDev && ((_bundlerConfig_output = bundlerConfig.output) === null || _bundlerConfig_output === void 0 ? void 0 : _bundlerConfig_output.publicPath) === "auto") {
249
+ var _modernjsConfig_dev, _modernjsConfig_server1;
250
+ const 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;
248
251
  const publicPath = `http://localhost:${port}/`;
249
- chain.output.publicPath(publicPath);
252
+ bundlerConfig.output.publicPath = publicPath;
250
253
  }
251
254
  if (isServer && enableSSR) {
252
- const uniqueName = mfConfig.name || chain.output.get("uniqueName");
253
- const chunkFileName = chain.output.get("chunkFilename");
254
- if (typeof chunkFileName === "string" && uniqueName && !chunkFileName.includes(uniqueName)) {
255
+ const { output } = bundlerConfig;
256
+ const uniqueName = mfConfig.name || (output === null || output === void 0 ? void 0 : output.uniqueName);
257
+ const chunkFileName = output === null || output === void 0 ? void 0 : output.chunkFilename;
258
+ if (output && typeof chunkFileName === "string" && uniqueName && !chunkFileName.includes(uniqueName)) {
255
259
  const suffix = `${(0, import_sdk.encodeName)(uniqueName)}-[chunkhash].js`;
256
- chain.output.chunkFilename(chunkFileName.replace(".js", suffix));
260
+ output.chunkFilename = chunkFileName.replace(".js", suffix);
257
261
  }
258
262
  }
259
263
  if (isDev && enableSSR && !isServer) {
260
- chain.resolve.fallback.set("crypto", false).set("stream", false).set("vm", false);
264
+ bundlerConfig.resolve.fallback = {
265
+ ...bundlerConfig.resolve.fallback,
266
+ crypto: false,
267
+ stream: false,
268
+ vm: false
269
+ };
261
270
  }
262
271
  if (((_modernjsConfig_deploy = modernjsConfig.deploy) === null || _modernjsConfig_deploy === void 0 ? void 0 : _modernjsConfig_deploy.microFrontend) && Object.keys(mfConfig.exposes || {}).length) {
263
- chain.optimization.usedExports(false);
272
+ if (!bundlerConfig.optimization) {
273
+ bundlerConfig.optimization = {};
274
+ }
275
+ bundlerConfig.optimization.usedExports = false;
264
276
  }
265
277
  }
266
278
  const localIpv4 = "127.0.0.1";
@@ -288,11 +300,34 @@ const getIPV4 = () => {
288
300
  };
289
301
  return ipv4Interface.address;
290
302
  };
303
+ const SPLIT_CHUNK_MAP = {
304
+ REACT: "react",
305
+ ROUTER: "router",
306
+ LODASH: "lib-lodash",
307
+ ANTD: "lib-antd",
308
+ ARCO: "lib-arco",
309
+ SEMI: "lib-semi",
310
+ AXIOS: "lib-axios"
311
+ };
312
+ const SHARED_SPLIT_CHUNK_MAP = {
313
+ react: SPLIT_CHUNK_MAP.REACT,
314
+ "react-dom": SPLIT_CHUNK_MAP.REACT,
315
+ "react-router": SPLIT_CHUNK_MAP.ROUTER,
316
+ "react-router-dom": SPLIT_CHUNK_MAP.ROUTER,
317
+ "@remix-run/router": SPLIT_CHUNK_MAP.ROUTER,
318
+ lodash: SPLIT_CHUNK_MAP.LODASH,
319
+ "lodash-es": SPLIT_CHUNK_MAP.LODASH,
320
+ antd: SPLIT_CHUNK_MAP.ANTD,
321
+ "@arco-design/web-react": SPLIT_CHUNK_MAP.ARCO,
322
+ "@douyinfe/semi-ui": SPLIT_CHUNK_MAP.SEMI,
323
+ axios: SPLIT_CHUNK_MAP.AXIOS
324
+ };
291
325
  // Annotate the CommonJS export names for ESM import in node:
292
326
  0 && (module.exports = {
293
327
  addMyTypes2Ignored,
294
328
  getIPV4,
295
329
  getMFConfig,
296
330
  patchBundlerConfig,
331
+ patchIgnoreWarning,
297
332
  patchMFConfig
298
333
  });
@@ -109,3 +109,63 @@ const mfConfig = {
109
109
  });
110
110
  });
111
111
  });
112
+ (0, import_vitest.describe)("patchBundlerConfig", async () => {
113
+ (0, import_vitest.it)("patchBundlerConfig: server", async () => {
114
+ const bundlerConfig = {
115
+ output: {
116
+ publicPath: "auto"
117
+ }
118
+ };
119
+ (0, import_utils.patchBundlerConfig)({
120
+ bundlerType: "webpack",
121
+ bundlerConfig,
122
+ isServer: true,
123
+ modernjsConfig: {
124
+ server: {
125
+ ssr: {
126
+ mode: "stream"
127
+ }
128
+ }
129
+ },
130
+ mfConfig
131
+ });
132
+ const expectedConfig = {
133
+ output: {
134
+ chunkLoadingGlobal: "chunk_host",
135
+ publicPath: "auto",
136
+ uniqueName: "host"
137
+ }
138
+ };
139
+ bundlerConfig === null || bundlerConfig === void 0 ? true : delete bundlerConfig.ignoreWarnings;
140
+ (0, import_vitest.expect)(bundlerConfig).toStrictEqual(expectedConfig);
141
+ });
142
+ (0, import_vitest.it)("patchBundlerConfig: client", async () => {
143
+ const bundlerConfig = {
144
+ output: {
145
+ publicPath: "auto"
146
+ }
147
+ };
148
+ (0, import_utils.patchBundlerConfig)({
149
+ bundlerType: "webpack",
150
+ bundlerConfig,
151
+ isServer: false,
152
+ modernjsConfig: {
153
+ server: {
154
+ ssr: {
155
+ mode: "stream"
156
+ }
157
+ }
158
+ },
159
+ mfConfig
160
+ });
161
+ const expectedConfig = {
162
+ output: {
163
+ chunkLoadingGlobal: "chunk_host",
164
+ publicPath: "auto",
165
+ uniqueName: "host"
166
+ }
167
+ };
168
+ bundlerConfig === null || bundlerConfig === void 0 ? true : delete bundlerConfig.ignoreWarnings;
169
+ (0, import_vitest.expect)(bundlerConfig).toStrictEqual(expectedConfig);
170
+ });
171
+ });