@module-federation/modern-js 0.13.1 → 0.14.0

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.
Files changed (78) hide show
  1. package/package.json +7 -7
  2. package/dist/LICENSE +0 -21
  3. package/dist/cjs/cli/configPlugin.js +0 -377
  4. package/dist/cjs/cli/configPlugin.spec.js +0 -112
  5. package/dist/cjs/cli/constant.js +0 -28
  6. package/dist/cjs/cli/index.js +0 -85
  7. package/dist/cjs/cli/logger.js +0 -27
  8. package/dist/cjs/cli/manifest.js +0 -75
  9. package/dist/cjs/cli/mfRuntimePlugins/inject-node-fetch.js +0 -44
  10. package/dist/cjs/cli/mfRuntimePlugins/resolve-entry-ipv4.js +0 -82
  11. package/dist/cjs/cli/mfRuntimePlugins/shared-strategy.js +0 -43
  12. package/dist/cjs/cli/ssrPlugin.js +0 -217
  13. package/dist/cjs/cli/utils.js +0 -85
  14. package/dist/cjs/constant.js +0 -31
  15. package/dist/cjs/interfaces/bundler.js +0 -16
  16. package/dist/cjs/runtime/createRemoteSSRComponent.js +0 -201
  17. package/dist/cjs/runtime/index.js +0 -38
  18. package/dist/cjs/ssr-runtime/SSRLiveReload.js +0 -43
  19. package/dist/cjs/ssr-runtime/index.js +0 -22
  20. package/dist/cjs/ssr-runtime/plugin.js +0 -68
  21. package/dist/cjs/types/index.js +0 -16
  22. package/dist/esm/cli/configPlugin.js +0 -384
  23. package/dist/esm/cli/configPlugin.spec.js +0 -108
  24. package/dist/esm/cli/constant.js +0 -4
  25. package/dist/esm/cli/index.js +0 -79
  26. package/dist/esm/cli/logger.js +0 -7
  27. package/dist/esm/cli/manifest.js +0 -41
  28. package/dist/esm/cli/mfRuntimePlugins/inject-node-fetch.js +0 -16
  29. package/dist/esm/cli/mfRuntimePlugins/resolve-entry-ipv4.js +0 -74
  30. package/dist/esm/cli/mfRuntimePlugins/shared-strategy.js +0 -25
  31. package/dist/esm/cli/ssrPlugin.js +0 -199
  32. package/dist/esm/cli/utils.js +0 -49
  33. package/dist/esm/constant.js +0 -6
  34. package/dist/esm/interfaces/bundler.js +0 -0
  35. package/dist/esm/runtime/createRemoteSSRComponent.js +0 -191
  36. package/dist/esm/runtime/index.js +0 -12
  37. package/dist/esm/ssr-runtime/SSRLiveReload.js +0 -26
  38. package/dist/esm/ssr-runtime/index.js +0 -1
  39. package/dist/esm/ssr-runtime/plugin.js +0 -70
  40. package/dist/esm/types/index.js +0 -0
  41. package/dist/esm-node/cli/configPlugin.js +0 -336
  42. package/dist/esm-node/cli/configPlugin.spec.js +0 -89
  43. package/dist/esm-node/cli/constant.js +0 -4
  44. package/dist/esm-node/cli/index.js +0 -60
  45. package/dist/esm-node/cli/logger.js +0 -7
  46. package/dist/esm-node/cli/manifest.js +0 -41
  47. package/dist/esm-node/cli/mfRuntimePlugins/inject-node-fetch.js +0 -14
  48. package/dist/esm-node/cli/mfRuntimePlugins/resolve-entry-ipv4.js +0 -62
  49. package/dist/esm-node/cli/mfRuntimePlugins/shared-strategy.js +0 -23
  50. package/dist/esm-node/cli/ssrPlugin.js +0 -181
  51. package/dist/esm-node/cli/utils.js +0 -49
  52. package/dist/esm-node/constant.js +0 -6
  53. package/dist/esm-node/interfaces/bundler.js +0 -0
  54. package/dist/esm-node/runtime/createRemoteSSRComponent.js +0 -166
  55. package/dist/esm-node/runtime/index.js +0 -12
  56. package/dist/esm-node/ssr-runtime/SSRLiveReload.js +0 -19
  57. package/dist/esm-node/ssr-runtime/index.js +0 -1
  58. package/dist/esm-node/ssr-runtime/plugin.js +0 -34
  59. package/dist/esm-node/types/index.js +0 -0
  60. package/dist/types/cli/configPlugin.d.ts +0 -21
  61. package/dist/types/cli/configPlugin.spec.d.ts +0 -1
  62. package/dist/types/cli/constant.d.ts +0 -1
  63. package/dist/types/cli/index.d.ts +0 -5
  64. package/dist/types/cli/logger.d.ts +0 -2
  65. package/dist/types/cli/manifest.d.ts +0 -2
  66. package/dist/types/cli/mfRuntimePlugins/inject-node-fetch.d.ts +0 -3
  67. package/dist/types/cli/mfRuntimePlugins/resolve-entry-ipv4.d.ts +0 -3
  68. package/dist/types/cli/mfRuntimePlugins/shared-strategy.d.ts +0 -3
  69. package/dist/types/cli/ssrPlugin.d.ts +0 -6
  70. package/dist/types/cli/utils.d.ts +0 -5
  71. package/dist/types/constant.d.ts +0 -2
  72. package/dist/types/interfaces/bundler.d.ts +0 -18
  73. package/dist/types/runtime/createRemoteSSRComponent.d.ts +0 -18
  74. package/dist/types/runtime/index.d.ts +0 -5
  75. package/dist/types/ssr-runtime/SSRLiveReload.d.ts +0 -1
  76. package/dist/types/ssr-runtime/index.d.ts +0 -1
  77. package/dist/types/ssr-runtime/plugin.d.ts +0 -2
  78. package/dist/types/types/index.d.ts +0 -22
@@ -1,27 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var logger_exports = {};
20
- __export(logger_exports, {
21
- default: () => logger_default
22
- });
23
- module.exports = __toCommonJS(logger_exports);
24
- var import_sdk = require("@module-federation/sdk");
25
- var import_constant = require("../constant");
26
- const logger = (0, import_sdk.createLogger)(import_constant.PLUGIN_IDENTIFIER);
27
- var logger_default = logger;
@@ -1,75 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var manifest_exports = {};
30
- __export(manifest_exports, {
31
- updateStatsAndManifest: () => updateStatsAndManifest
32
- });
33
- module.exports = __toCommonJS(manifest_exports);
34
- var import_path = __toESM(require("path"));
35
- var import_utils = require("@modern-js/utils");
36
- function mergeStats(browserStats, nodeStats) {
37
- const ssrRemoteEntry = nodeStats.metaData.remoteEntry;
38
- browserStats.metaData.ssrRemoteEntry = ssrRemoteEntry;
39
- if ("publicPath" in browserStats.metaData) {
40
- browserStats.metaData.ssrPublicPath = nodeStats.metaData.publicPath;
41
- }
42
- return browserStats;
43
- }
44
- function mergeManifest(browserManifest, nodeManifest) {
45
- const ssrRemoteEntry = nodeManifest.metaData.remoteEntry;
46
- browserManifest.metaData.ssrRemoteEntry = ssrRemoteEntry;
47
- if ("publicPath" in browserManifest.metaData) {
48
- browserManifest.metaData.ssrPublicPath = nodeManifest.metaData.publicPath;
49
- }
50
- return browserManifest;
51
- }
52
- function mergeStatsAndManifest(nodePlugin, browserPlugin) {
53
- const nodeResourceInfo = nodePlugin.statsResourceInfo;
54
- const browserResourceInfo = browserPlugin.statsResourceInfo;
55
- if (!browserResourceInfo || !nodeResourceInfo || !browserResourceInfo.stats || !nodeResourceInfo.stats || !browserResourceInfo.manifest || !nodeResourceInfo.manifest) {
56
- throw new Error("can not get browserResourceInfo or nodeResourceInfo");
57
- }
58
- const mergedStats = mergeStats(browserResourceInfo.stats.stats, nodeResourceInfo.stats.stats);
59
- const mergedManifest = mergeManifest(browserResourceInfo.manifest.manifest, nodeResourceInfo.manifest.manifest);
60
- return {
61
- mergedStats,
62
- mergedStatsFilePath: browserResourceInfo.stats.filename,
63
- mergedManifest,
64
- mergedManifestFilePath: browserResourceInfo.manifest.filename
65
- };
66
- }
67
- function updateStatsAndManifest(nodePlugin, browserPlugin, outputDir) {
68
- const { mergedStats, mergedStatsFilePath, mergedManifest, mergedManifestFilePath } = mergeStatsAndManifest(nodePlugin, browserPlugin);
69
- import_utils.fs.writeFileSync(import_path.default.resolve(outputDir, mergedStatsFilePath), JSON.stringify(mergedStats, null, 2));
70
- import_utils.fs.writeFileSync(import_path.default.resolve(outputDir, mergedManifestFilePath), JSON.stringify(mergedManifest, null, 2));
71
- }
72
- // Annotate the CommonJS export names for ESM import in node:
73
- 0 && (module.exports = {
74
- updateStatsAndManifest
75
- });
@@ -1,44 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var inject_node_fetch_exports = {};
30
- __export(inject_node_fetch_exports, {
31
- default: () => inject_node_fetch_default
32
- });
33
- module.exports = __toCommonJS(inject_node_fetch_exports);
34
- var import_node_fetch = __toESM(require("node-fetch"));
35
- const injectNodeFetchPlugin = () => ({
36
- name: "inject-node-fetch-plugin",
37
- beforeInit(args) {
38
- if (!globalThis.fetch) {
39
- globalThis.fetch = import_node_fetch.default;
40
- }
41
- return args;
42
- }
43
- });
44
- var inject_node_fetch_default = injectNodeFetchPlugin;
@@ -1,82 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var resolve_entry_ipv4_exports = {};
20
- __export(resolve_entry_ipv4_exports, {
21
- default: () => resolve_entry_ipv4_default
22
- });
23
- module.exports = __toCommonJS(resolve_entry_ipv4_exports);
24
- var import_constant = require("../../constant");
25
- const ipv4 = typeof FEDERATION_IPV4 !== "undefined" ? FEDERATION_IPV4 : "127.0.0.1";
26
- const remoteIpStrategy = typeof REMOTE_IP_STRATEGY !== "undefined" ? REMOTE_IP_STRATEGY : "inherit";
27
- function replaceObjectLocalhost(key, obj) {
28
- if (remoteIpStrategy !== "ipv4") {
29
- return;
30
- }
31
- if (!(key in obj)) {
32
- return;
33
- }
34
- const remote = obj[key];
35
- if (remote && typeof remote === "string" && remote.includes(import_constant.LOCALHOST)) {
36
- obj[key] = replaceLocalhost(remote);
37
- }
38
- }
39
- function replaceLocalhost(url) {
40
- return url.replace(import_constant.LOCALHOST, ipv4);
41
- }
42
- const resolveEntryIpv4Plugin = () => ({
43
- name: "resolve-entry-ipv4",
44
- beforeRegisterRemote(args) {
45
- const { remote } = args;
46
- replaceObjectLocalhost("entry", remote);
47
- return args;
48
- },
49
- async afterResolve(args) {
50
- const { remoteInfo } = args;
51
- replaceObjectLocalhost("entry", remoteInfo);
52
- return args;
53
- },
54
- beforeLoadRemoteSnapshot(args) {
55
- const { moduleInfo } = args;
56
- if ("entry" in moduleInfo) {
57
- replaceObjectLocalhost("entry", moduleInfo);
58
- return args;
59
- }
60
- if ("version" in moduleInfo) {
61
- replaceObjectLocalhost("version", moduleInfo);
62
- }
63
- return args;
64
- },
65
- loadRemoteSnapshot(args) {
66
- const { remoteSnapshot } = args;
67
- if ("publicPath" in remoteSnapshot) {
68
- replaceObjectLocalhost("publicPath", remoteSnapshot);
69
- }
70
- if ("getPublicPath" in remoteSnapshot) {
71
- replaceObjectLocalhost("getPublicPath", remoteSnapshot);
72
- }
73
- if (remoteSnapshot.remotesInfo) {
74
- Object.keys(remoteSnapshot.remotesInfo).forEach((key) => {
75
- const remoteInfo = remoteSnapshot.remotesInfo[key];
76
- replaceObjectLocalhost("matchedVersion", remoteInfo);
77
- });
78
- }
79
- return args;
80
- }
81
- });
82
- var resolve_entry_ipv4_default = resolveEntryIpv4Plugin;
@@ -1,43 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var shared_strategy_exports = {};
20
- __export(shared_strategy_exports, {
21
- default: () => shared_strategy_default
22
- });
23
- module.exports = __toCommonJS(shared_strategy_exports);
24
- const sharedStrategy = () => ({
25
- name: "shared-strategy-plugin",
26
- beforeInit(args) {
27
- const { userOptions } = args;
28
- const shared = userOptions.shared;
29
- if (shared) {
30
- Object.keys(shared).forEach((sharedKey) => {
31
- const sharedConfigs = shared[sharedKey];
32
- const arraySharedConfigs = Array.isArray(sharedConfigs) ? sharedConfigs : [
33
- sharedConfigs
34
- ];
35
- arraySharedConfigs.forEach((s) => {
36
- s.strategy = "loaded-first";
37
- });
38
- });
39
- }
40
- return args;
41
- }
42
- });
43
- var shared_strategy_default = sharedStrategy;
@@ -1,217 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var ssrPlugin_exports = {};
30
- __export(ssrPlugin_exports, {
31
- CHAIN_MF_PLUGIN_ID: () => CHAIN_MF_PLUGIN_ID,
32
- default: () => ssrPlugin_default,
33
- moduleFederationSSRPlugin: () => moduleFederationSSRPlugin,
34
- setEnv: () => setEnv
35
- });
36
- module.exports = __toCommonJS(ssrPlugin_exports);
37
- var import_path = __toESM(require("path"));
38
- var import_utils = require("@modern-js/utils");
39
- var import_webpack = require("@module-federation/enhanced/webpack");
40
- var import_rspack = require("@module-federation/enhanced/rspack");
41
- var import_universe_entry_chunk_tracker_plugin = __toESM(require("@module-federation/node/universe-entry-chunk-tracker-plugin"));
42
- var import_manifest = require("./manifest");
43
- var import_constant = require("./constant");
44
- var import_logger = __toESM(require("./logger"));
45
- var import_utils2 = require("./utils");
46
- function setEnv() {
47
- process.env["MF_DISABLE_EMIT_STATS"] = "true";
48
- process.env["MF_SSR_PRJ"] = "true";
49
- }
50
- const CHAIN_MF_PLUGIN_ID = "plugin-module-federation-server";
51
- const mfSSRRsbuildPlugin = (pluginOptions) => {
52
- return {
53
- name: "@modern-js/plugin-mf-post-config",
54
- pre: [
55
- "@modern-js/builder-plugin-ssr"
56
- ],
57
- setup(api) {
58
- if (pluginOptions.csrConfig.getPublicPath) {
59
- return;
60
- }
61
- let csrOutputPath = "";
62
- let ssrOutputPath = "";
63
- let ssrEnv = "";
64
- api.modifyEnvironmentConfig((config, { name }) => {
65
- const target = config.output.target;
66
- if ((0, import_utils2.skipByTarget)(target)) {
67
- return config;
68
- }
69
- if ((0, import_utils2.isWebTarget)(target)) {
70
- csrOutputPath = config.output.distPath.root;
71
- } else {
72
- ssrOutputPath = config.output.distPath.root;
73
- ssrEnv = name;
74
- }
75
- return config;
76
- });
77
- const modifySSRPublicPath = (config, utils) => {
78
- if (ssrEnv !== utils.environment.name) {
79
- return config;
80
- }
81
- const userSSRConfig = pluginOptions.userConfig.ssr ? typeof pluginOptions.userConfig.ssr === "object" ? pluginOptions.userConfig.ssr : {} : {};
82
- if (userSSRConfig.distOutputDir) {
83
- return;
84
- }
85
- config.output.publicPath = `${config.output.publicPath}${import_path.default.relative(csrOutputPath, ssrOutputPath)}/`;
86
- return config;
87
- };
88
- api.modifyWebpackConfig((config, utils) => {
89
- modifySSRPublicPath(config, utils);
90
- return config;
91
- });
92
- api.modifyRspackConfig((config, utils) => {
93
- modifySSRPublicPath(config, utils);
94
- return config;
95
- });
96
- }
97
- };
98
- };
99
- const moduleFederationSSRPlugin = (pluginOptions) => ({
100
- name: "@modern-js/plugin-module-federation-ssr",
101
- pre: [
102
- "@modern-js/plugin-module-federation-config",
103
- "@modern-js/plugin-module-federation"
104
- ],
105
- setup: async (api) => {
106
- var _pluginOptions_userConfig, _modernjsConfig_server;
107
- const modernjsConfig = api.getConfig();
108
- var _pluginOptions_userConfig_ssr;
109
- 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);
110
- if (!enableSSR) {
111
- return;
112
- }
113
- setEnv();
114
- api._internalRuntimePlugins(({ entrypoint, plugins }) => {
115
- if (!import_constant.isDev) {
116
- return {
117
- entrypoint,
118
- plugins
119
- };
120
- }
121
- plugins.push({
122
- name: "mfSSR",
123
- path: "@module-federation/modern-js/ssr-runtime",
124
- config: {}
125
- });
126
- return {
127
- entrypoint,
128
- plugins
129
- };
130
- });
131
- api.modifyBundlerChain((chain) => {
132
- const target = chain.get("target");
133
- if ((0, import_utils2.skipByTarget)(target)) {
134
- return;
135
- }
136
- const bundlerType = api.getAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
137
- const MFPlugin = bundlerType === "webpack" ? import_webpack.ModuleFederationPlugin : import_rspack.ModuleFederationPlugin;
138
- const isWeb = (0, import_utils2.isWebTarget)(target);
139
- if (!isWeb) {
140
- if (!chain.plugins.has(CHAIN_MF_PLUGIN_ID)) {
141
- chain.plugin(CHAIN_MF_PLUGIN_ID).use(MFPlugin, [
142
- pluginOptions.ssrConfig
143
- ]).init((Plugin, args) => {
144
- pluginOptions.nodePlugin = new Plugin(args[0]);
145
- return pluginOptions.nodePlugin;
146
- });
147
- }
148
- }
149
- if (!isWeb) {
150
- chain.target("async-node");
151
- if (import_constant.isDev) {
152
- chain.plugin("UniverseEntryChunkTrackerPlugin").use(import_universe_entry_chunk_tracker_plugin.default);
153
- }
154
- const userSSRConfig = pluginOptions.userConfig.ssr ? typeof pluginOptions.userConfig.ssr === "object" ? pluginOptions.userConfig.ssr : {} : {};
155
- const publicPath = chain.output.get("publicPath");
156
- if (userSSRConfig.distOutputDir && publicPath) {
157
- chain.output.publicPath(`${publicPath}${userSSRConfig.distOutputDir}/`);
158
- }
159
- }
160
- if (import_constant.isDev && isWeb) {
161
- chain.externals({
162
- "@module-federation/node/utils": "NOT_USED_IN_BROWSER"
163
- });
164
- }
165
- });
166
- api.config(() => {
167
- return {
168
- builderPlugins: [
169
- mfSSRRsbuildPlugin(pluginOptions)
170
- ],
171
- tools: {
172
- devServer: {
173
- before: [
174
- (req, res, next) => {
175
- if (!enableSSR) {
176
- next();
177
- return;
178
- }
179
- try {
180
- var _req_url, _req_url1;
181
- if (((_req_url = req.url) === null || _req_url === void 0 ? void 0 : _req_url.includes(".json")) && !((_req_url1 = req.url) === null || _req_url1 === void 0 ? void 0 : _req_url1.includes("hot-update"))) {
182
- const filepath = import_path.default.join(process.cwd(), `dist${req.url}`);
183
- import_utils.fs.statSync(filepath);
184
- res.setHeader("Access-Control-Allow-Origin", "*");
185
- res.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, PATCH, OPTIONS");
186
- res.setHeader("Access-Control-Allow-Headers", "*");
187
- import_utils.fs.createReadStream(filepath).pipe(res);
188
- } else {
189
- next();
190
- }
191
- } catch (err) {
192
- import_logger.default.debug(err);
193
- next();
194
- }
195
- }
196
- ]
197
- }
198
- }
199
- };
200
- });
201
- api.onAfterBuild(() => {
202
- const { nodePlugin, browserPlugin, distOutputDir } = pluginOptions;
203
- (0, import_manifest.updateStatsAndManifest)(nodePlugin, browserPlugin, distOutputDir);
204
- });
205
- api.onDevCompileDone(() => {
206
- const { nodePlugin, browserPlugin, distOutputDir } = pluginOptions;
207
- (0, import_manifest.updateStatsAndManifest)(nodePlugin, browserPlugin, distOutputDir);
208
- });
209
- }
210
- });
211
- var ssrPlugin_default = moduleFederationSSRPlugin;
212
- // Annotate the CommonJS export names for ESM import in node:
213
- 0 && (module.exports = {
214
- CHAIN_MF_PLUGIN_ID,
215
- moduleFederationSSRPlugin,
216
- setEnv
217
- });
@@ -1,85 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var utils_exports = {};
30
- __export(utils_exports, {
31
- getIPV4: () => getIPV4,
32
- isWebTarget: () => isWebTarget,
33
- skipByTarget: () => skipByTarget
34
- });
35
- module.exports = __toCommonJS(utils_exports);
36
- var import_os = __toESM(require("os"));
37
- const localIpv4 = "127.0.0.1";
38
- const getIpv4Interfaces = () => {
39
- try {
40
- const interfaces = import_os.default.networkInterfaces();
41
- const ipv4Interfaces = [];
42
- Object.values(interfaces).forEach((detail) => {
43
- detail === null || detail === void 0 ? void 0 : detail.forEach((detail2) => {
44
- const familyV4Value = typeof detail2.family === "string" ? "IPv4" : 4;
45
- if (detail2.family === familyV4Value && detail2.address !== localIpv4) {
46
- ipv4Interfaces.push(detail2);
47
- }
48
- });
49
- });
50
- return ipv4Interfaces;
51
- } catch (_err) {
52
- return [];
53
- }
54
- };
55
- const getIPV4 = () => {
56
- const ipv4Interfaces = getIpv4Interfaces();
57
- const ipv4Interface = ipv4Interfaces[0] || {
58
- address: localIpv4
59
- };
60
- return ipv4Interface.address;
61
- };
62
- const isWebTarget = (target) => {
63
- const WEB_TARGET = "web";
64
- if (Array.isArray(target)) {
65
- return target.includes(WEB_TARGET);
66
- } else if (typeof target === "string") {
67
- return target === WEB_TARGET;
68
- }
69
- return false;
70
- };
71
- const skipByTarget = (target) => {
72
- const IGNORE_TARGET = "webworker";
73
- if (Array.isArray(target)) {
74
- return target.includes(IGNORE_TARGET);
75
- } else if (typeof target === "string") {
76
- return target === IGNORE_TARGET;
77
- }
78
- return false;
79
- };
80
- // Annotate the CommonJS export names for ESM import in node:
81
- 0 && (module.exports = {
82
- getIPV4,
83
- isWebTarget,
84
- skipByTarget
85
- });
@@ -1,31 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var constant_exports = {};
20
- __export(constant_exports, {
21
- LOCALHOST: () => LOCALHOST,
22
- PLUGIN_IDENTIFIER: () => PLUGIN_IDENTIFIER
23
- });
24
- module.exports = __toCommonJS(constant_exports);
25
- const LOCALHOST = "localhost";
26
- const PLUGIN_IDENTIFIER = "[ Modern.js Module Federation ]";
27
- // Annotate the CommonJS export names for ESM import in node:
28
- 0 && (module.exports = {
29
- LOCALHOST,
30
- PLUGIN_IDENTIFIER
31
- });
@@ -1,16 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __copyProps = (to, from, except, desc) => {
7
- if (from && typeof from === "object" || typeof from === "function") {
8
- for (let key of __getOwnPropNames(from))
9
- if (!__hasOwnProp.call(to, key) && key !== except)
10
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
- }
12
- return to;
13
- };
14
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
- var bundler_exports = {};
16
- module.exports = __toCommonJS(bundler_exports);