@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.
- package/package.json +7 -7
- package/dist/LICENSE +0 -21
- package/dist/cjs/cli/configPlugin.js +0 -377
- package/dist/cjs/cli/configPlugin.spec.js +0 -112
- package/dist/cjs/cli/constant.js +0 -28
- package/dist/cjs/cli/index.js +0 -85
- package/dist/cjs/cli/logger.js +0 -27
- package/dist/cjs/cli/manifest.js +0 -75
- package/dist/cjs/cli/mfRuntimePlugins/inject-node-fetch.js +0 -44
- package/dist/cjs/cli/mfRuntimePlugins/resolve-entry-ipv4.js +0 -82
- package/dist/cjs/cli/mfRuntimePlugins/shared-strategy.js +0 -43
- package/dist/cjs/cli/ssrPlugin.js +0 -217
- package/dist/cjs/cli/utils.js +0 -85
- package/dist/cjs/constant.js +0 -31
- package/dist/cjs/interfaces/bundler.js +0 -16
- package/dist/cjs/runtime/createRemoteSSRComponent.js +0 -201
- package/dist/cjs/runtime/index.js +0 -38
- package/dist/cjs/ssr-runtime/SSRLiveReload.js +0 -43
- package/dist/cjs/ssr-runtime/index.js +0 -22
- package/dist/cjs/ssr-runtime/plugin.js +0 -68
- package/dist/cjs/types/index.js +0 -16
- package/dist/esm/cli/configPlugin.js +0 -384
- package/dist/esm/cli/configPlugin.spec.js +0 -108
- package/dist/esm/cli/constant.js +0 -4
- package/dist/esm/cli/index.js +0 -79
- package/dist/esm/cli/logger.js +0 -7
- package/dist/esm/cli/manifest.js +0 -41
- package/dist/esm/cli/mfRuntimePlugins/inject-node-fetch.js +0 -16
- package/dist/esm/cli/mfRuntimePlugins/resolve-entry-ipv4.js +0 -74
- package/dist/esm/cli/mfRuntimePlugins/shared-strategy.js +0 -25
- package/dist/esm/cli/ssrPlugin.js +0 -199
- package/dist/esm/cli/utils.js +0 -49
- package/dist/esm/constant.js +0 -6
- package/dist/esm/interfaces/bundler.js +0 -0
- package/dist/esm/runtime/createRemoteSSRComponent.js +0 -191
- package/dist/esm/runtime/index.js +0 -12
- package/dist/esm/ssr-runtime/SSRLiveReload.js +0 -26
- package/dist/esm/ssr-runtime/index.js +0 -1
- package/dist/esm/ssr-runtime/plugin.js +0 -70
- package/dist/esm/types/index.js +0 -0
- package/dist/esm-node/cli/configPlugin.js +0 -336
- package/dist/esm-node/cli/configPlugin.spec.js +0 -89
- package/dist/esm-node/cli/constant.js +0 -4
- package/dist/esm-node/cli/index.js +0 -60
- package/dist/esm-node/cli/logger.js +0 -7
- package/dist/esm-node/cli/manifest.js +0 -41
- package/dist/esm-node/cli/mfRuntimePlugins/inject-node-fetch.js +0 -14
- package/dist/esm-node/cli/mfRuntimePlugins/resolve-entry-ipv4.js +0 -62
- package/dist/esm-node/cli/mfRuntimePlugins/shared-strategy.js +0 -23
- package/dist/esm-node/cli/ssrPlugin.js +0 -181
- package/dist/esm-node/cli/utils.js +0 -49
- package/dist/esm-node/constant.js +0 -6
- package/dist/esm-node/interfaces/bundler.js +0 -0
- package/dist/esm-node/runtime/createRemoteSSRComponent.js +0 -166
- package/dist/esm-node/runtime/index.js +0 -12
- package/dist/esm-node/ssr-runtime/SSRLiveReload.js +0 -19
- package/dist/esm-node/ssr-runtime/index.js +0 -1
- package/dist/esm-node/ssr-runtime/plugin.js +0 -34
- package/dist/esm-node/types/index.js +0 -0
- package/dist/types/cli/configPlugin.d.ts +0 -21
- package/dist/types/cli/configPlugin.spec.d.ts +0 -1
- package/dist/types/cli/constant.d.ts +0 -1
- package/dist/types/cli/index.d.ts +0 -5
- package/dist/types/cli/logger.d.ts +0 -2
- package/dist/types/cli/manifest.d.ts +0 -2
- package/dist/types/cli/mfRuntimePlugins/inject-node-fetch.d.ts +0 -3
- package/dist/types/cli/mfRuntimePlugins/resolve-entry-ipv4.d.ts +0 -3
- package/dist/types/cli/mfRuntimePlugins/shared-strategy.d.ts +0 -3
- package/dist/types/cli/ssrPlugin.d.ts +0 -6
- package/dist/types/cli/utils.d.ts +0 -5
- package/dist/types/constant.d.ts +0 -2
- package/dist/types/interfaces/bundler.d.ts +0 -18
- package/dist/types/runtime/createRemoteSSRComponent.d.ts +0 -18
- package/dist/types/runtime/index.d.ts +0 -5
- package/dist/types/ssr-runtime/SSRLiveReload.d.ts +0 -1
- package/dist/types/ssr-runtime/index.d.ts +0 -1
- package/dist/types/ssr-runtime/plugin.d.ts +0 -2
- package/dist/types/types/index.d.ts +0 -22
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
import path from "path";
|
|
2
|
-
import { fs } from "@modern-js/utils";
|
|
3
|
-
import { ModuleFederationPlugin } from "@module-federation/enhanced/webpack";
|
|
4
|
-
import { ModuleFederationPlugin as RspackModuleFederationPlugin } from "@module-federation/enhanced/rspack";
|
|
5
|
-
import UniverseEntryChunkTrackerPlugin from "@module-federation/node/universe-entry-chunk-tracker-plugin";
|
|
6
|
-
import { updateStatsAndManifest } from "./manifest";
|
|
7
|
-
import { isDev } from "./constant";
|
|
8
|
-
import logger from "./logger";
|
|
9
|
-
import { isWebTarget, skipByTarget } from "./utils";
|
|
10
|
-
function setEnv() {
|
|
11
|
-
process.env["MF_DISABLE_EMIT_STATS"] = "true";
|
|
12
|
-
process.env["MF_SSR_PRJ"] = "true";
|
|
13
|
-
}
|
|
14
|
-
const CHAIN_MF_PLUGIN_ID = "plugin-module-federation-server";
|
|
15
|
-
const mfSSRRsbuildPlugin = (pluginOptions) => {
|
|
16
|
-
return {
|
|
17
|
-
name: "@modern-js/plugin-mf-post-config",
|
|
18
|
-
pre: [
|
|
19
|
-
"@modern-js/builder-plugin-ssr"
|
|
20
|
-
],
|
|
21
|
-
setup(api) {
|
|
22
|
-
if (pluginOptions.csrConfig.getPublicPath) {
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
let csrOutputPath = "";
|
|
26
|
-
let ssrOutputPath = "";
|
|
27
|
-
let ssrEnv = "";
|
|
28
|
-
api.modifyEnvironmentConfig((config, { name }) => {
|
|
29
|
-
const target = config.output.target;
|
|
30
|
-
if (skipByTarget(target)) {
|
|
31
|
-
return config;
|
|
32
|
-
}
|
|
33
|
-
if (isWebTarget(target)) {
|
|
34
|
-
csrOutputPath = config.output.distPath.root;
|
|
35
|
-
} else {
|
|
36
|
-
ssrOutputPath = config.output.distPath.root;
|
|
37
|
-
ssrEnv = name;
|
|
38
|
-
}
|
|
39
|
-
return config;
|
|
40
|
-
});
|
|
41
|
-
const modifySSRPublicPath = (config, utils) => {
|
|
42
|
-
if (ssrEnv !== utils.environment.name) {
|
|
43
|
-
return config;
|
|
44
|
-
}
|
|
45
|
-
const userSSRConfig = pluginOptions.userConfig.ssr ? typeof pluginOptions.userConfig.ssr === "object" ? pluginOptions.userConfig.ssr : {} : {};
|
|
46
|
-
if (userSSRConfig.distOutputDir) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
config.output.publicPath = `${config.output.publicPath}${path.relative(csrOutputPath, ssrOutputPath)}/`;
|
|
50
|
-
return config;
|
|
51
|
-
};
|
|
52
|
-
api.modifyWebpackConfig((config, utils) => {
|
|
53
|
-
modifySSRPublicPath(config, utils);
|
|
54
|
-
return config;
|
|
55
|
-
});
|
|
56
|
-
api.modifyRspackConfig((config, utils) => {
|
|
57
|
-
modifySSRPublicPath(config, utils);
|
|
58
|
-
return config;
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
};
|
|
63
|
-
const moduleFederationSSRPlugin = (pluginOptions) => ({
|
|
64
|
-
name: "@modern-js/plugin-module-federation-ssr",
|
|
65
|
-
pre: [
|
|
66
|
-
"@modern-js/plugin-module-federation-config",
|
|
67
|
-
"@modern-js/plugin-module-federation"
|
|
68
|
-
],
|
|
69
|
-
setup: async (api) => {
|
|
70
|
-
var _pluginOptions_userConfig, _modernjsConfig_server;
|
|
71
|
-
const modernjsConfig = api.getConfig();
|
|
72
|
-
var _pluginOptions_userConfig_ssr;
|
|
73
|
-
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);
|
|
74
|
-
if (!enableSSR) {
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
setEnv();
|
|
78
|
-
api._internalRuntimePlugins(({ entrypoint, plugins }) => {
|
|
79
|
-
if (!isDev) {
|
|
80
|
-
return {
|
|
81
|
-
entrypoint,
|
|
82
|
-
plugins
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
plugins.push({
|
|
86
|
-
name: "mfSSR",
|
|
87
|
-
path: "@module-federation/modern-js/ssr-runtime",
|
|
88
|
-
config: {}
|
|
89
|
-
});
|
|
90
|
-
return {
|
|
91
|
-
entrypoint,
|
|
92
|
-
plugins
|
|
93
|
-
};
|
|
94
|
-
});
|
|
95
|
-
api.modifyBundlerChain((chain) => {
|
|
96
|
-
const target = chain.get("target");
|
|
97
|
-
if (skipByTarget(target)) {
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
const bundlerType = api.getAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
|
|
101
|
-
const MFPlugin = bundlerType === "webpack" ? ModuleFederationPlugin : RspackModuleFederationPlugin;
|
|
102
|
-
const isWeb = isWebTarget(target);
|
|
103
|
-
if (!isWeb) {
|
|
104
|
-
if (!chain.plugins.has(CHAIN_MF_PLUGIN_ID)) {
|
|
105
|
-
chain.plugin(CHAIN_MF_PLUGIN_ID).use(MFPlugin, [
|
|
106
|
-
pluginOptions.ssrConfig
|
|
107
|
-
]).init((Plugin, args) => {
|
|
108
|
-
pluginOptions.nodePlugin = new Plugin(args[0]);
|
|
109
|
-
return pluginOptions.nodePlugin;
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
if (!isWeb) {
|
|
114
|
-
chain.target("async-node");
|
|
115
|
-
if (isDev) {
|
|
116
|
-
chain.plugin("UniverseEntryChunkTrackerPlugin").use(UniverseEntryChunkTrackerPlugin);
|
|
117
|
-
}
|
|
118
|
-
const userSSRConfig = pluginOptions.userConfig.ssr ? typeof pluginOptions.userConfig.ssr === "object" ? pluginOptions.userConfig.ssr : {} : {};
|
|
119
|
-
const publicPath = chain.output.get("publicPath");
|
|
120
|
-
if (userSSRConfig.distOutputDir && publicPath) {
|
|
121
|
-
chain.output.publicPath(`${publicPath}${userSSRConfig.distOutputDir}/`);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
if (isDev && isWeb) {
|
|
125
|
-
chain.externals({
|
|
126
|
-
"@module-federation/node/utils": "NOT_USED_IN_BROWSER"
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
api.config(() => {
|
|
131
|
-
return {
|
|
132
|
-
builderPlugins: [
|
|
133
|
-
mfSSRRsbuildPlugin(pluginOptions)
|
|
134
|
-
],
|
|
135
|
-
tools: {
|
|
136
|
-
devServer: {
|
|
137
|
-
before: [
|
|
138
|
-
(req, res, next) => {
|
|
139
|
-
if (!enableSSR) {
|
|
140
|
-
next();
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
try {
|
|
144
|
-
var _req_url, _req_url1;
|
|
145
|
-
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"))) {
|
|
146
|
-
const filepath = path.join(process.cwd(), `dist${req.url}`);
|
|
147
|
-
fs.statSync(filepath);
|
|
148
|
-
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
149
|
-
res.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, PATCH, OPTIONS");
|
|
150
|
-
res.setHeader("Access-Control-Allow-Headers", "*");
|
|
151
|
-
fs.createReadStream(filepath).pipe(res);
|
|
152
|
-
} else {
|
|
153
|
-
next();
|
|
154
|
-
}
|
|
155
|
-
} catch (err) {
|
|
156
|
-
logger.debug(err);
|
|
157
|
-
next();
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
]
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
};
|
|
164
|
-
});
|
|
165
|
-
api.onAfterBuild(() => {
|
|
166
|
-
const { nodePlugin, browserPlugin, distOutputDir } = pluginOptions;
|
|
167
|
-
updateStatsAndManifest(nodePlugin, browserPlugin, distOutputDir);
|
|
168
|
-
});
|
|
169
|
-
api.onDevCompileDone(() => {
|
|
170
|
-
const { nodePlugin, browserPlugin, distOutputDir } = pluginOptions;
|
|
171
|
-
updateStatsAndManifest(nodePlugin, browserPlugin, distOutputDir);
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
var ssrPlugin_default = moduleFederationSSRPlugin;
|
|
176
|
-
export {
|
|
177
|
-
CHAIN_MF_PLUGIN_ID,
|
|
178
|
-
ssrPlugin_default as default,
|
|
179
|
-
moduleFederationSSRPlugin,
|
|
180
|
-
setEnv
|
|
181
|
-
};
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import os from "os";
|
|
2
|
-
const localIpv4 = "127.0.0.1";
|
|
3
|
-
const getIpv4Interfaces = () => {
|
|
4
|
-
try {
|
|
5
|
-
const interfaces = os.networkInterfaces();
|
|
6
|
-
const ipv4Interfaces = [];
|
|
7
|
-
Object.values(interfaces).forEach((detail) => {
|
|
8
|
-
detail === null || detail === void 0 ? void 0 : detail.forEach((detail2) => {
|
|
9
|
-
const familyV4Value = typeof detail2.family === "string" ? "IPv4" : 4;
|
|
10
|
-
if (detail2.family === familyV4Value && detail2.address !== localIpv4) {
|
|
11
|
-
ipv4Interfaces.push(detail2);
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
});
|
|
15
|
-
return ipv4Interfaces;
|
|
16
|
-
} catch (_err) {
|
|
17
|
-
return [];
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
const getIPV4 = () => {
|
|
21
|
-
const ipv4Interfaces = getIpv4Interfaces();
|
|
22
|
-
const ipv4Interface = ipv4Interfaces[0] || {
|
|
23
|
-
address: localIpv4
|
|
24
|
-
};
|
|
25
|
-
return ipv4Interface.address;
|
|
26
|
-
};
|
|
27
|
-
const isWebTarget = (target) => {
|
|
28
|
-
const WEB_TARGET = "web";
|
|
29
|
-
if (Array.isArray(target)) {
|
|
30
|
-
return target.includes(WEB_TARGET);
|
|
31
|
-
} else if (typeof target === "string") {
|
|
32
|
-
return target === WEB_TARGET;
|
|
33
|
-
}
|
|
34
|
-
return false;
|
|
35
|
-
};
|
|
36
|
-
const skipByTarget = (target) => {
|
|
37
|
-
const IGNORE_TARGET = "webworker";
|
|
38
|
-
if (Array.isArray(target)) {
|
|
39
|
-
return target.includes(IGNORE_TARGET);
|
|
40
|
-
} else if (typeof target === "string") {
|
|
41
|
-
return target === IGNORE_TARGET;
|
|
42
|
-
}
|
|
43
|
-
return false;
|
|
44
|
-
};
|
|
45
|
-
export {
|
|
46
|
-
getIPV4,
|
|
47
|
-
isWebTarget,
|
|
48
|
-
skipByTarget
|
|
49
|
-
};
|
|
File without changes
|
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import React from "react";
|
|
3
|
-
import { getInstance } from "@module-federation/enhanced/runtime";
|
|
4
|
-
import { ErrorBoundary } from "react-error-boundary";
|
|
5
|
-
function getLoadedRemoteInfos(instance, id) {
|
|
6
|
-
const { name, expose } = instance.remoteHandler.idToRemoteMap[id] || {};
|
|
7
|
-
if (!name) {
|
|
8
|
-
return;
|
|
9
|
-
}
|
|
10
|
-
const module = instance.moduleCache.get(name);
|
|
11
|
-
if (!module) {
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
const { remoteSnapshot } = instance.snapshotHandler.getGlobalRemoteInfo(module.remoteInfo);
|
|
15
|
-
return {
|
|
16
|
-
...module.remoteInfo,
|
|
17
|
-
snapshot: remoteSnapshot,
|
|
18
|
-
expose
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
function getTargetModuleInfo(id) {
|
|
22
|
-
const instance = getInstance();
|
|
23
|
-
if (!instance) {
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
const loadedRemoteInfo = getLoadedRemoteInfos(instance, id);
|
|
27
|
-
if (!loadedRemoteInfo) {
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
const snapshot = loadedRemoteInfo.snapshot;
|
|
31
|
-
if (!snapshot) {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
const publicPath = "publicPath" in snapshot ? snapshot.publicPath : "getPublicPath" in snapshot ? new Function(snapshot.getPublicPath)() : "";
|
|
35
|
-
if (!publicPath) {
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
const modules = "modules" in snapshot ? snapshot.modules : [];
|
|
39
|
-
const targetModule = modules.find((m) => m.modulePath === loadedRemoteInfo.expose);
|
|
40
|
-
if (!targetModule) {
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
const remoteEntry = "remoteEntry" in snapshot ? snapshot.remoteEntry : "";
|
|
44
|
-
if (!remoteEntry) {
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
return {
|
|
48
|
-
module: targetModule,
|
|
49
|
-
publicPath,
|
|
50
|
-
remoteEntry
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
function collectSSRAssets(options) {
|
|
54
|
-
const { id, injectLink = true, injectScript = true } = typeof options === "string" ? {
|
|
55
|
-
id: options
|
|
56
|
-
} : options;
|
|
57
|
-
const links = [];
|
|
58
|
-
const scripts = [];
|
|
59
|
-
const instance = getInstance();
|
|
60
|
-
if (!instance || !injectLink && !injectScript) {
|
|
61
|
-
return [
|
|
62
|
-
...scripts,
|
|
63
|
-
...links
|
|
64
|
-
];
|
|
65
|
-
}
|
|
66
|
-
const moduleAndPublicPath = getTargetModuleInfo(id);
|
|
67
|
-
if (!moduleAndPublicPath) {
|
|
68
|
-
return [
|
|
69
|
-
...scripts,
|
|
70
|
-
...links
|
|
71
|
-
];
|
|
72
|
-
}
|
|
73
|
-
const { module: targetModule, publicPath, remoteEntry } = moduleAndPublicPath;
|
|
74
|
-
if (injectLink) {
|
|
75
|
-
[
|
|
76
|
-
...targetModule.assets.css.sync,
|
|
77
|
-
...targetModule.assets.css.async
|
|
78
|
-
].forEach((file, index) => {
|
|
79
|
-
links.push(/* @__PURE__ */ _jsx("link", {
|
|
80
|
-
href: `${publicPath}${file}`,
|
|
81
|
-
rel: "stylesheet",
|
|
82
|
-
type: "text/css"
|
|
83
|
-
}, `${file.split(".")[0]}_${index}`));
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
if (injectScript) {
|
|
87
|
-
scripts.push(/* @__PURE__ */ _jsx("script", {
|
|
88
|
-
async: true,
|
|
89
|
-
src: `${publicPath}${remoteEntry}`,
|
|
90
|
-
crossOrigin: "anonymous"
|
|
91
|
-
}, remoteEntry.split(".")[0]));
|
|
92
|
-
[
|
|
93
|
-
...targetModule.assets.js.sync
|
|
94
|
-
].forEach((file, index) => {
|
|
95
|
-
scripts.push(/* @__PURE__ */ _jsx("script", {
|
|
96
|
-
async: true,
|
|
97
|
-
src: `${publicPath}${file}`,
|
|
98
|
-
crossOrigin: "anonymous"
|
|
99
|
-
}, `${file.split(".")[0]}_${index}`));
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
return [
|
|
103
|
-
...scripts,
|
|
104
|
-
...links
|
|
105
|
-
];
|
|
106
|
-
}
|
|
107
|
-
function createRemoteSSRComponent(info) {
|
|
108
|
-
const exportName = (info === null || info === void 0 ? void 0 : info.export) || "default";
|
|
109
|
-
const LazyComponent = /* @__PURE__ */ React.lazy(async () => {
|
|
110
|
-
try {
|
|
111
|
-
const m = await info.loader();
|
|
112
|
-
if (!m) {
|
|
113
|
-
throw new Error("load remote failed");
|
|
114
|
-
}
|
|
115
|
-
const moduleId = m && m[Symbol.for("mf_module_id")];
|
|
116
|
-
const assets = collectSSRAssets({
|
|
117
|
-
id: moduleId
|
|
118
|
-
});
|
|
119
|
-
const Com = m[exportName];
|
|
120
|
-
if (exportName in m && typeof Com === "function") {
|
|
121
|
-
return {
|
|
122
|
-
default: (props) => /* @__PURE__ */ _jsxs(_Fragment, {
|
|
123
|
-
children: [
|
|
124
|
-
assets,
|
|
125
|
-
/* @__PURE__ */ _jsx(Com, {
|
|
126
|
-
...props
|
|
127
|
-
})
|
|
128
|
-
]
|
|
129
|
-
})
|
|
130
|
-
};
|
|
131
|
-
} else {
|
|
132
|
-
throw Error(`Make sure that ${moduleId} has the correct export when export is ${String(exportName)}`);
|
|
133
|
-
}
|
|
134
|
-
} catch (err) {
|
|
135
|
-
if (!info.fallback) {
|
|
136
|
-
throw err;
|
|
137
|
-
}
|
|
138
|
-
const FallbackFunctionComponent = info.fallback;
|
|
139
|
-
const FallbackNode = /* @__PURE__ */ _jsx(FallbackFunctionComponent, {
|
|
140
|
-
error: err,
|
|
141
|
-
resetErrorBoundary: () => {
|
|
142
|
-
console.log('SSR mode not support "resetErrorBoundary" !');
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
return {
|
|
146
|
-
default: () => FallbackNode
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
});
|
|
150
|
-
return (props) => {
|
|
151
|
-
const { key, ...args } = props;
|
|
152
|
-
return /* @__PURE__ */ _jsx(ErrorBoundary, {
|
|
153
|
-
FallbackComponent: info.fallback,
|
|
154
|
-
children: /* @__PURE__ */ _jsx(React.Suspense, {
|
|
155
|
-
fallback: info.loading,
|
|
156
|
-
children: /* @__PURE__ */ _jsx(LazyComponent, {
|
|
157
|
-
...args
|
|
158
|
-
})
|
|
159
|
-
})
|
|
160
|
-
});
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
export {
|
|
164
|
-
collectSSRAssets,
|
|
165
|
-
createRemoteSSRComponent
|
|
166
|
-
};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export * from "@module-federation/enhanced/runtime";
|
|
2
|
-
const kit = {
|
|
3
|
-
get createRemoteSSRComponent() {
|
|
4
|
-
return require("./createRemoteSSRComponent").createRemoteSSRComponent;
|
|
5
|
-
},
|
|
6
|
-
get collectSSRAssets() {
|
|
7
|
-
return require("./createRemoteSSRComponent").collectSSRAssets;
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
export {
|
|
11
|
-
kit
|
|
12
|
-
};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
function SSRLiveReload() {
|
|
3
|
-
if (process.env.NODE_ENV !== "development") {
|
|
4
|
-
return null;
|
|
5
|
-
}
|
|
6
|
-
return /* @__PURE__ */ _jsx("script", {
|
|
7
|
-
suppressHydrationWarning: true,
|
|
8
|
-
dangerouslySetInnerHTML: {
|
|
9
|
-
__html: String.raw`
|
|
10
|
-
if(${globalThis.shouldUpdate}){
|
|
11
|
-
location.reload();
|
|
12
|
-
}
|
|
13
|
-
`
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
export {
|
|
18
|
-
SSRLiveReload
|
|
19
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./plugin";
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { SSRLiveReload } from "./SSRLiveReload";
|
|
3
|
-
const mfSSRPlugin = () => ({
|
|
4
|
-
name: "@module-federation/modern-js",
|
|
5
|
-
setup: (api) => {
|
|
6
|
-
api.onBeforeRender(async () => {
|
|
7
|
-
if (typeof window !== "undefined") {
|
|
8
|
-
return;
|
|
9
|
-
}
|
|
10
|
-
globalThis.shouldUpdate = false;
|
|
11
|
-
const nodeUtils = await import("@module-federation/node/utils");
|
|
12
|
-
const shouldUpdate = await nodeUtils.revalidate();
|
|
13
|
-
if (shouldUpdate) {
|
|
14
|
-
console.log("should RELOAD", shouldUpdate);
|
|
15
|
-
await nodeUtils.flushChunks();
|
|
16
|
-
globalThis.shouldUpdate = true;
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
api.wrapRoot((App) => {
|
|
20
|
-
const AppWrapper = (props) => /* @__PURE__ */ _jsxs(_Fragment, {
|
|
21
|
-
children: [
|
|
22
|
-
/* @__PURE__ */ _jsx(SSRLiveReload, {}),
|
|
23
|
-
/* @__PURE__ */ _jsx(App, {
|
|
24
|
-
...props
|
|
25
|
-
})
|
|
26
|
-
]
|
|
27
|
-
});
|
|
28
|
-
return AppWrapper;
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
export {
|
|
33
|
-
mfSSRPlugin
|
|
34
|
-
};
|
|
File without changes
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { isWebTarget, skipByTarget } from './utils';
|
|
2
|
-
import { moduleFederationPlugin } from '@module-federation/sdk';
|
|
3
|
-
import { PluginOptions } from '../types';
|
|
4
|
-
import type { InternalModernPluginOptions } from '../types';
|
|
5
|
-
import type { AppTools, webpack, UserConfig, Rspack, CliPluginFuture } from '@modern-js/app-tools';
|
|
6
|
-
import type { BundlerChainConfig } from '../interfaces/bundler';
|
|
7
|
-
export type ConfigType<T> = T extends 'webpack' ? webpack.Configuration : T extends 'rspack' ? Rspack.Configuration : never;
|
|
8
|
-
export declare function setEnv(enableSSR: boolean): void;
|
|
9
|
-
export declare const getMFConfig: (userConfig: PluginOptions) => Promise<moduleFederationPlugin.ModuleFederationPluginOptions>;
|
|
10
|
-
export declare const patchMFConfig: (mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions, isServer: boolean, remoteIpStrategy?: "ipv4" | "inherit") => moduleFederationPlugin.ModuleFederationPluginOptions;
|
|
11
|
-
export declare function addMyTypes2Ignored(chain: BundlerChainConfig, mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions): void;
|
|
12
|
-
export declare function patchBundlerConfig(options: {
|
|
13
|
-
chain: BundlerChainConfig;
|
|
14
|
-
isServer: boolean;
|
|
15
|
-
modernjsConfig: UserConfig<AppTools>;
|
|
16
|
-
mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions;
|
|
17
|
-
enableSSR: boolean;
|
|
18
|
-
}): void;
|
|
19
|
-
export declare const moduleFederationConfigPlugin: (userConfig: InternalModernPluginOptions) => CliPluginFuture<AppTools>;
|
|
20
|
-
export default moduleFederationConfigPlugin;
|
|
21
|
-
export { isWebTarget, skipByTarget };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const isDev: boolean;
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { CliPluginFuture, AppTools } from '@modern-js/app-tools';
|
|
2
|
-
import type { PluginOptions } from '../types';
|
|
3
|
-
export declare const moduleFederationPlugin: (userConfig?: PluginOptions) => CliPluginFuture<AppTools>;
|
|
4
|
-
export default moduleFederationPlugin;
|
|
5
|
-
export { createModuleFederationConfig } from '@module-federation/enhanced';
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { CliPluginFuture, AppTools } from '@modern-js/app-tools';
|
|
2
|
-
import type { InternalModernPluginOptions } from '../types';
|
|
3
|
-
export declare function setEnv(): void;
|
|
4
|
-
export declare const CHAIN_MF_PLUGIN_ID = "plugin-module-federation-server";
|
|
5
|
-
export declare const moduleFederationSSRPlugin: (pluginOptions: Required<InternalModernPluginOptions>) => CliPluginFuture<AppTools>;
|
|
6
|
-
export default moduleFederationSSRPlugin;
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { webpack, Rspack } from '@modern-js/app-tools';
|
|
2
|
-
export type ConfigType<T> = T extends 'webpack' ? webpack.Configuration : T extends 'rspack' ? Rspack.Configuration : never;
|
|
3
|
-
export declare const getIPV4: () => string;
|
|
4
|
-
export declare const isWebTarget: (target: string[] | string) => boolean;
|
|
5
|
-
export declare const skipByTarget: (target: string[] | string) => boolean;
|
package/dist/types/constant.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { AppTools, Bundler, UserConfig } from '@modern-js/app-tools';
|
|
2
|
-
type AppToolsUserConfig<T extends Bundler> = AppTools<T>['userConfig']['tools'];
|
|
3
|
-
type ExcludeUndefined<T> = T extends undefined ? never : T;
|
|
4
|
-
type ExtractObjectType<T> = T extends (...args: any[]) => any ? never : T;
|
|
5
|
-
type OmitArrayConfiguration<T> = T extends Array<any> ? (T extends (infer U)[] ? U : T) : ExtractObjectType<T>;
|
|
6
|
-
type WebpackConfigs = ExcludeUndefined<AppToolsUserConfig<'webpack'>> extends {
|
|
7
|
-
webpack?: infer U;
|
|
8
|
-
} ? U : never;
|
|
9
|
-
type ObjectWebpack = ExtractObjectType<OmitArrayConfiguration<WebpackConfigs>>;
|
|
10
|
-
type RspackConfigs = ExcludeUndefined<AppToolsUserConfig<'rspack'>> extends {
|
|
11
|
-
rspack?: infer U;
|
|
12
|
-
} ? U : never;
|
|
13
|
-
type ObjectRspack = ExtractObjectType<OmitArrayConfiguration<RspackConfigs>>;
|
|
14
|
-
type BundlerChain = ExcludeUndefined<ExcludeUndefined<UserConfig<AppTools>['tools']>['bundlerChain']>;
|
|
15
|
-
type BundlerChainFunc = Extract<BundlerChain, (chain: any, utils: any) => any>;
|
|
16
|
-
export type BundlerChainConfig = Parameters<BundlerChainFunc>[0];
|
|
17
|
-
export type BundlerConfig<T extends Bundler> = T extends 'rspack' ? ObjectRspack : ObjectWebpack;
|
|
18
|
-
export {};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { ErrorBoundaryPropsWithComponent } from 'react-error-boundary';
|
|
3
|
-
type IProps = {
|
|
4
|
-
id: string;
|
|
5
|
-
injectScript?: boolean;
|
|
6
|
-
injectLink?: boolean;
|
|
7
|
-
};
|
|
8
|
-
type ReactKey = {
|
|
9
|
-
key?: React.Key | null;
|
|
10
|
-
};
|
|
11
|
-
export declare function collectSSRAssets(options: IProps): React.ReactNode[];
|
|
12
|
-
export declare function createRemoteSSRComponent<T, E extends keyof T>(info: {
|
|
13
|
-
loader: () => Promise<T>;
|
|
14
|
-
loading: React.ReactNode;
|
|
15
|
-
fallback: ErrorBoundaryPropsWithComponent['FallbackComponent'];
|
|
16
|
-
export?: E;
|
|
17
|
-
}): (props: T[E] extends (...args: any) => any ? Parameters<T[E]>[0] extends undefined ? ReactKey : Parameters<T[E]>[0] & ReactKey : ReactKey) => React.JSX.Element;
|
|
18
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function SSRLiveReload(): import("react").JSX.Element | null;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './plugin';
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { moduleFederationPlugin } from '@module-federation/sdk';
|
|
2
|
-
import type { ModuleFederationPlugin as WebpackModuleFederationPlugin } from '@module-federation/enhanced';
|
|
3
|
-
import type { ModuleFederationPlugin as RspackModuleFederationPlugin } from '@module-federation/enhanced/rspack';
|
|
4
|
-
export interface PluginOptions {
|
|
5
|
-
config?: moduleFederationPlugin.ModuleFederationPluginOptions;
|
|
6
|
-
configPath?: string;
|
|
7
|
-
ssr?: {
|
|
8
|
-
distOutputDir?: string;
|
|
9
|
-
} | boolean;
|
|
10
|
-
remoteIpStrategy?: 'ipv4' | 'inherit';
|
|
11
|
-
}
|
|
12
|
-
export interface InternalModernPluginOptions {
|
|
13
|
-
csrConfig?: moduleFederationPlugin.ModuleFederationPluginOptions;
|
|
14
|
-
ssrConfig?: moduleFederationPlugin.ModuleFederationPluginOptions;
|
|
15
|
-
distOutputDir: string;
|
|
16
|
-
originPluginOptions: PluginOptions;
|
|
17
|
-
browserPlugin?: BundlerPlugin;
|
|
18
|
-
nodePlugin?: BundlerPlugin;
|
|
19
|
-
remoteIpStrategy?: 'ipv4' | 'inherit';
|
|
20
|
-
userConfig?: PluginOptions;
|
|
21
|
-
}
|
|
22
|
-
export type BundlerPlugin = WebpackModuleFederationPlugin | RspackModuleFederationPlugin;
|