@module-federation/modern-js 0.0.0-next-20241017102355 → 0.0.0-next-20241018034800
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.
- package/dist/cjs/cli/{routes/ast/index.js → constant.js} +6 -6
- package/dist/cjs/cli/index.js +2 -7
- package/dist/cjs/cli/mfRuntimePlugins/{node-fetch.js → inject-node-fetch.js} +6 -6
- package/dist/cjs/cli/mfRuntimePlugins/resolve-entry-ipv4.js +38 -40
- package/dist/cjs/{runtime/withMFRouteId.js → cli/mfRuntimePlugins/shared-strategy.js} +23 -11
- package/dist/cjs/cli/ssrPlugin.js +2 -5
- package/dist/cjs/cli/utils.js +6 -11
- package/dist/cjs/cli/utils.spec.js +6 -5
- package/dist/cjs/constant.js +2 -35
- package/dist/cjs/runtime/index.js +1 -4
- package/dist/cjs/ssr-runtime/plugin.js +8 -7
- package/dist/esm/cli/constant.js +4 -0
- package/dist/esm/cli/index.js +2 -7
- package/dist/esm/cli/mfRuntimePlugins/{node-fetch.js → inject-node-fetch.js} +3 -3
- package/dist/esm/cli/mfRuntimePlugins/shared-strategy.js +25 -0
- package/dist/esm/cli/ssrPlugin.js +3 -6
- package/dist/esm/cli/utils.js +5 -9
- package/dist/esm/cli/utils.spec.js +6 -5
- package/dist/esm/constant.js +1 -23
- package/dist/esm/runtime/index.js +1 -3
- package/dist/esm/ssr-runtime/plugin.js +11 -8
- package/dist/esm-node/cli/constant.js +4 -0
- package/dist/esm-node/cli/index.js +2 -7
- package/dist/esm-node/cli/mfRuntimePlugins/{node-fetch.js → inject-node-fetch.js} +3 -3
- package/dist/esm-node/cli/mfRuntimePlugins/resolve-entry-ipv4.js +38 -40
- package/dist/esm-node/cli/mfRuntimePlugins/shared-strategy.js +23 -0
- package/dist/esm-node/cli/ssrPlugin.js +2 -5
- package/dist/esm-node/cli/utils.js +5 -9
- package/dist/esm-node/cli/utils.spec.js +6 -5
- package/dist/esm-node/constant.js +1 -23
- package/dist/esm-node/runtime/index.js +1 -3
- package/dist/esm-node/ssr-runtime/plugin.js +8 -7
- package/dist/types/cli/constant.d.ts +1 -0
- package/dist/types/cli/mfRuntimePlugins/shared-strategy.d.ts +3 -0
- package/dist/types/cli/utils.d.ts +0 -2
- package/dist/types/constant.d.ts +0 -11
- package/dist/types/runtime/index.d.ts +0 -1
- package/dist/types/ssr-runtime/plugin.d.ts +1 -3
- package/dist/types/types/index.d.ts +1 -3
- package/package.json +12 -49
- package/dist/cjs/cli/mfRuntimePlugins/node.js +0 -41
- package/dist/cjs/cli/routes/ast/constant.js +0 -49
- package/dist/cjs/cli/routes/ast/generateRoutes.js +0 -143
- package/dist/cjs/cli/routes/clearMFCache.js +0 -57
- package/dist/cjs/cli/routes/exportRoutePlugin.js +0 -77
- package/dist/cjs/cli/routes/importRoutesPlugin.js +0 -120
- package/dist/cjs/cli/routes/plugin.js +0 -157
- package/dist/cjs/cli/routes/traverseRouteFiles.js +0 -148
- package/dist/cjs/cli/routes/utils.js +0 -168
- package/dist/cjs/cli/server/fetchRemoteFullRoutesMap.js +0 -72
- package/dist/cjs/cli/server/fetchRoutePlugin.js +0 -81
- package/dist/cjs/interfaces/route.js +0 -16
- package/dist/cjs/runtime/routes/plugin-inject-assets.js +0 -92
- package/dist/cjs/runtime/routes/plugin.js +0 -75
- package/dist/cjs/runtime/routes/utils.js +0 -115
- package/dist/cjs/types/modern.js +0 -16
- package/dist/cjs/types/routes.js +0 -16
- package/dist/esm/cli/mfRuntimePlugins/node.js +0 -13
- package/dist/esm/cli/routes/ast/constant.js +0 -18
- package/dist/esm/cli/routes/ast/generateRoutes.js +0 -110
- package/dist/esm/cli/routes/ast/index.js +0 -4
- package/dist/esm/cli/routes/clearMFCache.js +0 -34
- package/dist/esm/cli/routes/exportRoutePlugin.js +0 -79
- package/dist/esm/cli/routes/importRoutesPlugin.js +0 -122
- package/dist/esm/cli/routes/plugin.js +0 -266
- package/dist/esm/cli/routes/traverseRouteFiles.js +0 -313
- package/dist/esm/cli/routes/utils.js +0 -130
- package/dist/esm/cli/server/fetchRemoteFullRoutesMap.js +0 -93
- package/dist/esm/cli/server/fetchRoutePlugin.js +0 -104
- package/dist/esm/interfaces/route.js +0 -0
- package/dist/esm/runtime/routes/plugin-inject-assets.js +0 -71
- package/dist/esm/runtime/routes/plugin.js +0 -97
- package/dist/esm/runtime/routes/utils.js +0 -86
- package/dist/esm/runtime/withMFRouteId.js +0 -7
- package/dist/esm/types/modern.js +0 -0
- package/dist/esm/types/routes.js +0 -0
- package/dist/esm-node/cli/mfRuntimePlugins/node.js +0 -11
- package/dist/esm-node/cli/routes/ast/constant.js +0 -18
- package/dist/esm-node/cli/routes/ast/generateRoutes.js +0 -109
- package/dist/esm-node/cli/routes/ast/index.js +0 -4
- package/dist/esm-node/cli/routes/clearMFCache.js +0 -33
- package/dist/esm-node/cli/routes/exportRoutePlugin.js +0 -53
- package/dist/esm-node/cli/routes/importRoutesPlugin.js +0 -96
- package/dist/esm-node/cli/routes/plugin.js +0 -123
- package/dist/esm-node/cli/routes/traverseRouteFiles.js +0 -113
- package/dist/esm-node/cli/routes/utils.js +0 -133
- package/dist/esm-node/cli/server/fetchRemoteFullRoutesMap.js +0 -47
- package/dist/esm-node/cli/server/fetchRoutePlugin.js +0 -61
- package/dist/esm-node/interfaces/route.js +0 -0
- package/dist/esm-node/runtime/routes/plugin-inject-assets.js +0 -68
- package/dist/esm-node/runtime/routes/plugin.js +0 -51
- package/dist/esm-node/runtime/routes/utils.js +0 -86
- package/dist/esm-node/runtime/withMFRouteId.js +0 -7
- package/dist/esm-node/types/modern.js +0 -0
- package/dist/esm-node/types/routes.js +0 -0
- package/dist/types/cli/mfRuntimePlugins/node.d.ts +0 -3
- package/dist/types/cli/routes/ast/constant.d.ts +0 -8
- package/dist/types/cli/routes/ast/generateRoutes.d.ts +0 -5
- package/dist/types/cli/routes/ast/index.d.ts +0 -1
- package/dist/types/cli/routes/clearMFCache.d.ts +0 -1
- package/dist/types/cli/routes/exportRoutePlugin.d.ts +0 -4
- package/dist/types/cli/routes/importRoutesPlugin.d.ts +0 -4
- package/dist/types/cli/routes/plugin.d.ts +0 -4
- package/dist/types/cli/routes/traverseRouteFiles.d.ts +0 -11
- package/dist/types/cli/routes/utils.d.ts +0 -11
- package/dist/types/cli/server/fetchRemoteFullRoutesMap.d.ts +0 -11
- package/dist/types/cli/server/fetchRoutePlugin.d.ts +0 -10
- package/dist/types/interfaces/route.d.ts +0 -12
- package/dist/types/runtime/routes/plugin-inject-assets.d.ts +0 -4
- package/dist/types/runtime/routes/plugin.d.ts +0 -5
- package/dist/types/runtime/routes/utils.d.ts +0 -22
- package/dist/types/runtime/withMFRouteId.d.ts +0 -1
- package/dist/types/types/modern.d.ts +0 -12
- package/dist/types/types/routes.d.ts +0 -19
- /package/dist/types/cli/mfRuntimePlugins/{node-fetch.d.ts → inject-node-fetch.d.ts} +0 -0
|
@@ -16,13 +16,13 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var
|
|
20
|
-
__export(
|
|
21
|
-
|
|
19
|
+
var constant_exports = {};
|
|
20
|
+
__export(constant_exports, {
|
|
21
|
+
isDev: () => isDev
|
|
22
22
|
});
|
|
23
|
-
module.exports = __toCommonJS(
|
|
24
|
-
|
|
23
|
+
module.exports = __toCommonJS(constant_exports);
|
|
24
|
+
const isDev = process.env.NODE_ENV === "development";
|
|
25
25
|
// Annotate the CommonJS export names for ESM import in node:
|
|
26
26
|
0 && (module.exports = {
|
|
27
|
-
|
|
27
|
+
isDev
|
|
28
28
|
});
|
package/dist/cjs/cli/index.js
CHANGED
|
@@ -27,7 +27,6 @@ var import_enhanced = require("@module-federation/enhanced");
|
|
|
27
27
|
var import_rspack = require("@module-federation/enhanced/rspack");
|
|
28
28
|
var import_configPlugin = require("./configPlugin");
|
|
29
29
|
var import_ssrPlugin = require("./ssrPlugin");
|
|
30
|
-
var import_plugin = require("./routes/plugin");
|
|
31
30
|
var import_enhanced2 = require("@module-federation/enhanced");
|
|
32
31
|
const moduleFederationPlugin = (userConfig = {}) => {
|
|
33
32
|
const internalModernPluginOptions = {
|
|
@@ -37,7 +36,7 @@ const moduleFederationPlugin = (userConfig = {}) => {
|
|
|
37
36
|
nodePlugin: void 0,
|
|
38
37
|
distOutputDir: "",
|
|
39
38
|
originPluginOptions: userConfig,
|
|
40
|
-
remoteIpStrategy: void 0
|
|
39
|
+
remoteIpStrategy: userConfig === null || userConfig === void 0 ? void 0 : userConfig.remoteIpStrategy
|
|
41
40
|
};
|
|
42
41
|
return {
|
|
43
42
|
name: "@modern-js/plugin-module-federation",
|
|
@@ -80,11 +79,7 @@ const moduleFederationPlugin = (userConfig = {}) => {
|
|
|
80
79
|
},
|
|
81
80
|
usePlugins: [
|
|
82
81
|
(0, import_configPlugin.moduleFederationConfigPlugin)(internalModernPluginOptions),
|
|
83
|
-
(0, import_ssrPlugin.moduleFederationSSRPlugin)(internalModernPluginOptions)
|
|
84
|
-
(0, import_plugin.moduleFederationRoutesPlugin)({
|
|
85
|
-
userConfig,
|
|
86
|
-
internalOptions: internalModernPluginOptions
|
|
87
|
-
})
|
|
82
|
+
(0, import_ssrPlugin.moduleFederationSSRPlugin)(internalModernPluginOptions)
|
|
88
83
|
]
|
|
89
84
|
};
|
|
90
85
|
};
|
|
@@ -26,14 +26,14 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var
|
|
30
|
-
__export(
|
|
31
|
-
default: () =>
|
|
29
|
+
var inject_node_fetch_exports = {};
|
|
30
|
+
__export(inject_node_fetch_exports, {
|
|
31
|
+
default: () => inject_node_fetch_default
|
|
32
32
|
});
|
|
33
|
-
module.exports = __toCommonJS(
|
|
33
|
+
module.exports = __toCommonJS(inject_node_fetch_exports);
|
|
34
34
|
var import_node_fetch = __toESM(require("node-fetch"));
|
|
35
35
|
const injectNodeFetchPlugin = () => ({
|
|
36
|
-
name: "node-fetch-plugin",
|
|
36
|
+
name: "inject-node-fetch-plugin",
|
|
37
37
|
beforeInit(args) {
|
|
38
38
|
if (!globalThis.fetch) {
|
|
39
39
|
globalThis.fetch = import_node_fetch.default;
|
|
@@ -41,4 +41,4 @@ const injectNodeFetchPlugin = () => ({
|
|
|
41
41
|
return args;
|
|
42
42
|
}
|
|
43
43
|
});
|
|
44
|
-
var
|
|
44
|
+
var inject_node_fetch_default = injectNodeFetchPlugin;
|
|
@@ -39,46 +39,44 @@ function replaceObjectLocalhost(key, obj) {
|
|
|
39
39
|
function replaceLocalhost(url) {
|
|
40
40
|
return url.replace(import_constant.LOCALHOST, ipv4);
|
|
41
41
|
}
|
|
42
|
-
const resolveEntryIpv4Plugin = () => {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
replaceObjectLocalhost("entry", moduleInfo);
|
|
59
|
-
return args;
|
|
60
|
-
}
|
|
61
|
-
if ("version" in moduleInfo) {
|
|
62
|
-
replaceObjectLocalhost("version", moduleInfo);
|
|
63
|
-
}
|
|
64
|
-
return args;
|
|
65
|
-
},
|
|
66
|
-
loadRemoteSnapshot(args) {
|
|
67
|
-
const { remoteSnapshot } = args;
|
|
68
|
-
if ("publicPath" in remoteSnapshot) {
|
|
69
|
-
replaceObjectLocalhost("publicPath", remoteSnapshot);
|
|
70
|
-
}
|
|
71
|
-
if ("getPublicPath" in remoteSnapshot) {
|
|
72
|
-
replaceObjectLocalhost("getPublicPath", remoteSnapshot);
|
|
73
|
-
}
|
|
74
|
-
if (remoteSnapshot.remotesInfo) {
|
|
75
|
-
Object.keys(remoteSnapshot.remotesInfo).forEach((key) => {
|
|
76
|
-
const remoteInfo = remoteSnapshot.remotesInfo[key];
|
|
77
|
-
replaceObjectLocalhost("matchedVersion", remoteInfo);
|
|
78
|
-
});
|
|
79
|
-
}
|
|
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);
|
|
80
58
|
return args;
|
|
81
59
|
}
|
|
82
|
-
|
|
83
|
-
|
|
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
|
+
});
|
|
84
82
|
var resolve_entry_ipv4_default = resolveEntryIpv4Plugin;
|
|
@@ -16,16 +16,28 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var
|
|
20
|
-
__export(
|
|
21
|
-
|
|
19
|
+
var shared_strategy_exports = {};
|
|
20
|
+
__export(shared_strategy_exports, {
|
|
21
|
+
default: () => shared_strategy_default
|
|
22
22
|
});
|
|
23
|
-
module.exports = __toCommonJS(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
+
}
|
|
31
42
|
});
|
|
43
|
+
var shared_strategy_default = sharedStrategy;
|
|
@@ -39,7 +39,7 @@ var import_webpack = require("@module-federation/enhanced/webpack");
|
|
|
39
39
|
var import_rspack = require("@module-federation/enhanced/rspack");
|
|
40
40
|
var import_universe_entry_chunk_tracker_plugin = __toESM(require("@module-federation/node/universe-entry-chunk-tracker-plugin"));
|
|
41
41
|
var import_manifest = require("./manifest");
|
|
42
|
-
var import_constant = require("
|
|
42
|
+
var import_constant = require("./constant");
|
|
43
43
|
function setEnv() {
|
|
44
44
|
process.env["MF_DISABLE_EMIT_STATS"] = "true";
|
|
45
45
|
process.env["MF_SSR_PRJ"] = "true";
|
|
@@ -53,7 +53,6 @@ const moduleFederationSSRPlugin = (userConfig) => ({
|
|
|
53
53
|
setup: async ({ useConfigContext, useAppContext }) => {
|
|
54
54
|
var _modernjsConfig_server;
|
|
55
55
|
const modernjsConfig = useConfigContext();
|
|
56
|
-
const { metaName = import_constant.META_NAME } = userConfig;
|
|
57
56
|
const enableSSR = Boolean(modernjsConfig === null || modernjsConfig === void 0 ? void 0 : (_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
|
|
58
57
|
if (!enableSSR) {
|
|
59
58
|
return {};
|
|
@@ -70,9 +69,7 @@ const moduleFederationSSRPlugin = (userConfig) => ({
|
|
|
70
69
|
plugins.push({
|
|
71
70
|
name: "mfSSR",
|
|
72
71
|
path: "@module-federation/modern-js/ssr-runtime",
|
|
73
|
-
config: {
|
|
74
|
-
metaName
|
|
75
|
-
}
|
|
72
|
+
config: {}
|
|
76
73
|
});
|
|
77
74
|
return {
|
|
78
75
|
entrypoint,
|
package/dist/cjs/cli/utils.js
CHANGED
|
@@ -32,8 +32,7 @@ __export(utils_exports, {
|
|
|
32
32
|
getMFConfig: () => getMFConfig,
|
|
33
33
|
patchBundlerConfig: () => patchBundlerConfig,
|
|
34
34
|
patchIgnoreWarning: () => patchIgnoreWarning,
|
|
35
|
-
patchMFConfig: () => patchMFConfig
|
|
36
|
-
replaceRemoteUrl: () => replaceRemoteUrl
|
|
35
|
+
patchMFConfig: () => patchMFConfig
|
|
37
36
|
});
|
|
38
37
|
module.exports = __toCommonJS(utils_exports);
|
|
39
38
|
var import_sdk = require("@module-federation/sdk");
|
|
@@ -85,9 +84,7 @@ const replaceRemoteUrl = (mfConfig, remoteIpStrategy) => {
|
|
|
85
84
|
if (typeof remoteObject === "string") {
|
|
86
85
|
return;
|
|
87
86
|
}
|
|
88
|
-
|
|
89
|
-
remoteObject.entry = remoteObject.entry.replace(import_constant.LOCALHOST, ipv4);
|
|
90
|
-
}
|
|
87
|
+
handleRemoteObject(remoteObject);
|
|
91
88
|
});
|
|
92
89
|
} else if (typeof mfConfig.remotes !== "string") {
|
|
93
90
|
handleRemoteObject(mfConfig.remotes);
|
|
@@ -136,18 +133,17 @@ const patchMFConfig = (mfConfig, isServer, remoteIpStrategy) => {
|
|
|
136
133
|
const runtimePlugins = [
|
|
137
134
|
...mfConfig.runtimePlugins || []
|
|
138
135
|
];
|
|
139
|
-
var _mfConfig_shareStrategy;
|
|
140
|
-
mfConfig.shareStrategy = (_mfConfig_shareStrategy = mfConfig.shareStrategy) !== null && _mfConfig_shareStrategy !== void 0 ? _mfConfig_shareStrategy : "loaded-first";
|
|
141
136
|
patchDTSConfig(mfConfig, isServer);
|
|
137
|
+
injectRuntimePlugins(import_path.default.resolve(__dirname, "./mfRuntimePlugins/shared-strategy.js"), runtimePlugins);
|
|
142
138
|
if (isDev) {
|
|
143
139
|
injectRuntimePlugins(import_path.default.resolve(__dirname, "./mfRuntimePlugins/resolve-entry-ipv4.js"), runtimePlugins);
|
|
144
140
|
}
|
|
145
141
|
if (isServer) {
|
|
146
|
-
injectRuntimePlugins(
|
|
142
|
+
injectRuntimePlugins(require.resolve("@module-federation/node/runtimePlugin"), runtimePlugins);
|
|
147
143
|
if (isDev) {
|
|
148
144
|
injectRuntimePlugins(require.resolve("@module-federation/node/record-dynamic-remote-entry-hash-plugin"), runtimePlugins);
|
|
149
145
|
}
|
|
150
|
-
injectRuntimePlugins(import_path.default.resolve(__dirname, "./mfRuntimePlugins/node-fetch.js"), runtimePlugins);
|
|
146
|
+
injectRuntimePlugins(import_path.default.resolve(__dirname, "./mfRuntimePlugins/inject-node-fetch.js"), runtimePlugins);
|
|
151
147
|
if (!mfConfig.library) {
|
|
152
148
|
mfConfig.library = {
|
|
153
149
|
type: "commonjs-module",
|
|
@@ -333,6 +329,5 @@ function autoDeleteSplitChunkCacheGroups(mfConfig, bundlerConfig) {
|
|
|
333
329
|
getMFConfig,
|
|
334
330
|
patchBundlerConfig,
|
|
335
331
|
patchIgnoreWarning,
|
|
336
|
-
patchMFConfig
|
|
337
|
-
replaceRemoteUrl
|
|
332
|
+
patchMFConfig
|
|
338
333
|
});
|
|
@@ -59,10 +59,10 @@ const mfConfig = {
|
|
|
59
59
|
remote: `http://${ipv4}:3000/remoteEntry.js`
|
|
60
60
|
},
|
|
61
61
|
remoteType: "script",
|
|
62
|
-
shareStrategy: "loaded-first",
|
|
63
62
|
runtimePlugins: [
|
|
64
|
-
import_path.default.resolve(__dirname, "./mfRuntimePlugins/
|
|
65
|
-
|
|
63
|
+
import_path.default.resolve(__dirname, "./mfRuntimePlugins/shared-strategy.js"),
|
|
64
|
+
require.resolve("@module-federation/node/runtimePlugin"),
|
|
65
|
+
import_path.default.resolve(__dirname, "./mfRuntimePlugins/inject-node-fetch.js")
|
|
66
66
|
],
|
|
67
67
|
shared: {
|
|
68
68
|
react: {
|
|
@@ -87,8 +87,9 @@ const mfConfig = {
|
|
|
87
87
|
remote: `http://${ipv4}:3000/remoteEntry.js`
|
|
88
88
|
},
|
|
89
89
|
remoteType: "script",
|
|
90
|
-
runtimePlugins: [
|
|
91
|
-
|
|
90
|
+
runtimePlugins: [
|
|
91
|
+
import_path.default.resolve(__dirname, "./mfRuntimePlugins/shared-strategy.js")
|
|
92
|
+
],
|
|
92
93
|
shared: {
|
|
93
94
|
react: {
|
|
94
95
|
eager: true,
|
package/dist/cjs/constant.js
CHANGED
|
@@ -18,50 +18,17 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var constant_exports = {};
|
|
20
20
|
__export(constant_exports, {
|
|
21
|
-
DEFAULT_ENTRY: () => DEFAULT_ENTRY,
|
|
22
|
-
DEFAULT_LAYOUT: () => DEFAULT_LAYOUT,
|
|
23
|
-
FOLD_IDENTIFIER: () => FOLD_IDENTIFIER,
|
|
24
21
|
LOCALHOST: () => LOCALHOST,
|
|
25
|
-
META_NAME: () => META_NAME,
|
|
26
|
-
MF_JSON: () => MF_JSON,
|
|
27
|
-
MF_ROUTES: () => MF_ROUTES,
|
|
28
|
-
MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME: () => MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME,
|
|
29
|
-
MODERN_JS_ROUTE_SERVER_LOADER: () => MODERN_JS_ROUTE_SERVER_LOADER,
|
|
30
22
|
MODERN_JS_SERVER_DIR: () => MODERN_JS_SERVER_DIR,
|
|
31
|
-
PLUGIN_IDENTIFIER: () => PLUGIN_IDENTIFIER
|
|
32
|
-
ROUTE_ID: () => ROUTE_ID,
|
|
33
|
-
SEPARATOR: () => SEPARATOR,
|
|
34
|
-
isDev: () => isDev
|
|
23
|
+
PLUGIN_IDENTIFIER: () => PLUGIN_IDENTIFIER
|
|
35
24
|
});
|
|
36
25
|
module.exports = __toCommonJS(constant_exports);
|
|
37
26
|
const MODERN_JS_SERVER_DIR = "bundles";
|
|
38
27
|
const LOCALHOST = "localhost";
|
|
39
28
|
const PLUGIN_IDENTIFIER = "[ Modern.js Module Federation ]";
|
|
40
|
-
const isDev = process.env.NODE_ENV === "development";
|
|
41
|
-
const MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME = "routes";
|
|
42
|
-
const MODERN_JS_ROUTE_SERVER_LOADER = "route-server-loaders";
|
|
43
|
-
const META_NAME = "modern-js";
|
|
44
|
-
const FOLD_IDENTIFIER = "@mf";
|
|
45
|
-
const SEPARATOR = "_";
|
|
46
|
-
const MF_ROUTES = "mf-routes";
|
|
47
|
-
const DEFAULT_ENTRY = "main";
|
|
48
|
-
const DEFAULT_LAYOUT = "layout";
|
|
49
|
-
const MF_JSON = "mf.json";
|
|
50
|
-
const ROUTE_ID = "ROUTE_ID";
|
|
51
29
|
// Annotate the CommonJS export names for ESM import in node:
|
|
52
30
|
0 && (module.exports = {
|
|
53
|
-
DEFAULT_ENTRY,
|
|
54
|
-
DEFAULT_LAYOUT,
|
|
55
|
-
FOLD_IDENTIFIER,
|
|
56
31
|
LOCALHOST,
|
|
57
|
-
META_NAME,
|
|
58
|
-
MF_JSON,
|
|
59
|
-
MF_ROUTES,
|
|
60
|
-
MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME,
|
|
61
|
-
MODERN_JS_ROUTE_SERVER_LOADER,
|
|
62
32
|
MODERN_JS_SERVER_DIR,
|
|
63
|
-
PLUGIN_IDENTIFIER
|
|
64
|
-
ROUTE_ID,
|
|
65
|
-
SEPARATOR,
|
|
66
|
-
isDev
|
|
33
|
+
PLUGIN_IDENTIFIER
|
|
67
34
|
});
|
|
@@ -19,16 +19,13 @@ 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
|
-
createRemoteSSRComponent: () => import_createRemoteSSRComponent.createRemoteSSRComponent
|
|
23
|
-
withMFRouteId: () => import_withMFRouteId.withMFRouteId
|
|
22
|
+
createRemoteSSRComponent: () => import_createRemoteSSRComponent.createRemoteSSRComponent
|
|
24
23
|
});
|
|
25
24
|
module.exports = __toCommonJS(runtime_exports);
|
|
26
25
|
__reExport(runtime_exports, require("@module-federation/enhanced/runtime"), module.exports);
|
|
27
26
|
var import_createRemoteSSRComponent = require("./createRemoteSSRComponent");
|
|
28
|
-
var import_withMFRouteId = require("./withMFRouteId");
|
|
29
27
|
// Annotate the CommonJS export names for ESM import in node:
|
|
30
28
|
0 && (module.exports = {
|
|
31
29
|
createRemoteSSRComponent,
|
|
32
|
-
withMFRouteId,
|
|
33
30
|
...require("@module-federation/enhanced/runtime")
|
|
34
31
|
});
|
|
@@ -34,16 +34,15 @@ module.exports = __toCommonJS(plugin_exports);
|
|
|
34
34
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
35
35
|
var import_hoist_non_react_statics = __toESM(require("hoist-non-react-statics"));
|
|
36
36
|
var import_SSRLiveReload = require("./SSRLiveReload");
|
|
37
|
-
const mfSSRPlugin = (
|
|
37
|
+
const mfSSRPlugin = () => ({
|
|
38
38
|
name: "@module-federation/modern-js",
|
|
39
|
-
pre: [
|
|
40
|
-
`@${metaName}/plugin-router`
|
|
41
|
-
],
|
|
42
39
|
setup: () => {
|
|
43
40
|
return {
|
|
44
|
-
async
|
|
41
|
+
async init({ context }, next) {
|
|
45
42
|
if (typeof window !== "undefined") {
|
|
46
|
-
return
|
|
43
|
+
return next({
|
|
44
|
+
context
|
|
45
|
+
});
|
|
47
46
|
}
|
|
48
47
|
globalThis.shouldUpdate = false;
|
|
49
48
|
const nodeUtils = await Promise.resolve().then(() => __toESM(require("@module-federation/node/utils")));
|
|
@@ -53,7 +52,9 @@ const mfSSRPlugin = ({ metaName }) => ({
|
|
|
53
52
|
await nodeUtils.flushChunks();
|
|
54
53
|
globalThis.shouldUpdate = true;
|
|
55
54
|
}
|
|
56
|
-
return
|
|
55
|
+
return next({
|
|
56
|
+
context
|
|
57
|
+
});
|
|
57
58
|
},
|
|
58
59
|
wrapRoot(App) {
|
|
59
60
|
const AppWrapper = (props) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
|
package/dist/esm/cli/index.js
CHANGED
|
@@ -5,7 +5,6 @@ import { ModuleFederationPlugin as WebpackModuleFederationPlugin, AsyncBoundaryP
|
|
|
5
5
|
import { ModuleFederationPlugin as RspackModuleFederationPlugin } from "@module-federation/enhanced/rspack";
|
|
6
6
|
import { moduleFederationConfigPlugin } from "./configPlugin";
|
|
7
7
|
import { moduleFederationSSRPlugin } from "./ssrPlugin";
|
|
8
|
-
import { moduleFederationRoutesPlugin } from "./routes/plugin";
|
|
9
8
|
var moduleFederationPlugin = function() {
|
|
10
9
|
var userConfig = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
11
10
|
var internalModernPluginOptions = {
|
|
@@ -15,7 +14,7 @@ var moduleFederationPlugin = function() {
|
|
|
15
14
|
nodePlugin: void 0,
|
|
16
15
|
distOutputDir: "",
|
|
17
16
|
originPluginOptions: userConfig,
|
|
18
|
-
remoteIpStrategy: void 0
|
|
17
|
+
remoteIpStrategy: userConfig === null || userConfig === void 0 ? void 0 : userConfig.remoteIpStrategy
|
|
19
18
|
};
|
|
20
19
|
return {
|
|
21
20
|
name: "@modern-js/plugin-module-federation",
|
|
@@ -81,11 +80,7 @@ var moduleFederationPlugin = function() {
|
|
|
81
80
|
}(),
|
|
82
81
|
usePlugins: [
|
|
83
82
|
moduleFederationConfigPlugin(internalModernPluginOptions),
|
|
84
|
-
moduleFederationSSRPlugin(internalModernPluginOptions)
|
|
85
|
-
moduleFederationRoutesPlugin({
|
|
86
|
-
userConfig,
|
|
87
|
-
internalOptions: internalModernPluginOptions
|
|
88
|
-
})
|
|
83
|
+
moduleFederationSSRPlugin(internalModernPluginOptions)
|
|
89
84
|
]
|
|
90
85
|
};
|
|
91
86
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import nodeFetch from "node-fetch";
|
|
2
2
|
var injectNodeFetchPlugin = function() {
|
|
3
3
|
return {
|
|
4
|
-
name: "node-fetch-plugin",
|
|
4
|
+
name: "inject-node-fetch-plugin",
|
|
5
5
|
beforeInit: function beforeInit(args) {
|
|
6
6
|
if (!globalThis.fetch) {
|
|
7
7
|
globalThis.fetch = nodeFetch;
|
|
@@ -10,7 +10,7 @@ var injectNodeFetchPlugin = function() {
|
|
|
10
10
|
}
|
|
11
11
|
};
|
|
12
12
|
};
|
|
13
|
-
var
|
|
13
|
+
var inject_node_fetch_default = injectNodeFetchPlugin;
|
|
14
14
|
export {
|
|
15
|
-
|
|
15
|
+
inject_node_fetch_default as default
|
|
16
16
|
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
var sharedStrategy = function() {
|
|
2
|
+
return {
|
|
3
|
+
name: "shared-strategy-plugin",
|
|
4
|
+
beforeInit: function beforeInit(args) {
|
|
5
|
+
var userOptions = args.userOptions;
|
|
6
|
+
var shared = userOptions.shared;
|
|
7
|
+
if (shared) {
|
|
8
|
+
Object.keys(shared).forEach(function(sharedKey) {
|
|
9
|
+
var sharedConfigs = shared[sharedKey];
|
|
10
|
+
var arraySharedConfigs = Array.isArray(sharedConfigs) ? sharedConfigs : [
|
|
11
|
+
sharedConfigs
|
|
12
|
+
];
|
|
13
|
+
arraySharedConfigs.forEach(function(s) {
|
|
14
|
+
s.strategy = "loaded-first";
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return args;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
var shared_strategy_default = sharedStrategy;
|
|
23
|
+
export {
|
|
24
|
+
shared_strategy_default as default
|
|
25
|
+
};
|
|
@@ -6,7 +6,7 @@ import { ModuleFederationPlugin } from "@module-federation/enhanced/webpack";
|
|
|
6
6
|
import { ModuleFederationPlugin as RspackModuleFederationPlugin } from "@module-federation/enhanced/rspack";
|
|
7
7
|
import UniverseEntryChunkTrackerPlugin from "@module-federation/node/universe-entry-chunk-tracker-plugin";
|
|
8
8
|
import { updateStatsAndManifest } from "./manifest";
|
|
9
|
-
import { isDev
|
|
9
|
+
import { isDev } from "./constant";
|
|
10
10
|
function setEnv() {
|
|
11
11
|
process.env["MF_DISABLE_EMIT_STATS"] = "true";
|
|
12
12
|
process.env["MF_SSR_PRJ"] = "true";
|
|
@@ -20,11 +20,10 @@ var moduleFederationSSRPlugin = function(userConfig) {
|
|
|
20
20
|
],
|
|
21
21
|
setup: function() {
|
|
22
22
|
var _ref = _async_to_generator(function(param) {
|
|
23
|
-
var useConfigContext, useAppContext, _modernjsConfig_server, modernjsConfig,
|
|
23
|
+
var useConfigContext, useAppContext, _modernjsConfig_server, modernjsConfig, enableSSR;
|
|
24
24
|
return _ts_generator(this, function(_state) {
|
|
25
25
|
useConfigContext = param.useConfigContext, useAppContext = param.useAppContext;
|
|
26
26
|
modernjsConfig = useConfigContext();
|
|
27
|
-
_userConfig_metaName = userConfig.metaName, metaName = _userConfig_metaName === void 0 ? META_NAME : _userConfig_metaName;
|
|
28
27
|
enableSSR = Boolean(modernjsConfig === null || modernjsConfig === void 0 ? void 0 : (_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
|
|
29
28
|
if (!enableSSR) {
|
|
30
29
|
return [
|
|
@@ -47,9 +46,7 @@ var moduleFederationSSRPlugin = function(userConfig) {
|
|
|
47
46
|
plugins.push({
|
|
48
47
|
name: "mfSSR",
|
|
49
48
|
path: "@module-federation/modern-js/ssr-runtime",
|
|
50
|
-
config: {
|
|
51
|
-
metaName
|
|
52
|
-
}
|
|
49
|
+
config: {}
|
|
53
50
|
});
|
|
54
51
|
return {
|
|
55
52
|
entrypoint,
|
package/dist/esm/cli/utils.js
CHANGED
|
@@ -80,9 +80,7 @@ var replaceRemoteUrl = function(mfConfig, remoteIpStrategy) {
|
|
|
80
80
|
if (typeof remoteObject === "string") {
|
|
81
81
|
return;
|
|
82
82
|
}
|
|
83
|
-
|
|
84
|
-
remoteObject.entry = remoteObject.entry.replace(LOCALHOST, ipv4);
|
|
85
|
-
}
|
|
83
|
+
handleRemoteObject(remoteObject);
|
|
86
84
|
});
|
|
87
85
|
} else if (typeof mfConfig.remotes !== "string") {
|
|
88
86
|
handleRemoteObject(mfConfig.remotes);
|
|
@@ -129,18 +127,17 @@ var patchMFConfig = function(mfConfig, isServer, remoteIpStrategy) {
|
|
|
129
127
|
throw new Error("".concat(PLUGIN_IDENTIFIER, " mfConfig.name can not be empty!"));
|
|
130
128
|
}
|
|
131
129
|
var runtimePlugins = _to_consumable_array(mfConfig.runtimePlugins || []);
|
|
132
|
-
var _mfConfig_shareStrategy;
|
|
133
|
-
mfConfig.shareStrategy = (_mfConfig_shareStrategy = mfConfig.shareStrategy) !== null && _mfConfig_shareStrategy !== void 0 ? _mfConfig_shareStrategy : "loaded-first";
|
|
134
130
|
patchDTSConfig(mfConfig, isServer);
|
|
131
|
+
injectRuntimePlugins(path.resolve(__dirname, "./mfRuntimePlugins/shared-strategy.js"), runtimePlugins);
|
|
135
132
|
if (isDev) {
|
|
136
133
|
injectRuntimePlugins(path.resolve(__dirname, "./mfRuntimePlugins/resolve-entry-ipv4.js"), runtimePlugins);
|
|
137
134
|
}
|
|
138
135
|
if (isServer) {
|
|
139
|
-
injectRuntimePlugins(
|
|
136
|
+
injectRuntimePlugins(require.resolve("@module-federation/node/runtimePlugin"), runtimePlugins);
|
|
140
137
|
if (isDev) {
|
|
141
138
|
injectRuntimePlugins(require.resolve("@module-federation/node/record-dynamic-remote-entry-hash-plugin"), runtimePlugins);
|
|
142
139
|
}
|
|
143
|
-
injectRuntimePlugins(path.resolve(__dirname, "./mfRuntimePlugins/node-fetch.js"), runtimePlugins);
|
|
140
|
+
injectRuntimePlugins(path.resolve(__dirname, "./mfRuntimePlugins/inject-node-fetch.js"), runtimePlugins);
|
|
144
141
|
if (!mfConfig.library) {
|
|
145
142
|
mfConfig.library = {
|
|
146
143
|
type: "commonjs-module",
|
|
@@ -343,6 +340,5 @@ export {
|
|
|
343
340
|
getMFConfig,
|
|
344
341
|
patchBundlerConfig,
|
|
345
342
|
patchIgnoreWarning,
|
|
346
|
-
patchMFConfig
|
|
347
|
-
replaceRemoteUrl
|
|
343
|
+
patchMFConfig
|
|
348
344
|
};
|
|
@@ -41,10 +41,10 @@ describe("patchMFConfig", /* @__PURE__ */ _async_to_generator(function() {
|
|
|
41
41
|
remote: "http://".concat(ipv4, ":3000/remoteEntry.js")
|
|
42
42
|
},
|
|
43
43
|
remoteType: "script",
|
|
44
|
-
shareStrategy: "loaded-first",
|
|
45
44
|
runtimePlugins: [
|
|
46
|
-
path.resolve(__dirname, "./mfRuntimePlugins/
|
|
47
|
-
|
|
45
|
+
path.resolve(__dirname, "./mfRuntimePlugins/shared-strategy.js"),
|
|
46
|
+
require.resolve("@module-federation/node/runtimePlugin"),
|
|
47
|
+
path.resolve(__dirname, "./mfRuntimePlugins/inject-node-fetch.js")
|
|
48
48
|
],
|
|
49
49
|
shared: {
|
|
50
50
|
react: {
|
|
@@ -75,8 +75,9 @@ describe("patchMFConfig", /* @__PURE__ */ _async_to_generator(function() {
|
|
|
75
75
|
remote: "http://".concat(ipv4, ":3000/remoteEntry.js")
|
|
76
76
|
},
|
|
77
77
|
remoteType: "script",
|
|
78
|
-
runtimePlugins: [
|
|
79
|
-
|
|
78
|
+
runtimePlugins: [
|
|
79
|
+
path.resolve(__dirname, "./mfRuntimePlugins/shared-strategy.js")
|
|
80
|
+
],
|
|
80
81
|
shared: {
|
|
81
82
|
react: {
|
|
82
83
|
eager: true,
|
package/dist/esm/constant.js
CHANGED
|
@@ -1,30 +1,8 @@
|
|
|
1
1
|
var MODERN_JS_SERVER_DIR = "bundles";
|
|
2
2
|
var LOCALHOST = "localhost";
|
|
3
3
|
var PLUGIN_IDENTIFIER = "[ Modern.js Module Federation ]";
|
|
4
|
-
var isDev = process.env.NODE_ENV === "development";
|
|
5
|
-
var MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME = "routes";
|
|
6
|
-
var MODERN_JS_ROUTE_SERVER_LOADER = "route-server-loaders";
|
|
7
|
-
var META_NAME = "modern-js";
|
|
8
|
-
var FOLD_IDENTIFIER = "@mf";
|
|
9
|
-
var SEPARATOR = "_";
|
|
10
|
-
var MF_ROUTES = "mf-routes";
|
|
11
|
-
var DEFAULT_ENTRY = "main";
|
|
12
|
-
var DEFAULT_LAYOUT = "layout";
|
|
13
|
-
var MF_JSON = "mf.json";
|
|
14
|
-
var ROUTE_ID = "ROUTE_ID";
|
|
15
4
|
export {
|
|
16
|
-
DEFAULT_ENTRY,
|
|
17
|
-
DEFAULT_LAYOUT,
|
|
18
|
-
FOLD_IDENTIFIER,
|
|
19
5
|
LOCALHOST,
|
|
20
|
-
META_NAME,
|
|
21
|
-
MF_JSON,
|
|
22
|
-
MF_ROUTES,
|
|
23
|
-
MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME,
|
|
24
|
-
MODERN_JS_ROUTE_SERVER_LOADER,
|
|
25
6
|
MODERN_JS_SERVER_DIR,
|
|
26
|
-
PLUGIN_IDENTIFIER
|
|
27
|
-
ROUTE_ID,
|
|
28
|
-
SEPARATOR,
|
|
29
|
-
isDev
|
|
7
|
+
PLUGIN_IDENTIFIER
|
|
30
8
|
};
|