@module-federation/modern-js 0.0.0-next-20240910102933 → 0.0.0-next-20240911025819
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/configPlugin.js +4 -2
- package/dist/cjs/cli/{dataLoader/ast/index.js → constant.js} +6 -6
- package/dist/cjs/cli/index.js +1 -5
- 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 +1 -7
- package/dist/cjs/cli/utils.js +8 -13
- package/dist/cjs/cli/utils.spec.js +6 -5
- package/dist/cjs/constant.js +2 -32
- package/dist/cjs/runtime/index.js +1 -4
- package/dist/cjs/ssr-runtime/plugin.js +7 -7
- package/dist/esm/cli/configPlugin.js +3 -2
- package/dist/esm/cli/constant.js +4 -0
- package/dist/esm/cli/index.js +1 -4
- 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 +1 -6
- package/dist/esm/cli/utils.js +7 -11
- package/dist/esm/cli/utils.spec.js +6 -5
- package/dist/esm/constant.js +1 -21
- package/dist/esm/runtime/index.js +1 -3
- package/dist/esm/ssr-runtime/plugin.js +10 -7
- package/dist/esm-node/cli/configPlugin.js +4 -2
- package/dist/esm-node/cli/constant.js +4 -0
- package/dist/esm-node/cli/index.js +1 -5
- 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 +1 -7
- package/dist/esm-node/cli/utils.js +7 -11
- package/dist/esm-node/cli/utils.spec.js +6 -5
- package/dist/esm-node/constant.js +1 -21
- package/dist/esm-node/runtime/index.js +1 -3
- package/dist/esm-node/ssr-runtime/plugin.js +7 -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 -10
- package/dist/types/runtime/index.d.ts +0 -1
- package/dist/types/types/index.d.ts +0 -9
- package/package.json +11 -48
- package/dist/cjs/cli/dataLoader/ast/constant.js +0 -49
- package/dist/cjs/cli/dataLoader/ast/generateRoutes.js +0 -141
- package/dist/cjs/cli/dataLoader/generateRouteFile.js +0 -143
- package/dist/cjs/cli/dataLoader/patchMFConfig.js +0 -140
- package/dist/cjs/cli/dataLoader/plugin.js +0 -199
- package/dist/cjs/cli/mfRuntimePlugins/node.js +0 -41
- package/dist/cjs/cli/server/dataLoaderPlugin.js +0 -82
- package/dist/cjs/cli/server/fetchRemoteFullRoutesMap.js +0 -69
- package/dist/cjs/interfaces/route.js +0 -16
- package/dist/cjs/runtime/dataLoader/plugin-inject-assets.js +0 -84
- package/dist/cjs/runtime/dataLoader/plugin.js +0 -74
- package/dist/cjs/runtime/dataLoader/utils.js +0 -106
- package/dist/esm/cli/dataLoader/ast/constant.js +0 -18
- package/dist/esm/cli/dataLoader/ast/generateRoutes.js +0 -108
- package/dist/esm/cli/dataLoader/ast/index.js +0 -4
- package/dist/esm/cli/dataLoader/generateRouteFile.js +0 -293
- package/dist/esm/cli/dataLoader/patchMFConfig.js +0 -106
- package/dist/esm/cli/dataLoader/plugin.js +0 -214
- package/dist/esm/cli/mfRuntimePlugins/node.js +0 -13
- package/dist/esm/cli/server/dataLoaderPlugin.js +0 -105
- package/dist/esm/cli/server/fetchRemoteFullRoutesMap.js +0 -88
- package/dist/esm/interfaces/route.js +0 -0
- package/dist/esm/runtime/dataLoader/plugin-inject-assets.js +0 -63
- package/dist/esm/runtime/dataLoader/plugin.js +0 -93
- package/dist/esm/runtime/dataLoader/utils.js +0 -77
- package/dist/esm/runtime/withMFRouteId.js +0 -7
- package/dist/esm-node/cli/dataLoader/ast/constant.js +0 -18
- package/dist/esm-node/cli/dataLoader/ast/generateRoutes.js +0 -107
- package/dist/esm-node/cli/dataLoader/ast/index.js +0 -4
- package/dist/esm-node/cli/dataLoader/generateRouteFile.js +0 -108
- package/dist/esm-node/cli/dataLoader/patchMFConfig.js +0 -106
- package/dist/esm-node/cli/dataLoader/plugin.js +0 -164
- package/dist/esm-node/cli/mfRuntimePlugins/node.js +0 -11
- package/dist/esm-node/cli/server/dataLoaderPlugin.js +0 -62
- package/dist/esm-node/cli/server/fetchRemoteFullRoutesMap.js +0 -44
- package/dist/esm-node/interfaces/route.js +0 -0
- package/dist/esm-node/runtime/dataLoader/plugin-inject-assets.js +0 -60
- package/dist/esm-node/runtime/dataLoader/plugin.js +0 -50
- package/dist/esm-node/runtime/dataLoader/utils.js +0 -77
- package/dist/esm-node/runtime/withMFRouteId.js +0 -7
- package/dist/types/cli/dataLoader/ast/constant.d.ts +0 -8
- package/dist/types/cli/dataLoader/ast/generateRoutes.d.ts +0 -5
- package/dist/types/cli/dataLoader/ast/index.d.ts +0 -1
- package/dist/types/cli/dataLoader/generateRouteFile.d.ts +0 -7
- package/dist/types/cli/dataLoader/patchMFConfig.d.ts +0 -10
- package/dist/types/cli/dataLoader/plugin.d.ts +0 -6
- package/dist/types/cli/mfRuntimePlugins/node.d.ts +0 -3
- package/dist/types/cli/server/dataLoaderPlugin.d.ts +0 -10
- package/dist/types/cli/server/fetchRemoteFullRoutesMap.d.ts +0 -10
- package/dist/types/interfaces/route.d.ts +0 -12
- package/dist/types/runtime/dataLoader/plugin-inject-assets.d.ts +0 -2
- package/dist/types/runtime/dataLoader/plugin.d.ts +0 -2
- package/dist/types/runtime/dataLoader/utils.d.ts +0 -22
- package/dist/types/runtime/withMFRouteId.d.ts +0 -1
- /package/dist/types/cli/mfRuntimePlugins/{node-fetch.d.ts → inject-node-fetch.d.ts} +0 -0
package/dist/esm/constant.js
CHANGED
|
@@ -1,28 +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
4
|
export {
|
|
15
|
-
DEFAULT_ENTRY,
|
|
16
|
-
DEFAULT_LAYOUT,
|
|
17
|
-
FOLD_IDENTIFIER,
|
|
18
5
|
LOCALHOST,
|
|
19
|
-
META_NAME,
|
|
20
|
-
MF_JSON,
|
|
21
|
-
MF_ROUTES,
|
|
22
|
-
MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME,
|
|
23
|
-
MODERN_JS_ROUTE_SERVER_LOADER,
|
|
24
6
|
MODERN_JS_SERVER_DIR,
|
|
25
|
-
PLUGIN_IDENTIFIER
|
|
26
|
-
SEPARATOR,
|
|
27
|
-
isDev
|
|
7
|
+
PLUGIN_IDENTIFIER
|
|
28
8
|
};
|
|
@@ -4,16 +4,13 @@ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
|
4
4
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
5
5
|
import hoistNonReactStatics from "hoist-non-react-statics";
|
|
6
6
|
import { SSRLiveReload } from "./SSRLiveReload";
|
|
7
|
-
console.log("mfSSRPlugin trigger");
|
|
8
7
|
var mfSSRPlugin = function() {
|
|
9
8
|
return {
|
|
10
9
|
name: "@module-federation/modern-js",
|
|
11
|
-
pre: [
|
|
12
|
-
"@modern-js/plugin-router"
|
|
13
|
-
],
|
|
14
10
|
setup: function() {
|
|
15
11
|
return {
|
|
16
|
-
|
|
12
|
+
init: function init(param, next) {
|
|
13
|
+
var context = param.context;
|
|
17
14
|
return _async_to_generator(function() {
|
|
18
15
|
var nodeUtils, shouldUpdate;
|
|
19
16
|
return _ts_generator(this, function(_state) {
|
|
@@ -21,7 +18,10 @@ var mfSSRPlugin = function() {
|
|
|
21
18
|
case 0:
|
|
22
19
|
if (typeof window !== "undefined") {
|
|
23
20
|
return [
|
|
24
|
-
2
|
|
21
|
+
2,
|
|
22
|
+
next({
|
|
23
|
+
context
|
|
24
|
+
})
|
|
25
25
|
];
|
|
26
26
|
}
|
|
27
27
|
globalThis.shouldUpdate = false;
|
|
@@ -53,7 +53,10 @@ var mfSSRPlugin = function() {
|
|
|
53
53
|
_state.label = 4;
|
|
54
54
|
case 4:
|
|
55
55
|
return [
|
|
56
|
-
2
|
|
56
|
+
2,
|
|
57
|
+
next({
|
|
58
|
+
context
|
|
59
|
+
})
|
|
57
60
|
];
|
|
58
61
|
}
|
|
59
62
|
});
|
|
@@ -31,7 +31,7 @@ const moduleFederationConfigPlugin = (userConfig) => ({
|
|
|
31
31
|
userConfig.csrConfig = csrConfig;
|
|
32
32
|
return {
|
|
33
33
|
config: async () => {
|
|
34
|
-
var _modernjsConfig_server, _modernjsConfig_dev;
|
|
34
|
+
var _modernjsConfig_server, _modernjsConfig_source, _modernjsConfig_source1, _modernjsConfig_dev;
|
|
35
35
|
const bundlerType = useAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
|
|
36
36
|
const ipv4 = getIPV4();
|
|
37
37
|
const enableSSR = Boolean(modernjsConfig === null || modernjsConfig === void 0 ? void 0 : (_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
|
|
@@ -42,6 +42,7 @@ const moduleFederationConfigPlugin = (userConfig) => ({
|
|
|
42
42
|
userConfig.remoteIpStrategy = "ipv4";
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
|
+
var _modernjsConfig_source_enableAsyncEntry;
|
|
45
46
|
return {
|
|
46
47
|
tools: {
|
|
47
48
|
rspack(config, { isServer }) {
|
|
@@ -83,7 +84,8 @@ const moduleFederationConfigPlugin = (userConfig) => ({
|
|
|
83
84
|
define: {
|
|
84
85
|
FEDERATION_IPV4: JSON.stringify(ipv4),
|
|
85
86
|
REMOTE_IP_STRATEGY: JSON.stringify(userConfig.remoteIpStrategy)
|
|
86
|
-
}
|
|
87
|
+
},
|
|
88
|
+
enableAsyncEntry: bundlerType === "rspack" ? (_modernjsConfig_source_enableAsyncEntry = (_modernjsConfig_source = modernjsConfig.source) === null || _modernjsConfig_source === void 0 ? void 0 : _modernjsConfig_source.enableAsyncEntry) !== null && _modernjsConfig_source_enableAsyncEntry !== void 0 ? _modernjsConfig_source_enableAsyncEntry : true : (_modernjsConfig_source1 = modernjsConfig.source) === null || _modernjsConfig_source1 === void 0 ? void 0 : _modernjsConfig_source1.enableAsyncEntry
|
|
87
89
|
},
|
|
88
90
|
dev: {
|
|
89
91
|
assetPrefix: (modernjsConfig === null || modernjsConfig === void 0 ? void 0 : (_modernjsConfig_dev = modernjsConfig.dev) === null || _modernjsConfig_dev === void 0 ? void 0 : _modernjsConfig_dev.assetPrefix) ? modernjsConfig.dev.assetPrefix : true
|
|
@@ -2,7 +2,6 @@ import { ModuleFederationPlugin as WebpackModuleFederationPlugin, AsyncBoundaryP
|
|
|
2
2
|
import { ModuleFederationPlugin as RspackModuleFederationPlugin } from "@module-federation/enhanced/rspack";
|
|
3
3
|
import { moduleFederationConfigPlugin } from "./configPlugin";
|
|
4
4
|
import { moduleFederationSSRPlugin } from "./ssrPlugin";
|
|
5
|
-
import { moduleFederationDataLoaderPlugin } from "./dataLoader/plugin";
|
|
6
5
|
const moduleFederationPlugin = (userConfig = {}) => {
|
|
7
6
|
const internalModernPluginOptions = {
|
|
8
7
|
csrConfig: void 0,
|
|
@@ -54,10 +53,7 @@ const moduleFederationPlugin = (userConfig = {}) => {
|
|
|
54
53
|
},
|
|
55
54
|
usePlugins: [
|
|
56
55
|
moduleFederationConfigPlugin(internalModernPluginOptions),
|
|
57
|
-
moduleFederationSSRPlugin(internalModernPluginOptions)
|
|
58
|
-
moduleFederationDataLoaderPlugin(Boolean(userConfig.dataLoader), internalModernPluginOptions, {
|
|
59
|
-
...typeof userConfig.dataLoader === "boolean" ? {} : userConfig.dataLoader
|
|
60
|
-
})
|
|
56
|
+
moduleFederationSSRPlugin(internalModernPluginOptions)
|
|
61
57
|
]
|
|
62
58
|
};
|
|
63
59
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import nodeFetch from "node-fetch";
|
|
2
2
|
const injectNodeFetchPlugin = () => ({
|
|
3
|
-
name: "node-fetch-plugin",
|
|
3
|
+
name: "inject-node-fetch-plugin",
|
|
4
4
|
beforeInit(args) {
|
|
5
5
|
if (!globalThis.fetch) {
|
|
6
6
|
globalThis.fetch = nodeFetch;
|
|
@@ -8,7 +8,7 @@ const injectNodeFetchPlugin = () => ({
|
|
|
8
8
|
return args;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
var
|
|
11
|
+
var inject_node_fetch_default = injectNodeFetchPlugin;
|
|
12
12
|
export {
|
|
13
|
-
|
|
13
|
+
inject_node_fetch_default as default
|
|
14
14
|
};
|
|
@@ -16,48 +16,46 @@ function replaceObjectLocalhost(key, obj) {
|
|
|
16
16
|
function replaceLocalhost(url) {
|
|
17
17
|
return url.replace(LOCALHOST, ipv4);
|
|
18
18
|
}
|
|
19
|
-
const resolveEntryIpv4Plugin = () => {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
replaceObjectLocalhost("entry", moduleInfo);
|
|
36
|
-
return args;
|
|
37
|
-
}
|
|
38
|
-
if ("version" in moduleInfo) {
|
|
39
|
-
replaceObjectLocalhost("version", moduleInfo);
|
|
40
|
-
}
|
|
41
|
-
return args;
|
|
42
|
-
},
|
|
43
|
-
loadRemoteSnapshot(args) {
|
|
44
|
-
const { remoteSnapshot } = args;
|
|
45
|
-
if ("publicPath" in remoteSnapshot) {
|
|
46
|
-
replaceObjectLocalhost("publicPath", remoteSnapshot);
|
|
47
|
-
}
|
|
48
|
-
if ("getPublicPath" in remoteSnapshot) {
|
|
49
|
-
replaceObjectLocalhost("getPublicPath", remoteSnapshot);
|
|
50
|
-
}
|
|
51
|
-
if (remoteSnapshot.remotesInfo) {
|
|
52
|
-
Object.keys(remoteSnapshot.remotesInfo).forEach((key) => {
|
|
53
|
-
const remoteInfo = remoteSnapshot.remotesInfo[key];
|
|
54
|
-
replaceObjectLocalhost("matchedVersion", remoteInfo);
|
|
55
|
-
});
|
|
56
|
-
}
|
|
19
|
+
const resolveEntryIpv4Plugin = () => ({
|
|
20
|
+
name: "resolve-entry-ipv4",
|
|
21
|
+
beforeRegisterRemote(args) {
|
|
22
|
+
const { remote } = args;
|
|
23
|
+
replaceObjectLocalhost("entry", remote);
|
|
24
|
+
return args;
|
|
25
|
+
},
|
|
26
|
+
async afterResolve(args) {
|
|
27
|
+
const { remoteInfo } = args;
|
|
28
|
+
replaceObjectLocalhost("entry", remoteInfo);
|
|
29
|
+
return args;
|
|
30
|
+
},
|
|
31
|
+
beforeLoadRemoteSnapshot(args) {
|
|
32
|
+
const { moduleInfo } = args;
|
|
33
|
+
if ("entry" in moduleInfo) {
|
|
34
|
+
replaceObjectLocalhost("entry", moduleInfo);
|
|
57
35
|
return args;
|
|
58
36
|
}
|
|
59
|
-
|
|
60
|
-
|
|
37
|
+
if ("version" in moduleInfo) {
|
|
38
|
+
replaceObjectLocalhost("version", moduleInfo);
|
|
39
|
+
}
|
|
40
|
+
return args;
|
|
41
|
+
},
|
|
42
|
+
loadRemoteSnapshot(args) {
|
|
43
|
+
const { remoteSnapshot } = args;
|
|
44
|
+
if ("publicPath" in remoteSnapshot) {
|
|
45
|
+
replaceObjectLocalhost("publicPath", remoteSnapshot);
|
|
46
|
+
}
|
|
47
|
+
if ("getPublicPath" in remoteSnapshot) {
|
|
48
|
+
replaceObjectLocalhost("getPublicPath", remoteSnapshot);
|
|
49
|
+
}
|
|
50
|
+
if (remoteSnapshot.remotesInfo) {
|
|
51
|
+
Object.keys(remoteSnapshot.remotesInfo).forEach((key) => {
|
|
52
|
+
const remoteInfo = remoteSnapshot.remotesInfo[key];
|
|
53
|
+
replaceObjectLocalhost("matchedVersion", remoteInfo);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return args;
|
|
57
|
+
}
|
|
58
|
+
});
|
|
61
59
|
var resolve_entry_ipv4_default = resolveEntryIpv4Plugin;
|
|
62
60
|
export {
|
|
63
61
|
resolve_entry_ipv4_default as default
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const sharedStrategy = () => ({
|
|
2
|
+
name: "shared-strategy-plugin",
|
|
3
|
+
beforeInit(args) {
|
|
4
|
+
const { userOptions } = args;
|
|
5
|
+
const shared = userOptions.shared;
|
|
6
|
+
if (shared) {
|
|
7
|
+
Object.keys(shared).forEach((sharedKey) => {
|
|
8
|
+
const sharedConfigs = shared[sharedKey];
|
|
9
|
+
const arraySharedConfigs = Array.isArray(sharedConfigs) ? sharedConfigs : [
|
|
10
|
+
sharedConfigs
|
|
11
|
+
];
|
|
12
|
+
arraySharedConfigs.forEach((s) => {
|
|
13
|
+
s.strategy = "loaded-first";
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return args;
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
var shared_strategy_default = sharedStrategy;
|
|
21
|
+
export {
|
|
22
|
+
shared_strategy_default as default
|
|
23
|
+
};
|
|
@@ -4,7 +4,7 @@ import { ModuleFederationPlugin } from "@module-federation/enhanced/webpack";
|
|
|
4
4
|
import { ModuleFederationPlugin as RspackModuleFederationPlugin } from "@module-federation/enhanced/rspack";
|
|
5
5
|
import UniverseEntryChunkTrackerPlugin from "@module-federation/node/universe-entry-chunk-tracker-plugin";
|
|
6
6
|
import { updateStatsAndManifest } from "./manifest";
|
|
7
|
-
import { isDev } from "
|
|
7
|
+
import { isDev } from "./constant";
|
|
8
8
|
function setEnv() {
|
|
9
9
|
process.env["MF_DISABLE_EMIT_STATS"] = "true";
|
|
10
10
|
process.env["MF_SSR_PRJ"] = "true";
|
|
@@ -42,13 +42,7 @@ const moduleFederationSSRPlugin = (userConfig) => ({
|
|
|
42
42
|
};
|
|
43
43
|
},
|
|
44
44
|
config: async () => {
|
|
45
|
-
var _modernjsConfig_source, _modernjsConfig_source1;
|
|
46
|
-
const bundlerType = useAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
|
|
47
|
-
var _modernjsConfig_source_enableAsyncEntry;
|
|
48
45
|
return {
|
|
49
|
-
source: {
|
|
50
|
-
enableAsyncEntry: bundlerType === "rspack" ? (_modernjsConfig_source_enableAsyncEntry = (_modernjsConfig_source = modernjsConfig.source) === null || _modernjsConfig_source === void 0 ? void 0 : _modernjsConfig_source.enableAsyncEntry) !== null && _modernjsConfig_source_enableAsyncEntry !== void 0 ? _modernjsConfig_source_enableAsyncEntry : true : (_modernjsConfig_source1 = modernjsConfig.source) === null || _modernjsConfig_source1 === void 0 ? void 0 : _modernjsConfig_source1.enableAsyncEntry
|
|
51
|
-
},
|
|
52
46
|
tools: {
|
|
53
47
|
rspack(config, { isServer }) {
|
|
54
48
|
if (isServer) {
|
|
@@ -47,9 +47,7 @@ const replaceRemoteUrl = (mfConfig, remoteIpStrategy) => {
|
|
|
47
47
|
if (typeof remoteObject === "string") {
|
|
48
48
|
return;
|
|
49
49
|
}
|
|
50
|
-
|
|
51
|
-
remoteObject.entry = remoteObject.entry.replace(LOCALHOST, ipv4);
|
|
52
|
-
}
|
|
50
|
+
handleRemoteObject(remoteObject);
|
|
53
51
|
});
|
|
54
52
|
} else if (typeof mfConfig.remotes !== "string") {
|
|
55
53
|
handleRemoteObject(mfConfig.remotes);
|
|
@@ -98,18 +96,17 @@ const patchMFConfig = (mfConfig, isServer, remoteIpStrategy) => {
|
|
|
98
96
|
const runtimePlugins = [
|
|
99
97
|
...mfConfig.runtimePlugins || []
|
|
100
98
|
];
|
|
101
|
-
var _mfConfig_shareStrategy;
|
|
102
|
-
mfConfig.shareStrategy = (_mfConfig_shareStrategy = mfConfig.shareStrategy) !== null && _mfConfig_shareStrategy !== void 0 ? _mfConfig_shareStrategy : "loaded-first";
|
|
103
99
|
patchDTSConfig(mfConfig, isServer);
|
|
100
|
+
injectRuntimePlugins(path.resolve(__dirname, "./mfRuntimePlugins/shared-strategy.js"), runtimePlugins);
|
|
104
101
|
if (isDev) {
|
|
105
102
|
injectRuntimePlugins(path.resolve(__dirname, "./mfRuntimePlugins/resolve-entry-ipv4.js"), runtimePlugins);
|
|
106
103
|
}
|
|
107
104
|
if (isServer) {
|
|
108
|
-
injectRuntimePlugins(
|
|
105
|
+
injectRuntimePlugins(require.resolve("@module-federation/node/runtimePlugin"), runtimePlugins);
|
|
109
106
|
if (isDev) {
|
|
110
107
|
injectRuntimePlugins(require.resolve("@module-federation/node/record-dynamic-remote-entry-hash-plugin"), runtimePlugins);
|
|
111
108
|
}
|
|
112
|
-
injectRuntimePlugins(path.resolve(__dirname, "./mfRuntimePlugins/node-fetch.js"), runtimePlugins);
|
|
109
|
+
injectRuntimePlugins(path.resolve(__dirname, "./mfRuntimePlugins/inject-node-fetch.js"), runtimePlugins);
|
|
113
110
|
if (!mfConfig.library) {
|
|
114
111
|
mfConfig.library = {
|
|
115
112
|
type: "commonjs-module",
|
|
@@ -249,8 +246,8 @@ const getIPV4 = () => {
|
|
|
249
246
|
return ipv4Interface.address;
|
|
250
247
|
};
|
|
251
248
|
const SPLIT_CHUNK_MAP = {
|
|
252
|
-
REACT: "
|
|
253
|
-
ROUTER: "
|
|
249
|
+
REACT: "react",
|
|
250
|
+
ROUTER: "router",
|
|
254
251
|
LODASH: "lib-lodash",
|
|
255
252
|
ANTD: "lib-antd",
|
|
256
253
|
ARCO: "lib-arco",
|
|
@@ -294,6 +291,5 @@ export {
|
|
|
294
291
|
getMFConfig,
|
|
295
292
|
patchBundlerConfig,
|
|
296
293
|
patchIgnoreWarning,
|
|
297
|
-
patchMFConfig
|
|
298
|
-
replaceRemoteUrl
|
|
294
|
+
patchMFConfig
|
|
299
295
|
};
|
|
@@ -36,10 +36,10 @@ describe("patchMFConfig", async () => {
|
|
|
36
36
|
remote: `http://${ipv4}:3000/remoteEntry.js`
|
|
37
37
|
},
|
|
38
38
|
remoteType: "script",
|
|
39
|
-
shareStrategy: "loaded-first",
|
|
40
39
|
runtimePlugins: [
|
|
41
|
-
path.resolve(__dirname, "./mfRuntimePlugins/
|
|
42
|
-
|
|
40
|
+
path.resolve(__dirname, "./mfRuntimePlugins/shared-strategy.js"),
|
|
41
|
+
require.resolve("@module-federation/node/runtimePlugin"),
|
|
42
|
+
path.resolve(__dirname, "./mfRuntimePlugins/inject-node-fetch.js")
|
|
43
43
|
],
|
|
44
44
|
shared: {
|
|
45
45
|
react: {
|
|
@@ -64,8 +64,9 @@ describe("patchMFConfig", async () => {
|
|
|
64
64
|
remote: `http://${ipv4}:3000/remoteEntry.js`
|
|
65
65
|
},
|
|
66
66
|
remoteType: "script",
|
|
67
|
-
runtimePlugins: [
|
|
68
|
-
|
|
67
|
+
runtimePlugins: [
|
|
68
|
+
path.resolve(__dirname, "./mfRuntimePlugins/shared-strategy.js")
|
|
69
|
+
],
|
|
69
70
|
shared: {
|
|
70
71
|
react: {
|
|
71
72
|
eager: true,
|
|
@@ -1,28 +1,8 @@
|
|
|
1
1
|
const MODERN_JS_SERVER_DIR = "bundles";
|
|
2
2
|
const LOCALHOST = "localhost";
|
|
3
3
|
const PLUGIN_IDENTIFIER = "[ Modern.js Module Federation ]";
|
|
4
|
-
const isDev = process.env.NODE_ENV === "development";
|
|
5
|
-
const MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME = "routes";
|
|
6
|
-
const MODERN_JS_ROUTE_SERVER_LOADER = "route-server-loaders";
|
|
7
|
-
const META_NAME = "modern-js";
|
|
8
|
-
const FOLD_IDENTIFIER = "@mf";
|
|
9
|
-
const SEPARATOR = "_";
|
|
10
|
-
const MF_ROUTES = "mf-routes";
|
|
11
|
-
const DEFAULT_ENTRY = "main";
|
|
12
|
-
const DEFAULT_LAYOUT = "layout";
|
|
13
|
-
const MF_JSON = "mf.json";
|
|
14
4
|
export {
|
|
15
|
-
DEFAULT_ENTRY,
|
|
16
|
-
DEFAULT_LAYOUT,
|
|
17
|
-
FOLD_IDENTIFIER,
|
|
18
5
|
LOCALHOST,
|
|
19
|
-
META_NAME,
|
|
20
|
-
MF_JSON,
|
|
21
|
-
MF_ROUTES,
|
|
22
|
-
MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME,
|
|
23
|
-
MODERN_JS_ROUTE_SERVER_LOADER,
|
|
24
6
|
MODERN_JS_SERVER_DIR,
|
|
25
|
-
PLUGIN_IDENTIFIER
|
|
26
|
-
SEPARATOR,
|
|
27
|
-
isDev
|
|
7
|
+
PLUGIN_IDENTIFIER
|
|
28
8
|
};
|
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import hoistNonReactStatics from "hoist-non-react-statics";
|
|
3
3
|
import { SSRLiveReload } from "./SSRLiveReload";
|
|
4
|
-
console.log("mfSSRPlugin trigger");
|
|
5
4
|
const mfSSRPlugin = () => ({
|
|
6
5
|
name: "@module-federation/modern-js",
|
|
7
|
-
pre: [
|
|
8
|
-
"@modern-js/plugin-router"
|
|
9
|
-
],
|
|
10
6
|
setup: () => {
|
|
11
7
|
return {
|
|
12
|
-
async
|
|
8
|
+
async init({ context }, next) {
|
|
13
9
|
if (typeof window !== "undefined") {
|
|
14
|
-
return
|
|
10
|
+
return next({
|
|
11
|
+
context
|
|
12
|
+
});
|
|
15
13
|
}
|
|
16
14
|
globalThis.shouldUpdate = false;
|
|
17
15
|
const nodeUtils = await import("@module-federation/node/utils");
|
|
@@ -21,7 +19,9 @@ const mfSSRPlugin = () => ({
|
|
|
21
19
|
await nodeUtils.flushChunks();
|
|
22
20
|
globalThis.shouldUpdate = true;
|
|
23
21
|
}
|
|
24
|
-
return
|
|
22
|
+
return next({
|
|
23
|
+
context
|
|
24
|
+
});
|
|
25
25
|
},
|
|
26
26
|
wrapRoot(App) {
|
|
27
27
|
const AppWrapper = (props) => /* @__PURE__ */ _jsxs(_Fragment, {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isDev: boolean;
|
|
@@ -2,10 +2,8 @@ import type { webpack, UserConfig, AppTools, Rspack, Bundler } from '@modern-js/
|
|
|
2
2
|
import { moduleFederationPlugin } from '@module-federation/sdk';
|
|
3
3
|
import { PluginOptions } from '../types';
|
|
4
4
|
import { BundlerConfig } from '../interfaces/bundler';
|
|
5
|
-
import type { init } from '@module-federation/enhanced/runtime';
|
|
6
5
|
export type ConfigType<T> = T extends 'webpack' ? webpack.Configuration : T extends 'rspack' ? Rspack.Configuration : never;
|
|
7
6
|
export declare const getMFConfig: (userConfig: PluginOptions) => Promise<moduleFederationPlugin.ModuleFederationPluginOptions>;
|
|
8
|
-
export declare const replaceRemoteUrl: (mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions | Parameters<typeof init>[0], remoteIpStrategy?: "ipv4" | "inherit") => void;
|
|
9
7
|
export declare const patchMFConfig: (mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions, isServer: boolean, remoteIpStrategy?: "ipv4" | "inherit") => moduleFederationPlugin.ModuleFederationPluginOptions;
|
|
10
8
|
export declare function patchIgnoreWarning<T extends Bundler>(bundlerConfig: BundlerConfig<T>): void;
|
|
11
9
|
export declare function patchBundlerConfig<T extends Bundler>(options: {
|
package/dist/types/constant.d.ts
CHANGED
|
@@ -1,13 +1,3 @@
|
|
|
1
1
|
export declare const MODERN_JS_SERVER_DIR = "bundles";
|
|
2
2
|
export declare const LOCALHOST = "localhost";
|
|
3
3
|
export declare const PLUGIN_IDENTIFIER = "[ Modern.js Module Federation ]";
|
|
4
|
-
export declare const isDev: boolean;
|
|
5
|
-
export declare const MODERN_JS_FILE_SYSTEM_ROUTES_FILE_NAME = "routes";
|
|
6
|
-
export declare const MODERN_JS_ROUTE_SERVER_LOADER = "route-server-loaders";
|
|
7
|
-
export declare const META_NAME = "modern-js";
|
|
8
|
-
export declare const FOLD_IDENTIFIER = "@mf";
|
|
9
|
-
export declare const SEPARATOR = "_";
|
|
10
|
-
export declare const MF_ROUTES = "mf-routes";
|
|
11
|
-
export declare const DEFAULT_ENTRY = "main";
|
|
12
|
-
export declare const DEFAULT_LAYOUT = "layout";
|
|
13
|
-
export declare const MF_JSON = "mf.json";
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { moduleFederationPlugin } from '@module-federation/sdk';
|
|
2
2
|
import type { ModuleFederationPlugin as WebpackModuleFederationPlugin } from '@module-federation/enhanced';
|
|
3
3
|
import type { ModuleFederationPlugin as RspackModuleFederationPlugin } from '@module-federation/enhanced/rspack';
|
|
4
|
-
import type { init } from '@module-federation/enhanced/runtime';
|
|
5
4
|
export interface PluginOptions {
|
|
6
5
|
config?: moduleFederationPlugin.ModuleFederationPluginOptions;
|
|
7
6
|
configPath?: string;
|
|
8
7
|
remoteIpStrategy?: 'ipv4' | 'inherit';
|
|
9
|
-
dataLoader?: boolean | DataLoaderOptions;
|
|
10
8
|
}
|
|
11
9
|
export interface InternalModernPluginOptions {
|
|
12
10
|
csrConfig?: moduleFederationPlugin.ModuleFederationPluginOptions;
|
|
@@ -18,10 +16,3 @@ export interface InternalModernPluginOptions {
|
|
|
18
16
|
remoteIpStrategy?: 'ipv4' | 'inherit';
|
|
19
17
|
}
|
|
20
18
|
export type BundlerPlugin = WebpackModuleFederationPlugin | RspackModuleFederationPlugin;
|
|
21
|
-
export type TransformRuntimeOptions = (mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions) => Parameters<typeof init>[0];
|
|
22
|
-
export type DataLoaderOptions = {
|
|
23
|
-
partialSSRRemotes?: string[];
|
|
24
|
-
metaName?: string;
|
|
25
|
-
serverPlugin?: string;
|
|
26
|
-
transformRuntimeOptions?: TransformRuntimeOptions;
|
|
27
|
-
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/modern-js",
|
|
3
|
-
"version": "0.0.0-next-
|
|
3
|
+
"version": "0.0.0-next-20240911025819",
|
|
4
4
|
"files": [
|
|
5
5
|
"dist/",
|
|
6
6
|
"types.d.ts",
|
|
@@ -23,23 +23,6 @@
|
|
|
23
23
|
"types": "./dist/types/ssr-runtime/index.d.ts",
|
|
24
24
|
"default": "./dist/esm/ssr-runtime/index.js"
|
|
25
25
|
},
|
|
26
|
-
"./data-loader": {
|
|
27
|
-
"types": "./dist/types/runtime/dataLoader/plugin.d.ts",
|
|
28
|
-
"default": "./dist/esm/runtime/dataLoader/plugin.js"
|
|
29
|
-
},
|
|
30
|
-
"./data-loader-inject-assets": {
|
|
31
|
-
"types": "./dist/types/runtime/dataLoader/plugin-inject-assets.d.ts",
|
|
32
|
-
"default": "./dist/esm/runtime/dataLoader/plugin-inject-assets.js"
|
|
33
|
-
},
|
|
34
|
-
"./data-loader-server": {
|
|
35
|
-
"types": "./dist/types/cli/server/dataLoaderPlugin.d.ts",
|
|
36
|
-
"default": "./dist/cjs/cli/server/dataLoaderPlugin.js"
|
|
37
|
-
},
|
|
38
|
-
"./data-loader-plugin": {
|
|
39
|
-
"import": "./dist/esm/cli/dataLoader/plugin.js",
|
|
40
|
-
"require": "./dist/cjs/cli/dataLoader/plugin.js",
|
|
41
|
-
"types": "./dist/types/cli/dataLoader/plugin.d.ts"
|
|
42
|
-
},
|
|
43
26
|
"./config-plugin": {
|
|
44
27
|
"import": "./dist/esm/cli/configPlugin.js",
|
|
45
28
|
"require": "./dist/cjs/cli/configPlugin.js",
|
|
@@ -64,18 +47,6 @@
|
|
|
64
47
|
],
|
|
65
48
|
"ssr-plugin": [
|
|
66
49
|
"./dist/types/cli/ssrPlugin.d.ts"
|
|
67
|
-
],
|
|
68
|
-
"data-loader-plugin": [
|
|
69
|
-
"./dist/types/cli/dataLoader/plugin.d.ts"
|
|
70
|
-
],
|
|
71
|
-
"data-loader": [
|
|
72
|
-
"./dist/types/runtime/dataLoader/plugin.d.ts"
|
|
73
|
-
],
|
|
74
|
-
"data-loader-inject-assets": [
|
|
75
|
-
"./dist/types/runtime/dataLoader/plugin-inject-assets.d.ts"
|
|
76
|
-
],
|
|
77
|
-
"data-loader-server": [
|
|
78
|
-
"./dist/types/cli/server/dataLoaderPlugin.d.ts"
|
|
79
50
|
]
|
|
80
51
|
}
|
|
81
52
|
},
|
|
@@ -85,33 +56,25 @@
|
|
|
85
56
|
"license": "MIT",
|
|
86
57
|
"dependencies": {
|
|
87
58
|
"@swc/helpers": "0.5.12",
|
|
88
|
-
"@modern-js/utils": "2.
|
|
59
|
+
"@modern-js/utils": "2.54.2",
|
|
89
60
|
"@modern-js/node-bundle-require": "2.54.2",
|
|
90
61
|
"node-fetch": "~3.3.0",
|
|
91
62
|
"react-error-boundary": "4.0.13",
|
|
92
63
|
"hoist-non-react-statics": "3.3.2",
|
|
93
|
-
"@
|
|
94
|
-
"@
|
|
95
|
-
"@
|
|
96
|
-
"@babel/types": "7.25.2",
|
|
97
|
-
"@module-federation/sdk": "0.0.0-next-20240910102933",
|
|
98
|
-
"@module-federation/enhanced": "0.0.0-next-20240910102933",
|
|
99
|
-
"@module-federation/node": "0.0.0-next-20240910102933"
|
|
64
|
+
"@module-federation/sdk": "0.0.0-next-20240911025819",
|
|
65
|
+
"@module-federation/enhanced": "0.0.0-next-20240911025819",
|
|
66
|
+
"@module-federation/node": "0.0.0-next-20240911025819"
|
|
100
67
|
},
|
|
101
68
|
"devDependencies": {
|
|
102
|
-
"@types/babel__traverse": "7.20.6",
|
|
103
|
-
"@types/babel__generator": "7.6.8",
|
|
104
69
|
"@types/hoist-non-react-statics": "3.3.2",
|
|
105
|
-
"@modern-js/
|
|
106
|
-
"@modern-js/
|
|
107
|
-
"@modern-js/
|
|
108
|
-
"@modern-js/
|
|
109
|
-
"@modern-js/
|
|
110
|
-
"@
|
|
111
|
-
"@module-federation/manifest": "0.0.0-next-20240910102933"
|
|
70
|
+
"@modern-js/app-tools": "2.57.0",
|
|
71
|
+
"@modern-js/core": "2.57.0",
|
|
72
|
+
"@modern-js/runtime": "2.57.0",
|
|
73
|
+
"@modern-js/module-tools": "2.57.0",
|
|
74
|
+
"@modern-js/tsconfig": "2.57.0",
|
|
75
|
+
"@module-federation/manifest": "0.0.0-next-20240911025819"
|
|
112
76
|
},
|
|
113
77
|
"peerDependencies": {
|
|
114
|
-
"@modern-js/runtime": "^2.59.0",
|
|
115
78
|
"react": ">=17",
|
|
116
79
|
"react-dom": ">=17",
|
|
117
80
|
"typescript": "^4.9.0 || ^5.0.0",
|
|
@@ -1,49 +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
|
-
COMPONENT: () => COMPONENT,
|
|
22
|
-
ELEMENT: () => ELEMENT,
|
|
23
|
-
ID: () => ID,
|
|
24
|
-
IS_ROOT: () => IS_ROOT,
|
|
25
|
-
LAZY_COMPONENT: () => LAZY_COMPONENT,
|
|
26
|
-
LOADER: () => LOADER,
|
|
27
|
-
PRIVATE_COMPONENT: () => PRIVATE_COMPONENT,
|
|
28
|
-
SHOULD_REVALIDATE: () => SHOULD_REVALIDATE
|
|
29
|
-
});
|
|
30
|
-
module.exports = __toCommonJS(constant_exports);
|
|
31
|
-
const IS_ROOT = "isRoot";
|
|
32
|
-
const ID = "id";
|
|
33
|
-
const COMPONENT = "component";
|
|
34
|
-
const LAZY_COMPONENT = "lazyImport";
|
|
35
|
-
const SHOULD_REVALIDATE = "shouldRevalidate";
|
|
36
|
-
const PRIVATE_COMPONENT = "_component";
|
|
37
|
-
const ELEMENT = "element";
|
|
38
|
-
const LOADER = "loader";
|
|
39
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
40
|
-
0 && (module.exports = {
|
|
41
|
-
COMPONENT,
|
|
42
|
-
ELEMENT,
|
|
43
|
-
ID,
|
|
44
|
-
IS_ROOT,
|
|
45
|
-
LAZY_COMPONENT,
|
|
46
|
-
LOADER,
|
|
47
|
-
PRIVATE_COMPONENT,
|
|
48
|
-
SHOULD_REVALIDATE
|
|
49
|
-
});
|