@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,74 +0,0 @@
|
|
|
1
|
-
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
-
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
3
|
-
import { LOCALHOST } from "../../constant";
|
|
4
|
-
var ipv4 = typeof FEDERATION_IPV4 !== "undefined" ? FEDERATION_IPV4 : "127.0.0.1";
|
|
5
|
-
var remoteIpStrategy = typeof REMOTE_IP_STRATEGY !== "undefined" ? REMOTE_IP_STRATEGY : "inherit";
|
|
6
|
-
function replaceObjectLocalhost(key, obj) {
|
|
7
|
-
if (remoteIpStrategy !== "ipv4") {
|
|
8
|
-
return;
|
|
9
|
-
}
|
|
10
|
-
if (!(key in obj)) {
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
var remote = obj[key];
|
|
14
|
-
if (remote && typeof remote === "string" && remote.includes(LOCALHOST)) {
|
|
15
|
-
obj[key] = replaceLocalhost(remote);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
function replaceLocalhost(url) {
|
|
19
|
-
return url.replace(LOCALHOST, ipv4);
|
|
20
|
-
}
|
|
21
|
-
var resolveEntryIpv4Plugin = function() {
|
|
22
|
-
return {
|
|
23
|
-
name: "resolve-entry-ipv4",
|
|
24
|
-
beforeRegisterRemote: function beforeRegisterRemote(args) {
|
|
25
|
-
var remote = args.remote;
|
|
26
|
-
replaceObjectLocalhost("entry", remote);
|
|
27
|
-
return args;
|
|
28
|
-
},
|
|
29
|
-
afterResolve: function afterResolve(args) {
|
|
30
|
-
return _async_to_generator(function() {
|
|
31
|
-
var remoteInfo;
|
|
32
|
-
return _ts_generator(this, function(_state) {
|
|
33
|
-
remoteInfo = args.remoteInfo;
|
|
34
|
-
replaceObjectLocalhost("entry", remoteInfo);
|
|
35
|
-
return [
|
|
36
|
-
2,
|
|
37
|
-
args
|
|
38
|
-
];
|
|
39
|
-
});
|
|
40
|
-
})();
|
|
41
|
-
},
|
|
42
|
-
beforeLoadRemoteSnapshot: function beforeLoadRemoteSnapshot(args) {
|
|
43
|
-
var moduleInfo = args.moduleInfo;
|
|
44
|
-
if ("entry" in moduleInfo) {
|
|
45
|
-
replaceObjectLocalhost("entry", moduleInfo);
|
|
46
|
-
return args;
|
|
47
|
-
}
|
|
48
|
-
if ("version" in moduleInfo) {
|
|
49
|
-
replaceObjectLocalhost("version", moduleInfo);
|
|
50
|
-
}
|
|
51
|
-
return args;
|
|
52
|
-
},
|
|
53
|
-
loadRemoteSnapshot: function loadRemoteSnapshot(args) {
|
|
54
|
-
var remoteSnapshot = args.remoteSnapshot;
|
|
55
|
-
if ("publicPath" in remoteSnapshot) {
|
|
56
|
-
replaceObjectLocalhost("publicPath", remoteSnapshot);
|
|
57
|
-
}
|
|
58
|
-
if ("getPublicPath" in remoteSnapshot) {
|
|
59
|
-
replaceObjectLocalhost("getPublicPath", remoteSnapshot);
|
|
60
|
-
}
|
|
61
|
-
if (remoteSnapshot.remotesInfo) {
|
|
62
|
-
Object.keys(remoteSnapshot.remotesInfo).forEach(function(key) {
|
|
63
|
-
var remoteInfo = remoteSnapshot.remotesInfo[key];
|
|
64
|
-
replaceObjectLocalhost("matchedVersion", remoteInfo);
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
return args;
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
};
|
|
71
|
-
var resolve_entry_ipv4_default = resolveEntryIpv4Plugin;
|
|
72
|
-
export {
|
|
73
|
-
resolve_entry_ipv4_default as default
|
|
74
|
-
};
|
|
@@ -1,25 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
-
import { _ as _type_of } from "@swc/helpers/_/_type_of";
|
|
3
|
-
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
4
|
-
import path from "path";
|
|
5
|
-
import { fs } from "@modern-js/utils";
|
|
6
|
-
import { ModuleFederationPlugin } from "@module-federation/enhanced/webpack";
|
|
7
|
-
import { ModuleFederationPlugin as RspackModuleFederationPlugin } from "@module-federation/enhanced/rspack";
|
|
8
|
-
import UniverseEntryChunkTrackerPlugin from "@module-federation/node/universe-entry-chunk-tracker-plugin";
|
|
9
|
-
import { updateStatsAndManifest } from "./manifest";
|
|
10
|
-
import { isDev } from "./constant";
|
|
11
|
-
import logger from "./logger";
|
|
12
|
-
import { isWebTarget, skipByTarget } from "./utils";
|
|
13
|
-
function setEnv() {
|
|
14
|
-
process.env["MF_DISABLE_EMIT_STATS"] = "true";
|
|
15
|
-
process.env["MF_SSR_PRJ"] = "true";
|
|
16
|
-
}
|
|
17
|
-
var CHAIN_MF_PLUGIN_ID = "plugin-module-federation-server";
|
|
18
|
-
var mfSSRRsbuildPlugin = function(pluginOptions) {
|
|
19
|
-
return {
|
|
20
|
-
name: "@modern-js/plugin-mf-post-config",
|
|
21
|
-
pre: [
|
|
22
|
-
"@modern-js/builder-plugin-ssr"
|
|
23
|
-
],
|
|
24
|
-
setup: function setup(api) {
|
|
25
|
-
if (pluginOptions.csrConfig.getPublicPath) {
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
var csrOutputPath = "";
|
|
29
|
-
var ssrOutputPath = "";
|
|
30
|
-
var ssrEnv = "";
|
|
31
|
-
api.modifyEnvironmentConfig(function(config, param) {
|
|
32
|
-
var name = param.name;
|
|
33
|
-
var target = config.output.target;
|
|
34
|
-
if (skipByTarget(target)) {
|
|
35
|
-
return config;
|
|
36
|
-
}
|
|
37
|
-
if (isWebTarget(target)) {
|
|
38
|
-
csrOutputPath = config.output.distPath.root;
|
|
39
|
-
} else {
|
|
40
|
-
ssrOutputPath = config.output.distPath.root;
|
|
41
|
-
ssrEnv = name;
|
|
42
|
-
}
|
|
43
|
-
return config;
|
|
44
|
-
});
|
|
45
|
-
var modifySSRPublicPath = function(config, utils) {
|
|
46
|
-
if (ssrEnv !== utils.environment.name) {
|
|
47
|
-
return config;
|
|
48
|
-
}
|
|
49
|
-
var userSSRConfig = pluginOptions.userConfig.ssr ? _type_of(pluginOptions.userConfig.ssr) === "object" ? pluginOptions.userConfig.ssr : {} : {};
|
|
50
|
-
if (userSSRConfig.distOutputDir) {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
config.output.publicPath = "".concat(config.output.publicPath).concat(path.relative(csrOutputPath, ssrOutputPath), "/");
|
|
54
|
-
return config;
|
|
55
|
-
};
|
|
56
|
-
api.modifyWebpackConfig(function(config, utils) {
|
|
57
|
-
modifySSRPublicPath(config, utils);
|
|
58
|
-
return config;
|
|
59
|
-
});
|
|
60
|
-
api.modifyRspackConfig(function(config, utils) {
|
|
61
|
-
modifySSRPublicPath(config, utils);
|
|
62
|
-
return config;
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
};
|
|
67
|
-
var moduleFederationSSRPlugin = function(pluginOptions) {
|
|
68
|
-
return {
|
|
69
|
-
name: "@modern-js/plugin-module-federation-ssr",
|
|
70
|
-
pre: [
|
|
71
|
-
"@modern-js/plugin-module-federation-config",
|
|
72
|
-
"@modern-js/plugin-module-federation"
|
|
73
|
-
],
|
|
74
|
-
setup: function() {
|
|
75
|
-
var _ref = _async_to_generator(function(api) {
|
|
76
|
-
var _pluginOptions_userConfig, _modernjsConfig_server, modernjsConfig, _pluginOptions_userConfig_ssr, enableSSR;
|
|
77
|
-
return _ts_generator(this, function(_state) {
|
|
78
|
-
modernjsConfig = api.getConfig();
|
|
79
|
-
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);
|
|
80
|
-
if (!enableSSR) {
|
|
81
|
-
return [
|
|
82
|
-
2
|
|
83
|
-
];
|
|
84
|
-
}
|
|
85
|
-
setEnv();
|
|
86
|
-
api._internalRuntimePlugins(function(param) {
|
|
87
|
-
var entrypoint = param.entrypoint, plugins = param.plugins;
|
|
88
|
-
if (!isDev) {
|
|
89
|
-
return {
|
|
90
|
-
entrypoint,
|
|
91
|
-
plugins
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
plugins.push({
|
|
95
|
-
name: "mfSSR",
|
|
96
|
-
path: "@module-federation/modern-js/ssr-runtime",
|
|
97
|
-
config: {}
|
|
98
|
-
});
|
|
99
|
-
return {
|
|
100
|
-
entrypoint,
|
|
101
|
-
plugins
|
|
102
|
-
};
|
|
103
|
-
});
|
|
104
|
-
api.modifyBundlerChain(function(chain) {
|
|
105
|
-
var target = chain.get("target");
|
|
106
|
-
if (skipByTarget(target)) {
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
var bundlerType = api.getAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
|
|
110
|
-
var MFPlugin = bundlerType === "webpack" ? ModuleFederationPlugin : RspackModuleFederationPlugin;
|
|
111
|
-
var isWeb = isWebTarget(target);
|
|
112
|
-
if (!isWeb) {
|
|
113
|
-
if (!chain.plugins.has(CHAIN_MF_PLUGIN_ID)) {
|
|
114
|
-
chain.plugin(CHAIN_MF_PLUGIN_ID).use(MFPlugin, [
|
|
115
|
-
pluginOptions.ssrConfig
|
|
116
|
-
]).init(function(Plugin, args) {
|
|
117
|
-
pluginOptions.nodePlugin = new Plugin(args[0]);
|
|
118
|
-
return pluginOptions.nodePlugin;
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
if (!isWeb) {
|
|
123
|
-
chain.target("async-node");
|
|
124
|
-
if (isDev) {
|
|
125
|
-
chain.plugin("UniverseEntryChunkTrackerPlugin").use(UniverseEntryChunkTrackerPlugin);
|
|
126
|
-
}
|
|
127
|
-
var userSSRConfig = pluginOptions.userConfig.ssr ? _type_of(pluginOptions.userConfig.ssr) === "object" ? pluginOptions.userConfig.ssr : {} : {};
|
|
128
|
-
var publicPath = chain.output.get("publicPath");
|
|
129
|
-
if (userSSRConfig.distOutputDir && publicPath) {
|
|
130
|
-
chain.output.publicPath("".concat(publicPath).concat(userSSRConfig.distOutputDir, "/"));
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
if (isDev && isWeb) {
|
|
134
|
-
chain.externals({
|
|
135
|
-
"@module-federation/node/utils": "NOT_USED_IN_BROWSER"
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
api.config(function() {
|
|
140
|
-
return {
|
|
141
|
-
builderPlugins: [
|
|
142
|
-
mfSSRRsbuildPlugin(pluginOptions)
|
|
143
|
-
],
|
|
144
|
-
tools: {
|
|
145
|
-
devServer: {
|
|
146
|
-
before: [
|
|
147
|
-
function(req, res, next) {
|
|
148
|
-
if (!enableSSR) {
|
|
149
|
-
next();
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
try {
|
|
153
|
-
var _req_url, _req_url1;
|
|
154
|
-
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"))) {
|
|
155
|
-
var filepath = path.join(process.cwd(), "dist".concat(req.url));
|
|
156
|
-
fs.statSync(filepath);
|
|
157
|
-
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
158
|
-
res.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, PATCH, OPTIONS");
|
|
159
|
-
res.setHeader("Access-Control-Allow-Headers", "*");
|
|
160
|
-
fs.createReadStream(filepath).pipe(res);
|
|
161
|
-
} else {
|
|
162
|
-
next();
|
|
163
|
-
}
|
|
164
|
-
} catch (err) {
|
|
165
|
-
logger.debug(err);
|
|
166
|
-
next();
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
]
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
};
|
|
173
|
-
});
|
|
174
|
-
api.onAfterBuild(function() {
|
|
175
|
-
var nodePlugin = pluginOptions.nodePlugin, browserPlugin = pluginOptions.browserPlugin, distOutputDir = pluginOptions.distOutputDir;
|
|
176
|
-
updateStatsAndManifest(nodePlugin, browserPlugin, distOutputDir);
|
|
177
|
-
});
|
|
178
|
-
api.onDevCompileDone(function() {
|
|
179
|
-
var nodePlugin = pluginOptions.nodePlugin, browserPlugin = pluginOptions.browserPlugin, distOutputDir = pluginOptions.distOutputDir;
|
|
180
|
-
updateStatsAndManifest(nodePlugin, browserPlugin, distOutputDir);
|
|
181
|
-
});
|
|
182
|
-
return [
|
|
183
|
-
2
|
|
184
|
-
];
|
|
185
|
-
});
|
|
186
|
-
});
|
|
187
|
-
return function(api) {
|
|
188
|
-
return _ref.apply(this, arguments);
|
|
189
|
-
};
|
|
190
|
-
}()
|
|
191
|
-
};
|
|
192
|
-
};
|
|
193
|
-
var ssrPlugin_default = moduleFederationSSRPlugin;
|
|
194
|
-
export {
|
|
195
|
-
CHAIN_MF_PLUGIN_ID,
|
|
196
|
-
ssrPlugin_default as default,
|
|
197
|
-
moduleFederationSSRPlugin,
|
|
198
|
-
setEnv
|
|
199
|
-
};
|
package/dist/esm/cli/utils.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import os from "os";
|
|
2
|
-
var localIpv4 = "127.0.0.1";
|
|
3
|
-
var getIpv4Interfaces = function() {
|
|
4
|
-
try {
|
|
5
|
-
var interfaces = os.networkInterfaces();
|
|
6
|
-
var ipv4Interfaces = [];
|
|
7
|
-
Object.values(interfaces).forEach(function(detail) {
|
|
8
|
-
detail === null || detail === void 0 ? void 0 : detail.forEach(function(detail2) {
|
|
9
|
-
var 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
|
-
var getIPV4 = function() {
|
|
21
|
-
var ipv4Interfaces = getIpv4Interfaces();
|
|
22
|
-
var ipv4Interface = ipv4Interfaces[0] || {
|
|
23
|
-
address: localIpv4
|
|
24
|
-
};
|
|
25
|
-
return ipv4Interface.address;
|
|
26
|
-
};
|
|
27
|
-
var isWebTarget = function(target) {
|
|
28
|
-
var 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
|
-
var skipByTarget = function(target) {
|
|
37
|
-
var 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
|
-
};
|
package/dist/esm/constant.js
DELETED
|
File without changes
|
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
-
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
3
|
-
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
|
4
|
-
import { _ as _object_without_properties } from "@swc/helpers/_/_object_without_properties";
|
|
5
|
-
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
6
|
-
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
7
|
-
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
8
|
-
import React from "react";
|
|
9
|
-
import { getInstance } from "@module-federation/enhanced/runtime";
|
|
10
|
-
import { ErrorBoundary } from "react-error-boundary";
|
|
11
|
-
function getLoadedRemoteInfos(instance, id) {
|
|
12
|
-
var _ref = instance.remoteHandler.idToRemoteMap[id] || {}, name = _ref.name, expose = _ref.expose;
|
|
13
|
-
if (!name) {
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
var module = instance.moduleCache.get(name);
|
|
17
|
-
if (!module) {
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
var remoteSnapshot = instance.snapshotHandler.getGlobalRemoteInfo(module.remoteInfo).remoteSnapshot;
|
|
21
|
-
return _object_spread_props(_object_spread({}, module.remoteInfo), {
|
|
22
|
-
snapshot: remoteSnapshot,
|
|
23
|
-
expose
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
function getTargetModuleInfo(id) {
|
|
27
|
-
var instance = getInstance();
|
|
28
|
-
if (!instance) {
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
var loadedRemoteInfo = getLoadedRemoteInfos(instance, id);
|
|
32
|
-
if (!loadedRemoteInfo) {
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
var snapshot = loadedRemoteInfo.snapshot;
|
|
36
|
-
if (!snapshot) {
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
var publicPath = "publicPath" in snapshot ? snapshot.publicPath : "getPublicPath" in snapshot ? new Function(snapshot.getPublicPath)() : "";
|
|
40
|
-
if (!publicPath) {
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
var modules = "modules" in snapshot ? snapshot.modules : [];
|
|
44
|
-
var targetModule = modules.find(function(m) {
|
|
45
|
-
return m.modulePath === loadedRemoteInfo.expose;
|
|
46
|
-
});
|
|
47
|
-
if (!targetModule) {
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
var remoteEntry = "remoteEntry" in snapshot ? snapshot.remoteEntry : "";
|
|
51
|
-
if (!remoteEntry) {
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
return {
|
|
55
|
-
module: targetModule,
|
|
56
|
-
publicPath,
|
|
57
|
-
remoteEntry
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
function collectSSRAssets(options) {
|
|
61
|
-
var _ref = typeof options === "string" ? {
|
|
62
|
-
id: options
|
|
63
|
-
} : options, id = _ref.id, _ref_injectLink = _ref.injectLink, injectLink = _ref_injectLink === void 0 ? true : _ref_injectLink, _ref_injectScript = _ref.injectScript, injectScript = _ref_injectScript === void 0 ? true : _ref_injectScript;
|
|
64
|
-
var links = [];
|
|
65
|
-
var scripts = [];
|
|
66
|
-
var instance = getInstance();
|
|
67
|
-
if (!instance || !injectLink && !injectScript) {
|
|
68
|
-
return _to_consumable_array(scripts).concat(_to_consumable_array(links));
|
|
69
|
-
}
|
|
70
|
-
var moduleAndPublicPath = getTargetModuleInfo(id);
|
|
71
|
-
if (!moduleAndPublicPath) {
|
|
72
|
-
return _to_consumable_array(scripts).concat(_to_consumable_array(links));
|
|
73
|
-
}
|
|
74
|
-
var targetModule = moduleAndPublicPath.module, publicPath = moduleAndPublicPath.publicPath, remoteEntry = moduleAndPublicPath.remoteEntry;
|
|
75
|
-
if (injectLink) {
|
|
76
|
-
_to_consumable_array(targetModule.assets.css.sync).concat(_to_consumable_array(targetModule.assets.css.async)).forEach(function(file, index) {
|
|
77
|
-
links.push(/* @__PURE__ */ _jsx("link", {
|
|
78
|
-
href: "".concat(publicPath).concat(file),
|
|
79
|
-
rel: "stylesheet",
|
|
80
|
-
type: "text/css"
|
|
81
|
-
}, "".concat(file.split(".")[0], "_").concat(index)));
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
if (injectScript) {
|
|
85
|
-
scripts.push(/* @__PURE__ */ _jsx("script", {
|
|
86
|
-
async: true,
|
|
87
|
-
src: "".concat(publicPath).concat(remoteEntry),
|
|
88
|
-
crossOrigin: "anonymous"
|
|
89
|
-
}, remoteEntry.split(".")[0]));
|
|
90
|
-
_to_consumable_array(targetModule.assets.js.sync).forEach(function(file, index) {
|
|
91
|
-
scripts.push(/* @__PURE__ */ _jsx("script", {
|
|
92
|
-
async: true,
|
|
93
|
-
src: "".concat(publicPath).concat(file),
|
|
94
|
-
crossOrigin: "anonymous"
|
|
95
|
-
}, "".concat(file.split(".")[0], "_").concat(index)));
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
return _to_consumable_array(scripts).concat(_to_consumable_array(links));
|
|
99
|
-
}
|
|
100
|
-
function createRemoteSSRComponent(info) {
|
|
101
|
-
var exportName = (info === null || info === void 0 ? void 0 : info.export) || "default";
|
|
102
|
-
var LazyComponent = /* @__PURE__ */ React.lazy(/* @__PURE__ */ _async_to_generator(function() {
|
|
103
|
-
var m, moduleId, assets, Com, err, FallbackFunctionComponent, FallbackNode;
|
|
104
|
-
return _ts_generator(this, function(_state) {
|
|
105
|
-
switch (_state.label) {
|
|
106
|
-
case 0:
|
|
107
|
-
_state.trys.push([
|
|
108
|
-
0,
|
|
109
|
-
2,
|
|
110
|
-
,
|
|
111
|
-
3
|
|
112
|
-
]);
|
|
113
|
-
return [
|
|
114
|
-
4,
|
|
115
|
-
info.loader()
|
|
116
|
-
];
|
|
117
|
-
case 1:
|
|
118
|
-
m = _state.sent();
|
|
119
|
-
if (!m) {
|
|
120
|
-
throw new Error("load remote failed");
|
|
121
|
-
}
|
|
122
|
-
moduleId = m && m[Symbol.for("mf_module_id")];
|
|
123
|
-
assets = collectSSRAssets({
|
|
124
|
-
id: moduleId
|
|
125
|
-
});
|
|
126
|
-
Com = m[exportName];
|
|
127
|
-
if (exportName in m && typeof Com === "function") {
|
|
128
|
-
return [
|
|
129
|
-
2,
|
|
130
|
-
{
|
|
131
|
-
default: function(props) {
|
|
132
|
-
return /* @__PURE__ */ _jsxs(_Fragment, {
|
|
133
|
-
children: [
|
|
134
|
-
assets,
|
|
135
|
-
/* @__PURE__ */ _jsx(Com, _object_spread({}, props))
|
|
136
|
-
]
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
];
|
|
141
|
-
} else {
|
|
142
|
-
throw Error("Make sure that ".concat(moduleId, " has the correct export when export is ").concat(String(exportName)));
|
|
143
|
-
}
|
|
144
|
-
return [
|
|
145
|
-
3,
|
|
146
|
-
3
|
|
147
|
-
];
|
|
148
|
-
case 2:
|
|
149
|
-
err = _state.sent();
|
|
150
|
-
if (!info.fallback) {
|
|
151
|
-
throw err;
|
|
152
|
-
}
|
|
153
|
-
FallbackFunctionComponent = info.fallback;
|
|
154
|
-
FallbackNode = /* @__PURE__ */ _jsx(FallbackFunctionComponent, {
|
|
155
|
-
error: err,
|
|
156
|
-
resetErrorBoundary: function() {
|
|
157
|
-
console.log('SSR mode not support "resetErrorBoundary" !');
|
|
158
|
-
}
|
|
159
|
-
});
|
|
160
|
-
return [
|
|
161
|
-
2,
|
|
162
|
-
{
|
|
163
|
-
default: function() {
|
|
164
|
-
return FallbackNode;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
];
|
|
168
|
-
case 3:
|
|
169
|
-
return [
|
|
170
|
-
2
|
|
171
|
-
];
|
|
172
|
-
}
|
|
173
|
-
});
|
|
174
|
-
}));
|
|
175
|
-
return function(props) {
|
|
176
|
-
var key = props.key, args = _object_without_properties(props, [
|
|
177
|
-
"key"
|
|
178
|
-
]);
|
|
179
|
-
return /* @__PURE__ */ _jsx(ErrorBoundary, {
|
|
180
|
-
FallbackComponent: info.fallback,
|
|
181
|
-
children: /* @__PURE__ */ _jsx(React.Suspense, {
|
|
182
|
-
fallback: info.loading,
|
|
183
|
-
children: /* @__PURE__ */ _jsx(LazyComponent, _object_spread({}, args))
|
|
184
|
-
})
|
|
185
|
-
});
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
export {
|
|
189
|
-
collectSSRAssets,
|
|
190
|
-
createRemoteSSRComponent
|
|
191
|
-
};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export * from "@module-federation/enhanced/runtime";
|
|
2
|
-
var 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,26 +0,0 @@
|
|
|
1
|
-
import { _ as _tagged_template_literal } from "@swc/helpers/_/_tagged_template_literal";
|
|
2
|
-
function _templateObject() {
|
|
3
|
-
var data = _tagged_template_literal([
|
|
4
|
-
"\n if(",
|
|
5
|
-
"){\n location.reload();\n }\n "
|
|
6
|
-
]);
|
|
7
|
-
_templateObject = function _templateObject2() {
|
|
8
|
-
return data;
|
|
9
|
-
};
|
|
10
|
-
return data;
|
|
11
|
-
}
|
|
12
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
-
function SSRLiveReload() {
|
|
14
|
-
if (process.env.NODE_ENV !== "development") {
|
|
15
|
-
return null;
|
|
16
|
-
}
|
|
17
|
-
return /* @__PURE__ */ _jsx("script", {
|
|
18
|
-
suppressHydrationWarning: true,
|
|
19
|
-
dangerouslySetInnerHTML: {
|
|
20
|
-
__html: String.raw(_templateObject(), globalThis.shouldUpdate)
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
export {
|
|
25
|
-
SSRLiveReload
|
|
26
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./plugin";
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
-
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
3
|
-
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
4
|
-
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
5
|
-
import { SSRLiveReload } from "./SSRLiveReload";
|
|
6
|
-
var mfSSRPlugin = function() {
|
|
7
|
-
return {
|
|
8
|
-
name: "@module-federation/modern-js",
|
|
9
|
-
setup: function(api) {
|
|
10
|
-
api.onBeforeRender(/* @__PURE__ */ _async_to_generator(function() {
|
|
11
|
-
var nodeUtils, shouldUpdate;
|
|
12
|
-
return _ts_generator(this, function(_state) {
|
|
13
|
-
switch (_state.label) {
|
|
14
|
-
case 0:
|
|
15
|
-
if (typeof window !== "undefined") {
|
|
16
|
-
return [
|
|
17
|
-
2
|
|
18
|
-
];
|
|
19
|
-
}
|
|
20
|
-
globalThis.shouldUpdate = false;
|
|
21
|
-
return [
|
|
22
|
-
4,
|
|
23
|
-
import("@module-federation/node/utils")
|
|
24
|
-
];
|
|
25
|
-
case 1:
|
|
26
|
-
nodeUtils = _state.sent();
|
|
27
|
-
return [
|
|
28
|
-
4,
|
|
29
|
-
nodeUtils.revalidate()
|
|
30
|
-
];
|
|
31
|
-
case 2:
|
|
32
|
-
shouldUpdate = _state.sent();
|
|
33
|
-
if (!shouldUpdate)
|
|
34
|
-
return [
|
|
35
|
-
3,
|
|
36
|
-
4
|
|
37
|
-
];
|
|
38
|
-
console.log("should RELOAD", shouldUpdate);
|
|
39
|
-
return [
|
|
40
|
-
4,
|
|
41
|
-
nodeUtils.flushChunks()
|
|
42
|
-
];
|
|
43
|
-
case 3:
|
|
44
|
-
_state.sent();
|
|
45
|
-
globalThis.shouldUpdate = true;
|
|
46
|
-
_state.label = 4;
|
|
47
|
-
case 4:
|
|
48
|
-
return [
|
|
49
|
-
2
|
|
50
|
-
];
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
}));
|
|
54
|
-
api.wrapRoot(function(App) {
|
|
55
|
-
var AppWrapper = function(props) {
|
|
56
|
-
return /* @__PURE__ */ _jsxs(_Fragment, {
|
|
57
|
-
children: [
|
|
58
|
-
/* @__PURE__ */ _jsx(SSRLiveReload, {}),
|
|
59
|
-
/* @__PURE__ */ _jsx(App, _object_spread({}, props))
|
|
60
|
-
]
|
|
61
|
-
});
|
|
62
|
-
};
|
|
63
|
-
return AppWrapper;
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
};
|
|
68
|
-
export {
|
|
69
|
-
mfSSRPlugin
|
|
70
|
-
};
|
package/dist/esm/types/index.js
DELETED
|
File without changes
|