@module-federation/modern-js 0.0.0-next-20250313081234 → 0.0.0-next-20250314065230

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,8 +29,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
29
29
  var configPlugin_exports = {};
30
30
  __export(configPlugin_exports, {
31
31
  default: () => configPlugin_default,
32
+ isWebTarget: () => import_utils.isWebTarget,
32
33
  moduleFederationConfigPlugin: () => moduleFederationConfigPlugin,
33
- setEnv: () => setEnv
34
+ setEnv: () => setEnv,
35
+ skipByTarget: () => import_utils.skipByTarget
34
36
  });
35
37
  module.exports = __toCommonJS(configPlugin_exports);
36
38
  var import_path = __toESM(require("path"));
@@ -60,7 +62,11 @@ const moduleFederationConfigPlugin = (userConfig) => ({
60
62
  var _userConfig_userConfig_ssr;
61
63
  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
64
  api.modifyBundlerChain((chain) => {
63
- const isWeb = (0, import_utils.isWebTarget)(chain.get("target"));
65
+ const target = chain.get("target");
66
+ if ((0, import_utils.skipByTarget)(target)) {
67
+ return;
68
+ }
69
+ const isWeb = (0, import_utils.isWebTarget)(target);
64
70
  (0, import_utils.addMyTypes2Ignored)(chain, !isWeb ? ssrConfig : csrConfig);
65
71
  const targetMFConfig = !isWeb ? ssrConfig : csrConfig;
66
72
  (0, import_utils.patchMFConfig)(targetMFConfig, !isWeb, userConfig.remoteIpStrategy || "ipv4");
@@ -116,6 +122,8 @@ const moduleFederationConfigPlugin = (userConfig) => ({
116
122
  var configPlugin_default = moduleFederationConfigPlugin;
117
123
  // Annotate the CommonJS export names for ESM import in node:
118
124
  0 && (module.exports = {
125
+ isWebTarget,
119
126
  moduleFederationConfigPlugin,
120
- setEnv
127
+ setEnv,
128
+ skipByTarget
121
129
  });
@@ -83,10 +83,14 @@ const moduleFederationSSRPlugin = (pluginOptions) => ({
83
83
  plugins
84
84
  };
85
85
  });
86
- api.modifyBundlerChain((chain, { isServer }) => {
86
+ api.modifyBundlerChain((chain) => {
87
+ const target = chain.get("target");
88
+ if ((0, import_utils2.skipByTarget)(target)) {
89
+ return;
90
+ }
87
91
  const bundlerType = api.getAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
88
92
  const MFPlugin = bundlerType === "webpack" ? import_webpack.ModuleFederationPlugin : import_rspack.ModuleFederationPlugin;
89
- const isWeb = (0, import_utils2.isWebTarget)(chain.get("target"));
93
+ const isWeb = (0, import_utils2.isWebTarget)(target);
90
94
  if (!isWeb) {
91
95
  if (!chain.plugins.has(CHAIN_MF_PLUGIN_ID)) {
92
96
  chain.plugin(CHAIN_MF_PLUGIN_ID).use(MFPlugin, [
@@ -103,12 +107,12 @@ const moduleFederationSSRPlugin = (pluginOptions) => ({
103
107
  chain.plugin("UniverseEntryChunkTrackerPlugin").use(import_universe_entry_chunk_tracker_plugin.default);
104
108
  }
105
109
  }
106
- if (import_constant.isDev && !isServer) {
110
+ if (import_constant.isDev && isWeb) {
107
111
  chain.externals({
108
112
  "@module-federation/node/utils": "NOT_USED_IN_BROWSER"
109
113
  });
110
114
  }
111
- if (isServer) {
115
+ if (!isWeb) {
112
116
  ssrOutputPath = chain.output.get("path") || import_path.default.resolve(process.cwd(), `dist/${import_constant2.MODERN_JS_SERVER_DIR}`);
113
117
  } else {
114
118
  csrOutputPath = chain.output.get("path") || import_path.default.resolve(process.cwd(), "dist");
@@ -33,7 +33,8 @@ __export(utils_exports, {
33
33
  getMFConfig: () => getMFConfig,
34
34
  isWebTarget: () => isWebTarget,
35
35
  patchBundlerConfig: () => patchBundlerConfig,
36
- patchMFConfig: () => patchMFConfig
36
+ patchMFConfig: () => patchMFConfig,
37
+ skipByTarget: () => skipByTarget
37
38
  });
38
39
  module.exports = __toCommonJS(utils_exports);
39
40
  var import_os = __toESM(require("os"));
@@ -291,11 +292,19 @@ const getIPV4 = () => {
291
292
  };
292
293
  const isWebTarget = (target) => {
293
294
  const WEB_TARGET = "web";
294
- const WEB_WORKER_TARGET = "webworker";
295
295
  if (Array.isArray(target)) {
296
- return target.includes(WEB_TARGET) || target.includes(WEB_WORKER_TARGET);
296
+ return target.includes(WEB_TARGET);
297
297
  } else if (typeof target === "string") {
298
- return target === WEB_TARGET || target === WEB_WORKER_TARGET;
298
+ return target === WEB_TARGET;
299
+ }
300
+ return false;
301
+ };
302
+ const skipByTarget = (target) => {
303
+ const IGNORE_TARGET = "webworker";
304
+ if (Array.isArray(target)) {
305
+ return target.includes(IGNORE_TARGET);
306
+ } else if (typeof target === "string") {
307
+ return target === IGNORE_TARGET;
299
308
  }
300
309
  return false;
301
310
  };
@@ -306,5 +315,6 @@ const isWebTarget = (target) => {
306
315
  getMFConfig,
307
316
  isWebTarget,
308
317
  patchBundlerConfig,
309
- patchMFConfig
318
+ patchMFConfig,
319
+ skipByTarget
310
320
  });
@@ -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 path from "path";
4
- import { patchBundlerConfig, getIPV4, getMFConfig, patchMFConfig, addMyTypes2Ignored, isWebTarget } from "./utils";
4
+ import { patchBundlerConfig, getIPV4, getMFConfig, patchMFConfig, addMyTypes2Ignored, isWebTarget, skipByTarget } from "./utils";
5
5
  function setEnv(enableSSR) {
6
6
  if (enableSSR) {
7
7
  process.env["MF_DISABLE_EMIT_STATS"] = "true";
@@ -36,7 +36,11 @@ var moduleFederationConfigPlugin = function(userConfig) {
36
36
  userConfig.csrConfig = csrConfig;
37
37
  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);
38
38
  api.modifyBundlerChain(function(chain) {
39
- var isWeb = isWebTarget(chain.get("target"));
39
+ var target = chain.get("target");
40
+ if (skipByTarget(target)) {
41
+ return;
42
+ }
43
+ var isWeb = isWebTarget(target);
40
44
  addMyTypes2Ignored(chain, !isWeb ? ssrConfig : csrConfig);
41
45
  var targetMFConfig = !isWeb ? ssrConfig : csrConfig;
42
46
  patchMFConfig(targetMFConfig, !isWeb, userConfig.remoteIpStrategy || "ipv4");
@@ -102,6 +106,8 @@ var moduleFederationConfigPlugin = function(userConfig) {
102
106
  var configPlugin_default = moduleFederationConfigPlugin;
103
107
  export {
104
108
  configPlugin_default as default,
109
+ isWebTarget,
105
110
  moduleFederationConfigPlugin,
106
- setEnv
111
+ setEnv,
112
+ skipByTarget
107
113
  };
@@ -9,7 +9,7 @@ import { updateStatsAndManifest } from "./manifest";
9
9
  import { isDev } from "./constant";
10
10
  import { MODERN_JS_SERVER_DIR } from "../constant";
11
11
  import logger from "./logger";
12
- import { isWebTarget } from "./utils";
12
+ import { isWebTarget, skipByTarget } from "./utils";
13
13
  function setEnv() {
14
14
  process.env["MF_DISABLE_EMIT_STATS"] = "true";
15
15
  process.env["MF_SSR_PRJ"] = "true";
@@ -54,11 +54,14 @@ var moduleFederationSSRPlugin = function(pluginOptions) {
54
54
  plugins
55
55
  };
56
56
  });
57
- api.modifyBundlerChain(function(chain, param) {
58
- var isServer = param.isServer;
57
+ api.modifyBundlerChain(function(chain) {
58
+ var target = chain.get("target");
59
+ if (skipByTarget(target)) {
60
+ return;
61
+ }
59
62
  var bundlerType = api.getAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
60
63
  var MFPlugin = bundlerType === "webpack" ? ModuleFederationPlugin : RspackModuleFederationPlugin;
61
- var isWeb = isWebTarget(chain.get("target"));
64
+ var isWeb = isWebTarget(target);
62
65
  if (!isWeb) {
63
66
  if (!chain.plugins.has(CHAIN_MF_PLUGIN_ID)) {
64
67
  chain.plugin(CHAIN_MF_PLUGIN_ID).use(MFPlugin, [
@@ -75,12 +78,12 @@ var moduleFederationSSRPlugin = function(pluginOptions) {
75
78
  chain.plugin("UniverseEntryChunkTrackerPlugin").use(UniverseEntryChunkTrackerPlugin);
76
79
  }
77
80
  }
78
- if (isDev && !isServer) {
81
+ if (isDev && isWeb) {
79
82
  chain.externals({
80
83
  "@module-federation/node/utils": "NOT_USED_IN_BROWSER"
81
84
  });
82
85
  }
83
- if (isServer) {
86
+ if (!isWeb) {
84
87
  ssrOutputPath = chain.output.get("path") || path.resolve(process.cwd(), "dist/".concat(MODERN_JS_SERVER_DIR));
85
88
  } else {
86
89
  csrOutputPath = chain.output.get("path") || path.resolve(process.cwd(), "dist");
@@ -282,11 +282,19 @@ var getIPV4 = function() {
282
282
  };
283
283
  var isWebTarget = function(target) {
284
284
  var WEB_TARGET = "web";
285
- var WEB_WORKER_TARGET = "webworker";
286
285
  if (Array.isArray(target)) {
287
- return target.includes(WEB_TARGET) || target.includes(WEB_WORKER_TARGET);
286
+ return target.includes(WEB_TARGET);
288
287
  } else if (typeof target === "string") {
289
- return target === WEB_TARGET || target === WEB_WORKER_TARGET;
288
+ return target === WEB_TARGET;
289
+ }
290
+ return false;
291
+ };
292
+ var skipByTarget = function(target) {
293
+ var IGNORE_TARGET = "webworker";
294
+ if (Array.isArray(target)) {
295
+ return target.includes(IGNORE_TARGET);
296
+ } else if (typeof target === "string") {
297
+ return target === IGNORE_TARGET;
290
298
  }
291
299
  return false;
292
300
  };
@@ -296,5 +304,6 @@ export {
296
304
  getMFConfig,
297
305
  isWebTarget,
298
306
  patchBundlerConfig,
299
- patchMFConfig
307
+ patchMFConfig,
308
+ skipByTarget
300
309
  };
@@ -1,5 +1,5 @@
1
1
  import path from "path";
2
- import { patchBundlerConfig, getIPV4, getMFConfig, patchMFConfig, addMyTypes2Ignored, isWebTarget } from "./utils";
2
+ import { patchBundlerConfig, getIPV4, getMFConfig, patchMFConfig, addMyTypes2Ignored, isWebTarget, skipByTarget } from "./utils";
3
3
  function setEnv(enableSSR) {
4
4
  if (enableSSR) {
5
5
  process.env["MF_DISABLE_EMIT_STATS"] = "true";
@@ -25,7 +25,11 @@ const moduleFederationConfigPlugin = (userConfig) => ({
25
25
  var _userConfig_userConfig_ssr;
26
26
  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);
27
27
  api.modifyBundlerChain((chain) => {
28
- const isWeb = isWebTarget(chain.get("target"));
28
+ const target = chain.get("target");
29
+ if (skipByTarget(target)) {
30
+ return;
31
+ }
32
+ const isWeb = isWebTarget(target);
29
33
  addMyTypes2Ignored(chain, !isWeb ? ssrConfig : csrConfig);
30
34
  const targetMFConfig = !isWeb ? ssrConfig : csrConfig;
31
35
  patchMFConfig(targetMFConfig, !isWeb, userConfig.remoteIpStrategy || "ipv4");
@@ -81,6 +85,8 @@ const moduleFederationConfigPlugin = (userConfig) => ({
81
85
  var configPlugin_default = moduleFederationConfigPlugin;
82
86
  export {
83
87
  configPlugin_default as default,
88
+ isWebTarget,
84
89
  moduleFederationConfigPlugin,
85
- setEnv
90
+ setEnv,
91
+ skipByTarget
86
92
  };
@@ -7,7 +7,7 @@ import { updateStatsAndManifest } from "./manifest";
7
7
  import { isDev } from "./constant";
8
8
  import { MODERN_JS_SERVER_DIR } from "../constant";
9
9
  import logger from "./logger";
10
- import { isWebTarget } from "./utils";
10
+ import { isWebTarget, skipByTarget } from "./utils";
11
11
  function setEnv() {
12
12
  process.env["MF_DISABLE_EMIT_STATS"] = "true";
13
13
  process.env["MF_SSR_PRJ"] = "true";
@@ -47,10 +47,14 @@ const moduleFederationSSRPlugin = (pluginOptions) => ({
47
47
  plugins
48
48
  };
49
49
  });
50
- api.modifyBundlerChain((chain, { isServer }) => {
50
+ api.modifyBundlerChain((chain) => {
51
+ const target = chain.get("target");
52
+ if (skipByTarget(target)) {
53
+ return;
54
+ }
51
55
  const bundlerType = api.getAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
52
56
  const MFPlugin = bundlerType === "webpack" ? ModuleFederationPlugin : RspackModuleFederationPlugin;
53
- const isWeb = isWebTarget(chain.get("target"));
57
+ const isWeb = isWebTarget(target);
54
58
  if (!isWeb) {
55
59
  if (!chain.plugins.has(CHAIN_MF_PLUGIN_ID)) {
56
60
  chain.plugin(CHAIN_MF_PLUGIN_ID).use(MFPlugin, [
@@ -67,12 +71,12 @@ const moduleFederationSSRPlugin = (pluginOptions) => ({
67
71
  chain.plugin("UniverseEntryChunkTrackerPlugin").use(UniverseEntryChunkTrackerPlugin);
68
72
  }
69
73
  }
70
- if (isDev && !isServer) {
74
+ if (isDev && isWeb) {
71
75
  chain.externals({
72
76
  "@module-federation/node/utils": "NOT_USED_IN_BROWSER"
73
77
  });
74
78
  }
75
- if (isServer) {
79
+ if (!isWeb) {
76
80
  ssrOutputPath = chain.output.get("path") || path.resolve(process.cwd(), `dist/${MODERN_JS_SERVER_DIR}`);
77
81
  } else {
78
82
  csrOutputPath = chain.output.get("path") || path.resolve(process.cwd(), "dist");
@@ -253,11 +253,19 @@ const getIPV4 = () => {
253
253
  };
254
254
  const isWebTarget = (target) => {
255
255
  const WEB_TARGET = "web";
256
- const WEB_WORKER_TARGET = "webworker";
257
256
  if (Array.isArray(target)) {
258
- return target.includes(WEB_TARGET) || target.includes(WEB_WORKER_TARGET);
257
+ return target.includes(WEB_TARGET);
259
258
  } else if (typeof target === "string") {
260
- return target === WEB_TARGET || target === WEB_WORKER_TARGET;
259
+ return target === WEB_TARGET;
260
+ }
261
+ return false;
262
+ };
263
+ const skipByTarget = (target) => {
264
+ const IGNORE_TARGET = "webworker";
265
+ if (Array.isArray(target)) {
266
+ return target.includes(IGNORE_TARGET);
267
+ } else if (typeof target === "string") {
268
+ return target === IGNORE_TARGET;
261
269
  }
262
270
  return false;
263
271
  };
@@ -267,5 +275,6 @@ export {
267
275
  getMFConfig,
268
276
  isWebTarget,
269
277
  patchBundlerConfig,
270
- patchMFConfig
278
+ patchMFConfig,
279
+ skipByTarget
271
280
  };
@@ -1,5 +1,7 @@
1
1
  import type { CliPluginFuture, AppTools } from '@modern-js/app-tools';
2
2
  import type { InternalModernPluginOptions } from '../types';
3
+ import { isWebTarget, skipByTarget } from './utils';
3
4
  export declare function setEnv(enableSSR: boolean): void;
4
5
  export declare const moduleFederationConfigPlugin: (userConfig: InternalModernPluginOptions) => CliPluginFuture<AppTools>;
5
6
  export default moduleFederationConfigPlugin;
7
+ export { isWebTarget, skipByTarget };
@@ -15,3 +15,4 @@ export declare function patchBundlerConfig(options: {
15
15
  }): void;
16
16
  export declare const getIPV4: () => string;
17
17
  export declare const isWebTarget: (target: string[] | string) => boolean;
18
+ export declare const skipByTarget: (target: string[] | string) => boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/modern-js",
3
- "version": "0.0.0-next-20250313081234",
3
+ "version": "0.0.0-next-20250314065230",
4
4
  "files": [
5
5
  "dist/",
6
6
  "types.d.ts",
@@ -89,10 +89,10 @@
89
89
  "@swc/helpers": "0.5.13",
90
90
  "node-fetch": "~3.3.0",
91
91
  "react-error-boundary": "4.1.2",
92
- "@module-federation/rsbuild-plugin": "0.0.0-next-20250313081234",
93
- "@module-federation/enhanced": "0.0.0-next-20250313081234",
94
- "@module-federation/node": "0.0.0-next-20250313081234",
95
- "@module-federation/sdk": "0.0.0-next-20250313081234"
92
+ "@module-federation/rsbuild-plugin": "0.0.0-next-20250314065230",
93
+ "@module-federation/enhanced": "0.0.0-next-20250314065230",
94
+ "@module-federation/node": "0.0.0-next-20250314065230",
95
+ "@module-federation/sdk": "0.0.0-next-20250314065230"
96
96
  },
97
97
  "devDependencies": {
98
98
  "@modern-js/app-tools": "2.65.1",
@@ -100,7 +100,7 @@
100
100
  "@modern-js/module-tools": "2.65.1",
101
101
  "@modern-js/runtime": "2.65.1",
102
102
  "@modern-js/tsconfig": "2.65.1",
103
- "@module-federation/manifest": "0.0.0-next-20250313081234"
103
+ "@module-federation/manifest": "0.0.0-next-20250314065230"
104
104
  },
105
105
  "peerDependencies": {
106
106
  "react": ">=17",