@module-federation/modern-js 0.10.0 → 0.11.1

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"));
@@ -59,14 +61,19 @@ const moduleFederationConfigPlugin = (userConfig) => ({
59
61
  userConfig.csrConfig = csrConfig;
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
- api.modifyBundlerChain((chain, { 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");
64
+ api.modifyBundlerChain((chain) => {
65
+ const target = chain.get("target");
66
+ if ((0, import_utils.skipByTarget)(target)) {
67
+ return;
68
+ }
69
+ const isWeb = (0, import_utils.isWebTarget)(target);
70
+ (0, import_utils.addMyTypes2Ignored)(chain, !isWeb ? ssrConfig : csrConfig);
71
+ const targetMFConfig = !isWeb ? ssrConfig : csrConfig;
72
+ (0, import_utils.patchMFConfig)(targetMFConfig, !isWeb, userConfig.remoteIpStrategy || "ipv4");
66
73
  (0, import_utils.patchBundlerConfig)({
67
74
  // @ts-expect-error chain type is not correct
68
75
  chain,
69
- isServer,
76
+ isServer: !isWeb,
70
77
  modernjsConfig,
71
78
  mfConfig,
72
79
  enableSSR
@@ -115,6 +122,8 @@ const moduleFederationConfigPlugin = (userConfig) => ({
115
122
  var configPlugin_default = moduleFederationConfigPlugin;
116
123
  // Annotate the CommonJS export names for ESM import in node:
117
124
  0 && (module.exports = {
125
+ isWebTarget,
118
126
  moduleFederationConfigPlugin,
119
- setEnv
127
+ setEnv,
128
+ skipByTarget
120
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"));
@@ -298,6 +299,15 @@ const isWebTarget = (target) => {
298
299
  }
299
300
  return false;
300
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;
308
+ }
309
+ return false;
310
+ };
301
311
  // Annotate the CommonJS export names for ESM import in node:
302
312
  0 && (module.exports = {
303
313
  addMyTypes2Ignored,
@@ -305,5 +315,6 @@ const isWebTarget = (target) => {
305
315
  getMFConfig,
306
316
  isWebTarget,
307
317
  patchBundlerConfig,
308
- patchMFConfig
318
+ patchMFConfig,
319
+ skipByTarget
309
320
  });
@@ -19,6 +19,7 @@ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "defau
19
19
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
20
  var runtime_exports = {};
21
21
  __export(runtime_exports, {
22
+ collectSSRAssets: () => import_createRemoteSSRComponent.collectSSRAssets,
22
23
  createRemoteSSRComponent: () => import_createRemoteSSRComponent.createRemoteSSRComponent
23
24
  });
24
25
  module.exports = __toCommonJS(runtime_exports);
@@ -26,6 +27,7 @@ __reExport(runtime_exports, require("@module-federation/enhanced/runtime"), modu
26
27
  var import_createRemoteSSRComponent = require("./createRemoteSSRComponent");
27
28
  // Annotate the CommonJS export names for ESM import in node:
28
29
  0 && (module.exports = {
30
+ collectSSRAssets,
29
31
  createRemoteSSRComponent,
30
32
  ...require("@module-federation/enhanced/runtime")
31
33
  });
@@ -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 } 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";
@@ -35,15 +35,19 @@ var moduleFederationConfigPlugin = function(userConfig) {
35
35
  userConfig.ssrConfig = ssrConfig;
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
- api.modifyBundlerChain(function(chain, param) {
39
- var isServer = param.isServer;
40
- addMyTypes2Ignored(chain, isServer ? ssrConfig : csrConfig);
41
- var targetMFConfig = isServer ? ssrConfig : csrConfig;
42
- patchMFConfig(targetMFConfig, isServer, userConfig.remoteIpStrategy || "ipv4");
38
+ api.modifyBundlerChain(function(chain) {
39
+ var target = chain.get("target");
40
+ if (skipByTarget(target)) {
41
+ return;
42
+ }
43
+ var isWeb = isWebTarget(target);
44
+ addMyTypes2Ignored(chain, !isWeb ? ssrConfig : csrConfig);
45
+ var targetMFConfig = !isWeb ? ssrConfig : csrConfig;
46
+ patchMFConfig(targetMFConfig, !isWeb, userConfig.remoteIpStrategy || "ipv4");
43
47
  patchBundlerConfig({
44
48
  // @ts-expect-error chain type is not correct
45
49
  chain,
46
- isServer,
50
+ isServer: !isWeb,
47
51
  modernjsConfig,
48
52
  mfConfig,
49
53
  enableSSR
@@ -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");
@@ -289,11 +289,21 @@ var isWebTarget = function(target) {
289
289
  }
290
290
  return false;
291
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;
298
+ }
299
+ return false;
300
+ };
292
301
  export {
293
302
  addMyTypes2Ignored,
294
303
  getIPV4,
295
304
  getMFConfig,
296
305
  isWebTarget,
297
306
  patchBundlerConfig,
298
- patchMFConfig
307
+ patchMFConfig,
308
+ skipByTarget
299
309
  };
@@ -1,5 +1,6 @@
1
1
  export * from "@module-federation/enhanced/runtime";
2
- import { createRemoteSSRComponent } from "./createRemoteSSRComponent";
2
+ import { createRemoteSSRComponent, collectSSRAssets } from "./createRemoteSSRComponent";
3
3
  export {
4
+ collectSSRAssets,
4
5
  createRemoteSSRComponent
5
6
  };
@@ -1,5 +1,5 @@
1
1
  import path from "path";
2
- import { patchBundlerConfig, getIPV4, getMFConfig, patchMFConfig, addMyTypes2Ignored } 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";
@@ -24,14 +24,19 @@ const moduleFederationConfigPlugin = (userConfig) => ({
24
24
  userConfig.csrConfig = csrConfig;
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
- api.modifyBundlerChain((chain, { isServer }) => {
28
- addMyTypes2Ignored(chain, isServer ? ssrConfig : csrConfig);
29
- const targetMFConfig = isServer ? ssrConfig : csrConfig;
30
- patchMFConfig(targetMFConfig, isServer, userConfig.remoteIpStrategy || "ipv4");
27
+ api.modifyBundlerChain((chain) => {
28
+ const target = chain.get("target");
29
+ if (skipByTarget(target)) {
30
+ return;
31
+ }
32
+ const isWeb = isWebTarget(target);
33
+ addMyTypes2Ignored(chain, !isWeb ? ssrConfig : csrConfig);
34
+ const targetMFConfig = !isWeb ? ssrConfig : csrConfig;
35
+ patchMFConfig(targetMFConfig, !isWeb, userConfig.remoteIpStrategy || "ipv4");
31
36
  patchBundlerConfig({
32
37
  // @ts-expect-error chain type is not correct
33
38
  chain,
34
- isServer,
39
+ isServer: !isWeb,
35
40
  modernjsConfig,
36
41
  mfConfig,
37
42
  enableSSR
@@ -80,6 +85,8 @@ const moduleFederationConfigPlugin = (userConfig) => ({
80
85
  var configPlugin_default = moduleFederationConfigPlugin;
81
86
  export {
82
87
  configPlugin_default as default,
88
+ isWebTarget,
83
89
  moduleFederationConfigPlugin,
84
- setEnv
90
+ setEnv,
91
+ skipByTarget
85
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");
@@ -260,11 +260,21 @@ const isWebTarget = (target) => {
260
260
  }
261
261
  return false;
262
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;
269
+ }
270
+ return false;
271
+ };
263
272
  export {
264
273
  addMyTypes2Ignored,
265
274
  getIPV4,
266
275
  getMFConfig,
267
276
  isWebTarget,
268
277
  patchBundlerConfig,
269
- patchMFConfig
278
+ patchMFConfig,
279
+ skipByTarget
270
280
  };
@@ -1,5 +1,6 @@
1
1
  export * from "@module-federation/enhanced/runtime";
2
- import { createRemoteSSRComponent } from "./createRemoteSSRComponent";
2
+ import { createRemoteSSRComponent, collectSSRAssets } from "./createRemoteSSRComponent";
3
3
  export {
4
+ collectSSRAssets,
4
5
  createRemoteSSRComponent
5
6
  };
@@ -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;
@@ -1,2 +1,2 @@
1
1
  export * from '@module-federation/enhanced/runtime';
2
- export { createRemoteSSRComponent } from './createRemoteSSRComponent';
2
+ export { createRemoteSSRComponent, collectSSRAssets, } from './createRemoteSSRComponent';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/modern-js",
3
- "version": "0.10.0",
3
+ "version": "0.11.1",
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.10.0",
93
- "@module-federation/enhanced": "0.10.0",
94
- "@module-federation/node": "2.6.28",
95
- "@module-federation/sdk": "0.10.0"
92
+ "@module-federation/rsbuild-plugin": "0.11.1",
93
+ "@module-federation/enhanced": "0.11.1",
94
+ "@module-federation/node": "2.6.30",
95
+ "@module-federation/sdk": "0.11.1"
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.10.0"
103
+ "@module-federation/manifest": "0.11.1"
104
104
  },
105
105
  "peerDependencies": {
106
106
  "react": ">=17",