@module-federation/modern-js 0.0.0-next-20240605083609 → 0.0.0-next-20240620090145
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/index.js +10 -7
- package/dist/cjs/cli/mfRuntimePlugins/resolve-entry-ipv4.js +60 -0
- package/dist/cjs/cli/mfRuntimePlugins/shared-strategy.js +5 -4
- package/dist/cjs/cli/utils.js +101 -24
- package/dist/cjs/constant.js +3 -0
- package/dist/cjs/runtime/LiveReload.js +43 -0
- package/dist/cjs/runtime/MFReactComponent.js +6 -2
- package/dist/cjs/runtime/index.js +3 -0
- package/dist/cjs/ssr-runtime/plugin.js +3 -17
- package/dist/esm/cli/index.js +123 -107
- package/dist/esm/cli/mfRuntimePlugins/resolve-entry-ipv4.js +54 -0
- package/dist/esm/cli/mfRuntimePlugins/shared-strategy.js +5 -4
- package/dist/esm/cli/utils.js +174 -22
- package/dist/esm/constant.js +2 -0
- package/dist/esm/runtime/LiveReload.js +26 -0
- package/dist/esm/runtime/MFReactComponent.js +6 -2
- package/dist/esm/runtime/index.js +2 -0
- package/dist/esm/ssr-runtime/plugin.js +12 -37
- package/dist/esm-node/cli/index.js +11 -8
- package/dist/esm-node/cli/mfRuntimePlugins/resolve-entry-ipv4.js +40 -0
- package/dist/esm-node/cli/mfRuntimePlugins/shared-strategy.js +5 -4
- package/dist/esm-node/cli/utils.js +100 -24
- package/dist/esm-node/constant.js +2 -0
- package/dist/esm-node/runtime/LiveReload.js +19 -0
- package/dist/esm-node/runtime/MFReactComponent.js +6 -2
- package/dist/esm-node/runtime/index.js +2 -0
- package/dist/esm-node/ssr-runtime/plugin.js +3 -17
- package/dist/types/cli/mfRuntimePlugins/resolve-entry-ipv4.d.ts +3 -0
- package/dist/types/cli/utils.d.ts +5 -24
- package/dist/types/constant.d.ts +1 -0
- package/dist/types/runtime/LiveReload.d.ts +2 -0
- package/dist/types/runtime/MFReactComponent.d.ts +4 -3
- package/dist/types/runtime/index.d.ts +1 -0
- package/dist/types/ssr-runtime/plugin.d.ts +1 -3
- package/package.json +5 -6
package/dist/esm/cli/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import { fs } from "@modern-js/utils";
|
|
|
5
5
|
import { ModuleFederationPlugin as WebpackModuleFederationPlugin, AsyncBoundaryPlugin } from "@module-federation/enhanced";
|
|
6
6
|
import { ModuleFederationPlugin as RspackModuleFederationPlugin } from "@module-federation/enhanced/rspack";
|
|
7
7
|
import { StreamingTargetPlugin, EntryChunkTrackerPlugin } from "@module-federation/node";
|
|
8
|
-
import { getMFConfig, getTargetEnvConfig, patchWebpackConfig } from "./utils";
|
|
8
|
+
import { getMFConfig, getTargetEnvConfig, patchWebpackConfig, lookupIpv4 } from "./utils";
|
|
9
9
|
import { updateStatsAndManifest } from "./manifest";
|
|
10
10
|
import { MODERN_JS_SERVER_DIR } from "../constant";
|
|
11
11
|
var SSR_PLUGIN_IDENTIFIER = "mfPluginSSR";
|
|
@@ -33,115 +33,133 @@ var moduleFederationPlugin = function() {
|
|
|
33
33
|
return [
|
|
34
34
|
2,
|
|
35
35
|
{
|
|
36
|
-
config: function() {
|
|
37
|
-
var _modernjsConfig_dev;
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
if (isServer) {
|
|
49
|
-
var _config_plugins, _config_plugins1;
|
|
50
|
-
nodePlugin = new MFBundlerPlugin(envConfig);
|
|
51
|
-
(_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(nodePlugin);
|
|
52
|
-
(_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(new StreamingTargetPlugin(envConfig));
|
|
53
|
-
if (isDev) {
|
|
54
|
-
var _config_plugins2;
|
|
55
|
-
(_config_plugins2 = config.plugins) === null || _config_plugins2 === void 0 ? void 0 : _config_plugins2.push(new EntryChunkTrackerPlugin());
|
|
56
|
-
}
|
|
57
|
-
} else {
|
|
58
|
-
var _config_output, _config_plugins3;
|
|
59
|
-
outputDir = ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.path) || path.resolve(process.cwd(), "dist");
|
|
60
|
-
browserPlugin = new MFBundlerPlugin(envConfig);
|
|
61
|
-
(_config_plugins3 = config.plugins) === null || _config_plugins3 === void 0 ? void 0 : _config_plugins3.push(browserPlugin);
|
|
62
|
-
}
|
|
63
|
-
patchWebpackConfig({
|
|
64
|
-
bundlerConfig: config,
|
|
65
|
-
isServer,
|
|
66
|
-
modernjsConfig,
|
|
67
|
-
mfConfig: envConfig
|
|
68
|
-
});
|
|
69
|
-
};
|
|
70
|
-
return {
|
|
71
|
-
tools: {
|
|
72
|
-
rspack: function rspack(config) {
|
|
73
|
-
modifyBundlerConfig(config, false);
|
|
74
|
-
},
|
|
75
|
-
webpack: function webpack(config, param2) {
|
|
76
|
-
var isServer = param2.isServer;
|
|
77
|
-
var _modernjsConfig_source;
|
|
78
|
-
modifyBundlerConfig(config, isServer);
|
|
79
|
-
var enableAsyncEntry = (_modernjsConfig_source = modernjsConfig.source) === null || _modernjsConfig_source === void 0 ? void 0 : _modernjsConfig_source.enableAsyncEntry;
|
|
80
|
-
if (mfConfig.async || !enableAsyncEntry && mfConfig.async !== false) {
|
|
81
|
-
var _config_plugins;
|
|
82
|
-
var asyncBoundaryPluginOptions = typeof mfConfig.async === "object" ? mfConfig.async : {
|
|
83
|
-
eager: function(module) {
|
|
84
|
-
return module && /\.federation/.test((module === null || module === void 0 ? void 0 : module.request) || "");
|
|
85
|
-
},
|
|
86
|
-
excludeChunk: function(chunk) {
|
|
87
|
-
return chunk.name === mfConfig.name;
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
(_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(new AsyncBoundaryPlugin(asyncBoundaryPluginOptions));
|
|
36
|
+
config: /* @__PURE__ */ _async_to_generator(function() {
|
|
37
|
+
var _modernjsConfig_dev, bundlerType, WebpackPluginConstructor, RspackPluginConstructor, MFBundlerPlugin, modifyBundlerConfig, ipv4;
|
|
38
|
+
return _ts_generator(this, function(_state2) {
|
|
39
|
+
switch (_state2.label) {
|
|
40
|
+
case 0:
|
|
41
|
+
bundlerType = useAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
|
|
42
|
+
WebpackPluginConstructor = userConfig.webpackPluginImplementation || WebpackModuleFederationPlugin;
|
|
43
|
+
RspackPluginConstructor = userConfig.rspackPluginImplementation || RspackModuleFederationPlugin;
|
|
44
|
+
MFBundlerPlugin = bundlerType === "rspack" ? RspackPluginConstructor : WebpackPluginConstructor;
|
|
45
|
+
if (enableSSR) {
|
|
46
|
+
process.env["MF_DISABLE_EMIT_STATS"] = "true";
|
|
47
|
+
process.env["MF_SSR_PRJ"] = "true";
|
|
91
48
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
next();
|
|
103
|
-
return;
|
|
49
|
+
modifyBundlerConfig = function(config, isServer) {
|
|
50
|
+
var envConfig = getTargetEnvConfig(mfConfig, isServer);
|
|
51
|
+
if (isServer) {
|
|
52
|
+
var _config_plugins, _config_plugins1;
|
|
53
|
+
nodePlugin = new MFBundlerPlugin(envConfig);
|
|
54
|
+
(_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(nodePlugin);
|
|
55
|
+
(_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(new StreamingTargetPlugin(envConfig));
|
|
56
|
+
if (isDev) {
|
|
57
|
+
var _config_plugins2;
|
|
58
|
+
(_config_plugins2 = config.plugins) === null || _config_plugins2 === void 0 ? void 0 : _config_plugins2.push(new EntryChunkTrackerPlugin());
|
|
104
59
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
60
|
+
} else {
|
|
61
|
+
var _config_output, _config_plugins3;
|
|
62
|
+
outputDir = ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.path) || path.resolve(process.cwd(), "dist");
|
|
63
|
+
browserPlugin = new MFBundlerPlugin(envConfig);
|
|
64
|
+
(_config_plugins3 = config.plugins) === null || _config_plugins3 === void 0 ? void 0 : _config_plugins3.push(browserPlugin);
|
|
65
|
+
}
|
|
66
|
+
patchWebpackConfig({
|
|
67
|
+
bundlerConfig: config,
|
|
68
|
+
isServer,
|
|
69
|
+
modernjsConfig,
|
|
70
|
+
mfConfig: envConfig
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
return [
|
|
74
|
+
4,
|
|
75
|
+
lookupIpv4()
|
|
76
|
+
];
|
|
77
|
+
case 1:
|
|
78
|
+
ipv4 = _state2.sent();
|
|
79
|
+
return [
|
|
80
|
+
2,
|
|
81
|
+
{
|
|
82
|
+
tools: {
|
|
83
|
+
rspack: function rspack(config) {
|
|
84
|
+
modifyBundlerConfig(config, false);
|
|
85
|
+
},
|
|
86
|
+
webpack: function webpack(config, param2) {
|
|
87
|
+
var isServer = param2.isServer;
|
|
88
|
+
var _modernjsConfig_source;
|
|
89
|
+
modifyBundlerConfig(config, isServer);
|
|
90
|
+
var enableAsyncEntry = (_modernjsConfig_source = modernjsConfig.source) === null || _modernjsConfig_source === void 0 ? void 0 : _modernjsConfig_source.enableAsyncEntry;
|
|
91
|
+
if (mfConfig.async || !enableAsyncEntry && mfConfig.async !== false) {
|
|
92
|
+
var _config_plugins;
|
|
93
|
+
var asyncBoundaryPluginOptions = typeof mfConfig.async === "object" ? mfConfig.async : {
|
|
94
|
+
eager: function(module) {
|
|
95
|
+
return module && /\.federation/.test((module === null || module === void 0 ? void 0 : module.request) || "");
|
|
96
|
+
},
|
|
97
|
+
excludeChunk: function(chunk) {
|
|
98
|
+
return chunk.name === mfConfig.name;
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
(_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(new AsyncBoundaryPlugin(asyncBoundaryPluginOptions));
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
devServer: {
|
|
105
|
+
headers: {
|
|
106
|
+
"Access-Control-Allow-Origin": "*",
|
|
107
|
+
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, PATCH, OPTIONS",
|
|
108
|
+
"Access-Control-Allow-Headers": "X-Requested-With, content-type, Authorization"
|
|
109
|
+
},
|
|
110
|
+
before: [
|
|
111
|
+
function(req, res, next) {
|
|
112
|
+
if (!enableSSR) {
|
|
113
|
+
next();
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
try {
|
|
117
|
+
var _req_url, _req_url1, _req_url2;
|
|
118
|
+
var SERVER_PREFIX = "/".concat(MODERN_JS_SERVER_DIR);
|
|
119
|
+
if (((_req_url = req.url) === null || _req_url === void 0 ? void 0 : _req_url.startsWith(SERVER_PREFIX)) || ((_req_url1 = req.url) === null || _req_url1 === void 0 ? void 0 : _req_url1.includes(".json")) && !((_req_url2 = req.url) === null || _req_url2 === void 0 ? void 0 : _req_url2.includes("hot-update"))) {
|
|
120
|
+
var filepath = path.join(process.cwd(), "dist".concat(req.url));
|
|
121
|
+
fs.statSync(filepath);
|
|
122
|
+
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
123
|
+
res.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, PATCH, OPTIONS");
|
|
124
|
+
res.setHeader("Access-Control-Allow-Headers", "X-Requested-With, content-type, Authorization");
|
|
125
|
+
fs.createReadStream(filepath).pipe(res);
|
|
126
|
+
} else {
|
|
127
|
+
next();
|
|
128
|
+
}
|
|
129
|
+
} catch (err) {
|
|
130
|
+
if (process.env.FEDERATION_DEBUG) {
|
|
131
|
+
console.error(err);
|
|
132
|
+
}
|
|
133
|
+
next();
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
]
|
|
137
|
+
},
|
|
138
|
+
bundlerChain: function bundlerChain(chain, param2) {
|
|
139
|
+
var isServer = param2.isServer;
|
|
140
|
+
if (isDev && !isServer) {
|
|
141
|
+
chain.externals({
|
|
142
|
+
"@module-federation/node/utils": "NOT_USED_IN_BROWSER"
|
|
143
|
+
});
|
|
144
|
+
}
|
|
117
145
|
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
|
|
146
|
+
},
|
|
147
|
+
source: {
|
|
148
|
+
alias: {
|
|
149
|
+
"@modern-js/runtime/mf": require.resolve("@module-federation/modern-js/runtime")
|
|
150
|
+
},
|
|
151
|
+
define: {
|
|
152
|
+
FEDERATION_IPV4: JSON.stringify(ipv4)
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
dev: {
|
|
156
|
+
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
|
|
121
157
|
}
|
|
122
158
|
}
|
|
123
|
-
]
|
|
124
|
-
},
|
|
125
|
-
bundlerChain: function bundlerChain(chain, param2) {
|
|
126
|
-
var isServer = param2.isServer;
|
|
127
|
-
if (isDev && !isServer) {
|
|
128
|
-
chain.externals({
|
|
129
|
-
"@module-federation/node/utils": "NOT_USED_IN_BROWSER",
|
|
130
|
-
"@module-federation/dts-plugin/server": "NOT_USED_IN_BROWSER"
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
},
|
|
135
|
-
source: {
|
|
136
|
-
alias: {
|
|
137
|
-
"@modern-js/runtime/mf": require.resolve("@module-federation/modern-js/runtime")
|
|
138
|
-
}
|
|
139
|
-
},
|
|
140
|
-
dev: {
|
|
141
|
-
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
|
|
159
|
+
];
|
|
142
160
|
}
|
|
143
|
-
};
|
|
144
|
-
},
|
|
161
|
+
});
|
|
162
|
+
}),
|
|
145
163
|
modifyEntryImports: function modifyEntryImports(param2) {
|
|
146
164
|
var entrypoint = param2.entrypoint, imports = param2.imports;
|
|
147
165
|
if (!enableSSR || !isDev) {
|
|
@@ -173,9 +191,7 @@ var moduleFederationPlugin = function() {
|
|
|
173
191
|
}
|
|
174
192
|
plugins.unshift({
|
|
175
193
|
name: SSR_PLUGIN_IDENTIFIER,
|
|
176
|
-
options: JSON.stringify({
|
|
177
|
-
name: mfConfig.name
|
|
178
|
-
})
|
|
194
|
+
options: JSON.stringify({})
|
|
179
195
|
});
|
|
180
196
|
return {
|
|
181
197
|
entrypoint,
|
|
@@ -0,0 +1,54 @@
|
|
|
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
|
+
function replaceLocalhost(url) {
|
|
6
|
+
return url.replace(LOCALHOST, ipv4);
|
|
7
|
+
}
|
|
8
|
+
var resolveEntryIpv4Plugin = function() {
|
|
9
|
+
return {
|
|
10
|
+
name: "resolve-entry-ipv4",
|
|
11
|
+
beforeRegisterRemote: function beforeRegisterRemote(args) {
|
|
12
|
+
var remote = args.remote;
|
|
13
|
+
if ("entry" in remote && remote.entry.includes(LOCALHOST)) {
|
|
14
|
+
remote.entry = replaceLocalhost(remote.entry);
|
|
15
|
+
}
|
|
16
|
+
return args;
|
|
17
|
+
},
|
|
18
|
+
afterResolve: (
|
|
19
|
+
// async fetch(manifestUrl) {
|
|
20
|
+
// const ipv4ManifestUrl = manifestUrl.replace(LOCALHOST, ipv4);
|
|
21
|
+
// return globalThis.fetch(ipv4ManifestUrl);
|
|
22
|
+
// },
|
|
23
|
+
function afterResolve(args) {
|
|
24
|
+
return _async_to_generator(function() {
|
|
25
|
+
var remoteInfo;
|
|
26
|
+
return _ts_generator(this, function(_state) {
|
|
27
|
+
remoteInfo = args.remoteInfo;
|
|
28
|
+
if (remoteInfo.entry.includes(LOCALHOST)) {
|
|
29
|
+
remoteInfo.entry = replaceLocalhost(remoteInfo.entry);
|
|
30
|
+
}
|
|
31
|
+
return [
|
|
32
|
+
2,
|
|
33
|
+
args
|
|
34
|
+
];
|
|
35
|
+
});
|
|
36
|
+
})();
|
|
37
|
+
}
|
|
38
|
+
),
|
|
39
|
+
loadRemoteSnapshot: function loadRemoteSnapshot(args) {
|
|
40
|
+
var remoteSnapshot = args.remoteSnapshot;
|
|
41
|
+
if ("publicPath" in remoteSnapshot && remoteSnapshot.publicPath.includes(LOCALHOST)) {
|
|
42
|
+
remoteSnapshot.publicPath = replaceLocalhost(remoteSnapshot.publicPath);
|
|
43
|
+
}
|
|
44
|
+
if ("getPublicPath" in remoteSnapshot && remoteSnapshot.getPublicPath.includes(LOCALHOST)) {
|
|
45
|
+
remoteSnapshot.getPublicPath = replaceLocalhost(remoteSnapshot.getPublicPath);
|
|
46
|
+
}
|
|
47
|
+
return args;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
var resolve_entry_ipv4_default = resolveEntryIpv4Plugin;
|
|
52
|
+
export {
|
|
53
|
+
resolve_entry_ipv4_default as default
|
|
54
|
+
};
|
|
@@ -2,10 +2,11 @@ var sharedStrategy = function() {
|
|
|
2
2
|
return {
|
|
3
3
|
name: "shared-strategy-plugin",
|
|
4
4
|
beforeInit: function beforeInit(args) {
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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];
|
|
9
10
|
var arraySharedConfigs = Array.isArray(sharedConfigs) ? sharedConfigs : [
|
|
10
11
|
sharedConfigs
|
|
11
12
|
];
|
package/dist/esm/cli/utils.js
CHANGED
|
@@ -6,6 +6,8 @@ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
|
6
6
|
import { encodeName } from "@module-federation/sdk";
|
|
7
7
|
import path from "path";
|
|
8
8
|
import { bundle } from "@modern-js/node-bundle-require";
|
|
9
|
+
import dns from "dns";
|
|
10
|
+
import { LOCALHOST } from "../constant";
|
|
9
11
|
var defaultPath = path.resolve(process.cwd(), "module-federation.config.ts");
|
|
10
12
|
var getMFConfig = function() {
|
|
11
13
|
var _ref = _async_to_generator(function(userConfig) {
|
|
@@ -33,6 +35,12 @@ var getMFConfig = function() {
|
|
|
33
35
|
];
|
|
34
36
|
case 2:
|
|
35
37
|
mfConfig = _state.sent().default;
|
|
38
|
+
return [
|
|
39
|
+
4,
|
|
40
|
+
replaceRemoteUrl(mfConfig)
|
|
41
|
+
];
|
|
42
|
+
case 3:
|
|
43
|
+
_state.sent();
|
|
36
44
|
return [
|
|
37
45
|
2,
|
|
38
46
|
mfConfig
|
|
@@ -44,40 +52,81 @@ var getMFConfig = function() {
|
|
|
44
52
|
return _ref.apply(this, arguments);
|
|
45
53
|
};
|
|
46
54
|
}();
|
|
55
|
+
var injectRuntimePlugins = function(runtimePlugin, runtimePlugins) {
|
|
56
|
+
if (!runtimePlugins.includes(runtimePlugin)) {
|
|
57
|
+
runtimePlugins.push(runtimePlugin);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
var replaceRemoteUrl = function() {
|
|
61
|
+
var _ref = _async_to_generator(function(mfConfig) {
|
|
62
|
+
var ipv4, handleRemoteObject;
|
|
63
|
+
return _ts_generator(this, function(_state) {
|
|
64
|
+
switch (_state.label) {
|
|
65
|
+
case 0:
|
|
66
|
+
if (!mfConfig.remotes) {
|
|
67
|
+
return [
|
|
68
|
+
2
|
|
69
|
+
];
|
|
70
|
+
}
|
|
71
|
+
return [
|
|
72
|
+
4,
|
|
73
|
+
lookupIpv4()
|
|
74
|
+
];
|
|
75
|
+
case 1:
|
|
76
|
+
ipv4 = _state.sent();
|
|
77
|
+
handleRemoteObject = function(remoteObject) {
|
|
78
|
+
Object.keys(remoteObject).forEach(function(remoteKey) {
|
|
79
|
+
var remote = remoteObject[remoteKey];
|
|
80
|
+
if (Array.isArray(remote)) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if (typeof remote === "string" && remote.includes(LOCALHOST)) {
|
|
84
|
+
remoteObject[remoteKey] = remote.replace(LOCALHOST, ipv4);
|
|
85
|
+
}
|
|
86
|
+
if (typeof remote === "object" && !Array.isArray(remote.external) && remote.external.includes(LOCALHOST)) {
|
|
87
|
+
remote.external = remote.external.replace(LOCALHOST, ipv4);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
};
|
|
91
|
+
if (Array.isArray(mfConfig.remotes)) {
|
|
92
|
+
mfConfig.remotes.forEach(function(remoteObject) {
|
|
93
|
+
if (typeof remoteObject === "string") {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
handleRemoteObject(remoteObject);
|
|
97
|
+
});
|
|
98
|
+
} else if (typeof mfConfig.remotes !== "string") {
|
|
99
|
+
handleRemoteObject(mfConfig.remotes);
|
|
100
|
+
}
|
|
101
|
+
return [
|
|
102
|
+
2
|
|
103
|
+
];
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
return function replaceRemoteUrl2(mfConfig) {
|
|
108
|
+
return _ref.apply(this, arguments);
|
|
109
|
+
};
|
|
110
|
+
}();
|
|
47
111
|
var patchMFConfig = function(mfConfig, isServer) {
|
|
112
|
+
var isDev = process.env.NODE_ENV === "development";
|
|
48
113
|
var runtimePlugins = _to_consumable_array(mfConfig.runtimePlugins || []);
|
|
49
|
-
|
|
50
|
-
if (
|
|
51
|
-
|
|
114
|
+
injectRuntimePlugins(path.resolve(__dirname, "./mfRuntimePlugins/shared-strategy.js"), runtimePlugins);
|
|
115
|
+
if (isDev) {
|
|
116
|
+
injectRuntimePlugins(path.resolve(__dirname, "./mfRuntimePlugins/resolve-entry-ipv4.js"), runtimePlugins);
|
|
52
117
|
}
|
|
53
118
|
if (isServer) {
|
|
54
|
-
var isDev = process.env.NODE_ENV === "development";
|
|
55
119
|
if (isDev) {
|
|
56
|
-
|
|
57
|
-
if (!runtimePlugins.includes(nodeHmrPluginPath)) {
|
|
58
|
-
runtimePlugins.push(nodeHmrPluginPath);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
var injectNodeFetchRuntimePluginPath = path.resolve(__dirname, "./mfRuntimePlugins/inject-node-fetch.js");
|
|
62
|
-
if (!runtimePlugins.includes(injectNodeFetchRuntimePluginPath)) {
|
|
63
|
-
runtimePlugins.push(injectNodeFetchRuntimePluginPath);
|
|
120
|
+
injectRuntimePlugins(require.resolve("@module-federation/node/record-dynamic-remote-entry-hash-plugin"), runtimePlugins);
|
|
64
121
|
}
|
|
122
|
+
injectRuntimePlugins(path.resolve(__dirname, "./mfRuntimePlugins/inject-node-fetch.js"), runtimePlugins);
|
|
65
123
|
}
|
|
66
124
|
if (typeof mfConfig.async === "undefined") {
|
|
67
125
|
mfConfig.async = true;
|
|
68
126
|
}
|
|
69
127
|
if (!isServer) {
|
|
70
128
|
return _object_spread_props(_object_spread({}, mfConfig), {
|
|
71
|
-
runtimePlugins
|
|
72
|
-
dts: mfConfig.dts === false ? false : _object_spread({
|
|
73
|
-
generateTypes: false,
|
|
74
|
-
consumeTypes: false
|
|
75
|
-
}, typeof mfConfig.dts === "object" ? mfConfig.dts : {}),
|
|
76
|
-
dev: mfConfig.dev === false ? false : _object_spread({
|
|
77
|
-
disableHotTypesReload: true,
|
|
78
|
-
disableLiveReload: false,
|
|
79
|
-
injectWebClient: true
|
|
80
|
-
}, typeof mfConfig.dev === "object" ? mfConfig.dev : {})
|
|
129
|
+
runtimePlugins
|
|
81
130
|
});
|
|
82
131
|
}
|
|
83
132
|
return _object_spread_props(_object_spread({}, mfConfig), {
|
|
@@ -111,6 +160,9 @@ function patchWebpackConfig(options) {
|
|
|
111
160
|
var bundlerConfig = options.bundlerConfig, modernjsConfig = options.modernjsConfig, isServer = options.isServer, mfConfig = options.mfConfig;
|
|
112
161
|
var enableSSR = Boolean((_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
|
|
113
162
|
(_bundlerConfig_optimization = bundlerConfig.optimization) === null || _bundlerConfig_optimization === void 0 ? true : delete _bundlerConfig_optimization.runtimeChunk;
|
|
163
|
+
if (!isServer) {
|
|
164
|
+
autoDeleteSplitChunkCacheGroups(mfConfig, bundlerConfig);
|
|
165
|
+
}
|
|
114
166
|
if (!isServer && enableSSR && typeof ((_bundlerConfig_optimization1 = bundlerConfig.optimization) === null || _bundlerConfig_optimization1 === void 0 ? void 0 : _bundlerConfig_optimization1.splitChunks) === "object" && bundlerConfig.optimization.splitChunks.cacheGroups) {
|
|
115
167
|
bundlerConfig.optimization.splitChunks.chunks = "async";
|
|
116
168
|
console.warn('[Modern.js Module Federation] splitChunks.chunks = async is not allowed with stream SSR mode, it will auto changed to "async"');
|
|
@@ -139,9 +191,109 @@ function patchWebpackConfig(options) {
|
|
|
139
191
|
});
|
|
140
192
|
}
|
|
141
193
|
}
|
|
194
|
+
var lookupIpv4 = function() {
|
|
195
|
+
var _ref = _async_to_generator(function() {
|
|
196
|
+
var res, err;
|
|
197
|
+
return _ts_generator(this, function(_state) {
|
|
198
|
+
switch (_state.label) {
|
|
199
|
+
case 0:
|
|
200
|
+
_state.trys.push([
|
|
201
|
+
0,
|
|
202
|
+
2,
|
|
203
|
+
,
|
|
204
|
+
3
|
|
205
|
+
]);
|
|
206
|
+
return [
|
|
207
|
+
4,
|
|
208
|
+
dns.promises.lookup(LOCALHOST, {
|
|
209
|
+
family: 4
|
|
210
|
+
})
|
|
211
|
+
];
|
|
212
|
+
case 1:
|
|
213
|
+
res = _state.sent();
|
|
214
|
+
return [
|
|
215
|
+
2,
|
|
216
|
+
res.address
|
|
217
|
+
];
|
|
218
|
+
case 2:
|
|
219
|
+
err = _state.sent();
|
|
220
|
+
return [
|
|
221
|
+
2,
|
|
222
|
+
"127.0.0.1"
|
|
223
|
+
];
|
|
224
|
+
case 3:
|
|
225
|
+
return [
|
|
226
|
+
2
|
|
227
|
+
];
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
return function lookupIpv42() {
|
|
232
|
+
return _ref.apply(this, arguments);
|
|
233
|
+
};
|
|
234
|
+
}();
|
|
235
|
+
var SPLIT_CHUNK_MAP = {
|
|
236
|
+
REACT: "lib-react",
|
|
237
|
+
ROUTER: "lib-router",
|
|
238
|
+
LODASH: "lib-lodash",
|
|
239
|
+
ANTD: "lib-antd",
|
|
240
|
+
ARCO: "lib-arco",
|
|
241
|
+
SEMI: "lib-semi",
|
|
242
|
+
AXIOS: "lib-axios"
|
|
243
|
+
};
|
|
244
|
+
var SHARED_SPLIT_CHUNK_MAP = {
|
|
245
|
+
react: SPLIT_CHUNK_MAP.REACT,
|
|
246
|
+
"react-dom": SPLIT_CHUNK_MAP.REACT,
|
|
247
|
+
"react-router": SPLIT_CHUNK_MAP.ROUTER,
|
|
248
|
+
"react-router-dom": SPLIT_CHUNK_MAP.ROUTER,
|
|
249
|
+
"@remix-run/router": SPLIT_CHUNK_MAP.ROUTER,
|
|
250
|
+
lodash: SPLIT_CHUNK_MAP.LODASH,
|
|
251
|
+
"lodash-es": SPLIT_CHUNK_MAP.LODASH,
|
|
252
|
+
antd: SPLIT_CHUNK_MAP.ANTD,
|
|
253
|
+
"@arco-design/web-react": SPLIT_CHUNK_MAP.ARCO,
|
|
254
|
+
"@douyinfe/semi-ui": SPLIT_CHUNK_MAP.SEMI,
|
|
255
|
+
axios: SPLIT_CHUNK_MAP.AXIOS
|
|
256
|
+
};
|
|
257
|
+
function autoDeleteSplitChunkCacheGroups(mfConfig, bundlerConfig) {
|
|
258
|
+
var _bundlerConfig_optimization;
|
|
259
|
+
if (!mfConfig.shared) {
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
if (!((_bundlerConfig_optimization = bundlerConfig.optimization) === null || _bundlerConfig_optimization === void 0 ? void 0 : _bundlerConfig_optimization.splitChunks) || !bundlerConfig.optimization.splitChunks.cacheGroups) {
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
var arrayShared = Array.isArray(mfConfig.shared) ? mfConfig.shared : Object.keys(mfConfig.shared);
|
|
266
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
|
267
|
+
try {
|
|
268
|
+
for (var _iterator = arrayShared[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
269
|
+
var shared = _step.value;
|
|
270
|
+
var splitChunkKey = SHARED_SPLIT_CHUNK_MAP[shared];
|
|
271
|
+
if (!splitChunkKey) {
|
|
272
|
+
continue;
|
|
273
|
+
}
|
|
274
|
+
if (bundlerConfig.optimization.splitChunks.cacheGroups[splitChunkKey]) {
|
|
275
|
+
delete bundlerConfig.optimization.splitChunks.cacheGroups[splitChunkKey];
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
} catch (err) {
|
|
279
|
+
_didIteratorError = true;
|
|
280
|
+
_iteratorError = err;
|
|
281
|
+
} finally {
|
|
282
|
+
try {
|
|
283
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
284
|
+
_iterator.return();
|
|
285
|
+
}
|
|
286
|
+
} finally {
|
|
287
|
+
if (_didIteratorError) {
|
|
288
|
+
throw _iteratorError;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
142
293
|
export {
|
|
143
294
|
getMFConfig,
|
|
144
295
|
getTargetEnvConfig,
|
|
296
|
+
lookupIpv4,
|
|
145
297
|
patchMFConfig,
|
|
146
298
|
patchWebpackConfig
|
|
147
299
|
};
|
package/dist/esm/constant.js
CHANGED
|
@@ -0,0 +1,26 @@
|
|
|
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 LiveReload() {
|
|
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
|
+
LiveReload
|
|
26
|
+
};
|
|
@@ -54,7 +54,9 @@ function getTargetModuleInfo(id) {
|
|
|
54
54
|
};
|
|
55
55
|
}
|
|
56
56
|
function collectAssets(options) {
|
|
57
|
-
var
|
|
57
|
+
var _ref = typeof options === "string" ? {
|
|
58
|
+
id: options
|
|
59
|
+
} : 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;
|
|
58
60
|
var links = [];
|
|
59
61
|
var scripts = [];
|
|
60
62
|
var instance = getInstance();
|
|
@@ -92,7 +94,9 @@ function collectAssets(options) {
|
|
|
92
94
|
return _to_consumable_array(scripts).concat(_to_consumable_array(links));
|
|
93
95
|
}
|
|
94
96
|
function MFReactComponent(props) {
|
|
95
|
-
var
|
|
97
|
+
var _ref = typeof props === "string" ? {
|
|
98
|
+
id: props
|
|
99
|
+
} : props, _ref_loading = _ref.loading, loading = _ref_loading === void 0 ? "loading..." : _ref_loading, id = _ref.id, _ref_fallback = _ref.fallback, fallback = _ref_fallback === void 0 ? void 0 : _ref_fallback;
|
|
96
100
|
var Component = /* @__PURE__ */ React.lazy(function() {
|
|
97
101
|
return loadRemote(id).then(function(mod) {
|
|
98
102
|
var assets = collectAssets(props);
|