@module-federation/modern-js 0.11.2 → 0.11.4
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 +258 -11
- package/dist/cjs/cli/{utils.spec.js → configPlugin.spec.js} +3 -2
- package/dist/cjs/cli/index.js +1 -1
- package/dist/cjs/cli/manifest.js +13 -9
- package/dist/cjs/cli/ssrPlugin.js +58 -10
- package/dist/cjs/cli/utils.js +0 -235
- package/dist/cjs/constant.js +0 -3
- package/dist/esm/cli/configPlugin.js +278 -8
- package/dist/esm/cli/{utils.spec.js → configPlugin.spec.js} +2 -1
- package/dist/esm/cli/index.js +1 -1
- package/dist/esm/cli/manifest.js +13 -9
- package/dist/esm/cli/ssrPlugin.js +61 -11
- package/dist/esm/cli/utils.js +0 -260
- package/dist/esm/constant.js +0 -2
- package/dist/esm-node/cli/configPlugin.js +251 -8
- package/dist/esm-node/cli/{utils.spec.js → configPlugin.spec.js} +2 -1
- package/dist/esm-node/cli/index.js +1 -1
- package/dist/esm-node/cli/manifest.js +13 -9
- package/dist/esm-node/cli/ssrPlugin.js +58 -10
- package/dist/esm-node/cli/utils.js +0 -231
- package/dist/esm-node/constant.js +0 -2
- package/dist/types/cli/configPlugin.d.ts +16 -2
- package/dist/types/cli/manifest.d.ts +1 -1
- package/dist/types/cli/utils.d.ts +1 -14
- package/dist/types/constant.d.ts +0 -1
- package/dist/types/types/index.d.ts +3 -1
- package/package.json +8 -7
- /package/dist/types/cli/{utils.spec.d.ts → configPlugin.spec.d.ts} +0 -0
package/dist/cjs/cli/utils.js
CHANGED
|
@@ -28,243 +28,12 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
var utils_exports = {};
|
|
30
30
|
__export(utils_exports, {
|
|
31
|
-
addMyTypes2Ignored: () => addMyTypes2Ignored,
|
|
32
31
|
getIPV4: () => getIPV4,
|
|
33
|
-
getMFConfig: () => getMFConfig,
|
|
34
32
|
isWebTarget: () => isWebTarget,
|
|
35
|
-
patchBundlerConfig: () => patchBundlerConfig,
|
|
36
|
-
patchMFConfig: () => patchMFConfig,
|
|
37
33
|
skipByTarget: () => skipByTarget
|
|
38
34
|
});
|
|
39
35
|
module.exports = __toCommonJS(utils_exports);
|
|
40
36
|
var import_os = __toESM(require("os"));
|
|
41
|
-
var import_path = __toESM(require("path"));
|
|
42
|
-
var import_sdk = require("@module-federation/sdk");
|
|
43
|
-
var import_node_bundle_require = require("@modern-js/node-bundle-require");
|
|
44
|
-
var import_constant = require("../constant");
|
|
45
|
-
var import_logger = __toESM(require("./logger"));
|
|
46
|
-
var import_utils = require("@module-federation/rsbuild-plugin/utils");
|
|
47
|
-
const defaultPath = import_path.default.resolve(process.cwd(), "module-federation.config.ts");
|
|
48
|
-
const isDev = process.env.NODE_ENV === "development";
|
|
49
|
-
const getMFConfig = async (userConfig) => {
|
|
50
|
-
const { config, configPath } = userConfig;
|
|
51
|
-
if (config) {
|
|
52
|
-
return config;
|
|
53
|
-
}
|
|
54
|
-
const mfConfigPath = configPath ? configPath : defaultPath;
|
|
55
|
-
const preBundlePath = await (0, import_node_bundle_require.bundle)(mfConfigPath);
|
|
56
|
-
const mfConfig = (await Promise.resolve().then(() => __toESM(require(preBundlePath)))).default;
|
|
57
|
-
return mfConfig;
|
|
58
|
-
};
|
|
59
|
-
const injectRuntimePlugins = (runtimePlugin, runtimePlugins) => {
|
|
60
|
-
if (!runtimePlugins.includes(runtimePlugin)) {
|
|
61
|
-
runtimePlugins.push(runtimePlugin);
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
const replaceRemoteUrl = (mfConfig, remoteIpStrategy) => {
|
|
65
|
-
if (remoteIpStrategy && remoteIpStrategy === "inherit") {
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
if (!mfConfig.remotes) {
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
const ipv4 = getIPV4();
|
|
72
|
-
const handleRemoteObject = (remoteObject) => {
|
|
73
|
-
Object.keys(remoteObject).forEach((remoteKey) => {
|
|
74
|
-
const remote = remoteObject[remoteKey];
|
|
75
|
-
if (Array.isArray(remote)) {
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
if (typeof remote === "string" && remote.includes(import_constant.LOCALHOST)) {
|
|
79
|
-
remoteObject[remoteKey] = remote.replace(import_constant.LOCALHOST, ipv4);
|
|
80
|
-
}
|
|
81
|
-
if (typeof remote === "object" && !Array.isArray(remote.external) && remote.external.includes(import_constant.LOCALHOST)) {
|
|
82
|
-
remote.external = remote.external.replace(import_constant.LOCALHOST, ipv4);
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
};
|
|
86
|
-
if (Array.isArray(mfConfig.remotes)) {
|
|
87
|
-
mfConfig.remotes.forEach((remoteObject) => {
|
|
88
|
-
if (typeof remoteObject === "string") {
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
handleRemoteObject(remoteObject);
|
|
92
|
-
});
|
|
93
|
-
} else if (typeof mfConfig.remotes !== "string") {
|
|
94
|
-
handleRemoteObject(mfConfig.remotes);
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
const patchDTSConfig = (mfConfig, isServer) => {
|
|
98
|
-
if (isServer) {
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
const ModernJSRuntime = "@modern-js/runtime/mf";
|
|
102
|
-
if (mfConfig.dts !== false) {
|
|
103
|
-
var _mfConfig_dts, _mfConfig_dts1;
|
|
104
|
-
if (typeof mfConfig.dts === "boolean" || mfConfig.dts === void 0) {
|
|
105
|
-
mfConfig.dts = {
|
|
106
|
-
consumeTypes: {
|
|
107
|
-
runtimePkgs: [
|
|
108
|
-
ModernJSRuntime
|
|
109
|
-
]
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
} else if (((_mfConfig_dts = mfConfig.dts) === null || _mfConfig_dts === void 0 ? void 0 : _mfConfig_dts.consumeTypes) || ((_mfConfig_dts1 = mfConfig.dts) === null || _mfConfig_dts1 === void 0 ? void 0 : _mfConfig_dts1.consumeTypes) === void 0) {
|
|
113
|
-
var _mfConfig_dts2;
|
|
114
|
-
if (typeof mfConfig.dts.consumeTypes === "boolean" || ((_mfConfig_dts2 = mfConfig.dts) === null || _mfConfig_dts2 === void 0 ? void 0 : _mfConfig_dts2.consumeTypes) === void 0) {
|
|
115
|
-
mfConfig.dts.consumeTypes = {
|
|
116
|
-
runtimePkgs: [
|
|
117
|
-
ModernJSRuntime
|
|
118
|
-
]
|
|
119
|
-
};
|
|
120
|
-
} else {
|
|
121
|
-
mfConfig.dts.consumeTypes.runtimePkgs = mfConfig.dts.consumeTypes.runtimePkgs || [];
|
|
122
|
-
if (!mfConfig.dts.consumeTypes.runtimePkgs.includes(ModernJSRuntime)) {
|
|
123
|
-
mfConfig.dts.consumeTypes.runtimePkgs.push(ModernJSRuntime);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
};
|
|
129
|
-
const patchMFConfig = (mfConfig, isServer, remoteIpStrategy) => {
|
|
130
|
-
replaceRemoteUrl(mfConfig, remoteIpStrategy);
|
|
131
|
-
if (mfConfig.remoteType === void 0) {
|
|
132
|
-
mfConfig.remoteType = "script";
|
|
133
|
-
}
|
|
134
|
-
if (!mfConfig.name) {
|
|
135
|
-
throw new Error(`${import_constant.PLUGIN_IDENTIFIER} mfConfig.name can not be empty!`);
|
|
136
|
-
}
|
|
137
|
-
const runtimePlugins = [
|
|
138
|
-
...mfConfig.runtimePlugins || []
|
|
139
|
-
];
|
|
140
|
-
patchDTSConfig(mfConfig, isServer);
|
|
141
|
-
injectRuntimePlugins(require.resolve("@module-federation/modern-js/shared-strategy"), runtimePlugins);
|
|
142
|
-
if (isDev) {
|
|
143
|
-
injectRuntimePlugins(require.resolve("@module-federation/modern-js/resolve-entry-ipv4"), runtimePlugins);
|
|
144
|
-
}
|
|
145
|
-
if (isServer) {
|
|
146
|
-
injectRuntimePlugins(require.resolve("@module-federation/node/runtimePlugin"), runtimePlugins);
|
|
147
|
-
if (isDev) {
|
|
148
|
-
injectRuntimePlugins(require.resolve("@module-federation/node/record-dynamic-remote-entry-hash-plugin"), runtimePlugins);
|
|
149
|
-
}
|
|
150
|
-
injectRuntimePlugins(require.resolve("@module-federation/modern-js/inject-node-fetch"), runtimePlugins);
|
|
151
|
-
if (!mfConfig.library) {
|
|
152
|
-
mfConfig.library = {
|
|
153
|
-
type: "commonjs-module",
|
|
154
|
-
name: mfConfig.name
|
|
155
|
-
};
|
|
156
|
-
} else {
|
|
157
|
-
if (!mfConfig.library.type) {
|
|
158
|
-
mfConfig.library.type = "commonjs-module";
|
|
159
|
-
}
|
|
160
|
-
if (!mfConfig.library.name) {
|
|
161
|
-
mfConfig.library.name = mfConfig.name;
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
mfConfig.runtimePlugins = runtimePlugins;
|
|
166
|
-
if (!isServer) {
|
|
167
|
-
var _mfConfig_library;
|
|
168
|
-
if (((_mfConfig_library = mfConfig.library) === null || _mfConfig_library === void 0 ? void 0 : _mfConfig_library.type) === "commonjs-module") {
|
|
169
|
-
mfConfig.library.type = "global";
|
|
170
|
-
}
|
|
171
|
-
return mfConfig;
|
|
172
|
-
}
|
|
173
|
-
mfConfig.dts = false;
|
|
174
|
-
mfConfig.dev = false;
|
|
175
|
-
return mfConfig;
|
|
176
|
-
};
|
|
177
|
-
function patchIgnoreWarning(chain) {
|
|
178
|
-
const ignoreWarnings = chain.get("ignoreWarnings") || [];
|
|
179
|
-
const ignoredMsgs = [
|
|
180
|
-
"external script",
|
|
181
|
-
"process.env.WS_NO_BUFFER_UTIL",
|
|
182
|
-
`Can't resolve 'utf-8-validate`
|
|
183
|
-
];
|
|
184
|
-
ignoreWarnings.push((warning) => {
|
|
185
|
-
if (ignoredMsgs.some((msg) => warning.message.includes(msg))) {
|
|
186
|
-
return true;
|
|
187
|
-
}
|
|
188
|
-
return false;
|
|
189
|
-
});
|
|
190
|
-
chain.ignoreWarnings(ignoreWarnings);
|
|
191
|
-
}
|
|
192
|
-
function addMyTypes2Ignored(chain, mfConfig) {
|
|
193
|
-
const watchOptions = chain.get("watchOptions");
|
|
194
|
-
if (!watchOptions || !watchOptions.ignored) {
|
|
195
|
-
chain.watchOptions({
|
|
196
|
-
ignored: /[\\/](?:\.git|node_modules|@mf-types)[\\/]/
|
|
197
|
-
});
|
|
198
|
-
return;
|
|
199
|
-
}
|
|
200
|
-
const ignored = watchOptions.ignored;
|
|
201
|
-
const DEFAULT_IGNORED_GLOB = "**/@mf-types/**";
|
|
202
|
-
if (Array.isArray(ignored)) {
|
|
203
|
-
if (mfConfig.dts !== false && typeof mfConfig.dts === "object" && typeof mfConfig.dts.consumeTypes === "object" && mfConfig.dts.consumeTypes.remoteTypesFolder) {
|
|
204
|
-
chain.watchOptions({
|
|
205
|
-
...watchOptions,
|
|
206
|
-
ignored: ignored.concat(`**/${mfConfig.dts.consumeTypes.remoteTypesFolder}/**`)
|
|
207
|
-
});
|
|
208
|
-
} else {
|
|
209
|
-
chain.watchOptions({
|
|
210
|
-
...watchOptions,
|
|
211
|
-
ignored: ignored.concat(DEFAULT_IGNORED_GLOB)
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
return;
|
|
215
|
-
}
|
|
216
|
-
if (typeof ignored !== "string") {
|
|
217
|
-
chain.watchOptions({
|
|
218
|
-
...watchOptions,
|
|
219
|
-
ignored: /[\\/](?:\.git|node_modules|@mf-types)[\\/]/
|
|
220
|
-
});
|
|
221
|
-
return;
|
|
222
|
-
}
|
|
223
|
-
chain.watchOptions({
|
|
224
|
-
...watchOptions,
|
|
225
|
-
ignored: ignored.concat(DEFAULT_IGNORED_GLOB)
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
function patchBundlerConfig(options) {
|
|
229
|
-
var _modernjsConfig_deploy;
|
|
230
|
-
const { chain, modernjsConfig, isServer, mfConfig, enableSSR } = options;
|
|
231
|
-
chain.optimization.delete("runtimeChunk");
|
|
232
|
-
patchIgnoreWarning(chain);
|
|
233
|
-
if (!chain.output.get("chunkLoadingGlobal")) {
|
|
234
|
-
chain.output.chunkLoadingGlobal(`chunk_${mfConfig.name}`);
|
|
235
|
-
}
|
|
236
|
-
if (!chain.output.get("uniqueName")) {
|
|
237
|
-
chain.output.uniqueName(mfConfig.name);
|
|
238
|
-
}
|
|
239
|
-
const splitChunkConfig = chain.optimization.splitChunks.entries();
|
|
240
|
-
if (!isServer) {
|
|
241
|
-
(0, import_utils.autoDeleteSplitChunkCacheGroups)(mfConfig, splitChunkConfig);
|
|
242
|
-
}
|
|
243
|
-
if (!isServer && enableSSR && splitChunkConfig && typeof splitChunkConfig === "object" && splitChunkConfig.cacheGroups) {
|
|
244
|
-
splitChunkConfig.chunks = "async";
|
|
245
|
-
import_logger.default.warn(`splitChunks.chunks = async is not allowed with stream SSR mode, it will auto changed to "async"`);
|
|
246
|
-
}
|
|
247
|
-
if (isDev && chain.output.get("publicPath") === "auto") {
|
|
248
|
-
var _modernjsConfig_dev, _modernjsConfig_server;
|
|
249
|
-
const port = ((_modernjsConfig_dev = modernjsConfig.dev) === null || _modernjsConfig_dev === void 0 ? void 0 : _modernjsConfig_dev.port) || ((_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.port) || 8080;
|
|
250
|
-
const publicPath = `http://localhost:${port}/`;
|
|
251
|
-
chain.output.publicPath(publicPath);
|
|
252
|
-
}
|
|
253
|
-
if (isServer && enableSSR) {
|
|
254
|
-
const uniqueName = mfConfig.name || chain.output.get("uniqueName");
|
|
255
|
-
const chunkFileName = chain.output.get("chunkFilename");
|
|
256
|
-
if (typeof chunkFileName === "string" && uniqueName && !chunkFileName.includes(uniqueName)) {
|
|
257
|
-
const suffix = `${(0, import_sdk.encodeName)(uniqueName)}-[chunkhash].js`;
|
|
258
|
-
chain.output.chunkFilename(chunkFileName.replace(".js", suffix));
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
if (isDev && enableSSR && !isServer) {
|
|
262
|
-
chain.resolve.fallback.set("crypto", false).set("stream", false).set("vm", false);
|
|
263
|
-
}
|
|
264
|
-
if (((_modernjsConfig_deploy = modernjsConfig.deploy) === null || _modernjsConfig_deploy === void 0 ? void 0 : _modernjsConfig_deploy.microFrontend) && Object.keys(mfConfig.exposes || {}).length) {
|
|
265
|
-
chain.optimization.usedExports(false);
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
37
|
const localIpv4 = "127.0.0.1";
|
|
269
38
|
const getIpv4Interfaces = () => {
|
|
270
39
|
try {
|
|
@@ -310,11 +79,7 @@ const skipByTarget = (target) => {
|
|
|
310
79
|
};
|
|
311
80
|
// Annotate the CommonJS export names for ESM import in node:
|
|
312
81
|
0 && (module.exports = {
|
|
313
|
-
addMyTypes2Ignored,
|
|
314
82
|
getIPV4,
|
|
315
|
-
getMFConfig,
|
|
316
83
|
isWebTarget,
|
|
317
|
-
patchBundlerConfig,
|
|
318
|
-
patchMFConfig,
|
|
319
84
|
skipByTarget
|
|
320
85
|
});
|
package/dist/cjs/constant.js
CHANGED
|
@@ -19,16 +19,13 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
var constant_exports = {};
|
|
20
20
|
__export(constant_exports, {
|
|
21
21
|
LOCALHOST: () => LOCALHOST,
|
|
22
|
-
MODERN_JS_SERVER_DIR: () => MODERN_JS_SERVER_DIR,
|
|
23
22
|
PLUGIN_IDENTIFIER: () => PLUGIN_IDENTIFIER
|
|
24
23
|
});
|
|
25
24
|
module.exports = __toCommonJS(constant_exports);
|
|
26
|
-
const MODERN_JS_SERVER_DIR = "bundles";
|
|
27
25
|
const LOCALHOST = "localhost";
|
|
28
26
|
const PLUGIN_IDENTIFIER = "[ Modern.js Module Federation ]";
|
|
29
27
|
// Annotate the CommonJS export names for ESM import in node:
|
|
30
28
|
0 && (module.exports = {
|
|
31
29
|
LOCALHOST,
|
|
32
|
-
MODERN_JS_SERVER_DIR,
|
|
33
30
|
PLUGIN_IDENTIFIER
|
|
34
31
|
});
|
|
@@ -1,13 +1,266 @@
|
|
|
1
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 _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
5
|
+
import { _ as _type_of } from "@swc/helpers/_/_type_of";
|
|
2
6
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
3
7
|
import path from "path";
|
|
4
|
-
import {
|
|
8
|
+
import { getIPV4, isWebTarget, skipByTarget } from "./utils";
|
|
9
|
+
import { encodeName } from "@module-federation/sdk";
|
|
10
|
+
import { bundle } from "@modern-js/node-bundle-require";
|
|
11
|
+
import { LOCALHOST, PLUGIN_IDENTIFIER } from "../constant";
|
|
12
|
+
import { autoDeleteSplitChunkCacheGroups } from "@module-federation/rsbuild-plugin/utils";
|
|
13
|
+
import logger from "./logger";
|
|
14
|
+
var defaultPath = path.resolve(process.cwd(), "module-federation.config.ts");
|
|
15
|
+
var isDev = process.env.NODE_ENV === "development";
|
|
5
16
|
function setEnv(enableSSR) {
|
|
6
17
|
if (enableSSR) {
|
|
7
18
|
process.env["MF_DISABLE_EMIT_STATS"] = "true";
|
|
8
19
|
process.env["MF_SSR_PRJ"] = "true";
|
|
9
20
|
}
|
|
10
21
|
}
|
|
22
|
+
var getMFConfig = function() {
|
|
23
|
+
var _ref = _async_to_generator(function(userConfig) {
|
|
24
|
+
var config, configPath, mfConfigPath, preBundlePath, mfConfig;
|
|
25
|
+
return _ts_generator(this, function(_state) {
|
|
26
|
+
switch (_state.label) {
|
|
27
|
+
case 0:
|
|
28
|
+
config = userConfig.config, configPath = userConfig.configPath;
|
|
29
|
+
if (config) {
|
|
30
|
+
return [
|
|
31
|
+
2,
|
|
32
|
+
config
|
|
33
|
+
];
|
|
34
|
+
}
|
|
35
|
+
mfConfigPath = configPath ? configPath : defaultPath;
|
|
36
|
+
return [
|
|
37
|
+
4,
|
|
38
|
+
bundle(mfConfigPath)
|
|
39
|
+
];
|
|
40
|
+
case 1:
|
|
41
|
+
preBundlePath = _state.sent();
|
|
42
|
+
return [
|
|
43
|
+
4,
|
|
44
|
+
import(preBundlePath)
|
|
45
|
+
];
|
|
46
|
+
case 2:
|
|
47
|
+
mfConfig = _state.sent().default;
|
|
48
|
+
return [
|
|
49
|
+
2,
|
|
50
|
+
mfConfig
|
|
51
|
+
];
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
return function getMFConfig2(userConfig) {
|
|
56
|
+
return _ref.apply(this, arguments);
|
|
57
|
+
};
|
|
58
|
+
}();
|
|
59
|
+
var injectRuntimePlugins = function(runtimePlugin, runtimePlugins) {
|
|
60
|
+
if (!runtimePlugins.includes(runtimePlugin)) {
|
|
61
|
+
runtimePlugins.push(runtimePlugin);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
var replaceRemoteUrl = function(mfConfig, remoteIpStrategy) {
|
|
65
|
+
if (remoteIpStrategy && remoteIpStrategy === "inherit") {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (!mfConfig.remotes) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
var ipv4 = getIPV4();
|
|
72
|
+
var handleRemoteObject = function(remoteObject) {
|
|
73
|
+
Object.keys(remoteObject).forEach(function(remoteKey) {
|
|
74
|
+
var remote = remoteObject[remoteKey];
|
|
75
|
+
if (Array.isArray(remote)) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if (typeof remote === "string" && remote.includes(LOCALHOST)) {
|
|
79
|
+
remoteObject[remoteKey] = remote.replace(LOCALHOST, ipv4);
|
|
80
|
+
}
|
|
81
|
+
if ((typeof remote === "undefined" ? "undefined" : _type_of(remote)) === "object" && !Array.isArray(remote.external) && remote.external.includes(LOCALHOST)) {
|
|
82
|
+
remote.external = remote.external.replace(LOCALHOST, ipv4);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
if (Array.isArray(mfConfig.remotes)) {
|
|
87
|
+
mfConfig.remotes.forEach(function(remoteObject) {
|
|
88
|
+
if (typeof remoteObject === "string") {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
handleRemoteObject(remoteObject);
|
|
92
|
+
});
|
|
93
|
+
} else if (typeof mfConfig.remotes !== "string") {
|
|
94
|
+
handleRemoteObject(mfConfig.remotes);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
var patchDTSConfig = function(mfConfig, isServer) {
|
|
98
|
+
if (isServer) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
var ModernJSRuntime = "@modern-js/runtime/mf";
|
|
102
|
+
if (mfConfig.dts !== false) {
|
|
103
|
+
var _mfConfig_dts, _mfConfig_dts1;
|
|
104
|
+
if (typeof mfConfig.dts === "boolean" || mfConfig.dts === void 0) {
|
|
105
|
+
mfConfig.dts = {
|
|
106
|
+
consumeTypes: {
|
|
107
|
+
runtimePkgs: [
|
|
108
|
+
ModernJSRuntime
|
|
109
|
+
]
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
} else if (((_mfConfig_dts = mfConfig.dts) === null || _mfConfig_dts === void 0 ? void 0 : _mfConfig_dts.consumeTypes) || ((_mfConfig_dts1 = mfConfig.dts) === null || _mfConfig_dts1 === void 0 ? void 0 : _mfConfig_dts1.consumeTypes) === void 0) {
|
|
113
|
+
var _mfConfig_dts2;
|
|
114
|
+
if (typeof mfConfig.dts.consumeTypes === "boolean" || ((_mfConfig_dts2 = mfConfig.dts) === null || _mfConfig_dts2 === void 0 ? void 0 : _mfConfig_dts2.consumeTypes) === void 0) {
|
|
115
|
+
mfConfig.dts.consumeTypes = {
|
|
116
|
+
runtimePkgs: [
|
|
117
|
+
ModernJSRuntime
|
|
118
|
+
]
|
|
119
|
+
};
|
|
120
|
+
} else {
|
|
121
|
+
mfConfig.dts.consumeTypes.runtimePkgs = mfConfig.dts.consumeTypes.runtimePkgs || [];
|
|
122
|
+
if (!mfConfig.dts.consumeTypes.runtimePkgs.includes(ModernJSRuntime)) {
|
|
123
|
+
mfConfig.dts.consumeTypes.runtimePkgs.push(ModernJSRuntime);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
var patchMFConfig = function(mfConfig, isServer, remoteIpStrategy) {
|
|
130
|
+
replaceRemoteUrl(mfConfig, remoteIpStrategy);
|
|
131
|
+
if (mfConfig.remoteType === void 0) {
|
|
132
|
+
mfConfig.remoteType = "script";
|
|
133
|
+
}
|
|
134
|
+
if (!mfConfig.name) {
|
|
135
|
+
throw new Error("".concat(PLUGIN_IDENTIFIER, " mfConfig.name can not be empty!"));
|
|
136
|
+
}
|
|
137
|
+
var runtimePlugins = _to_consumable_array(mfConfig.runtimePlugins || []);
|
|
138
|
+
patchDTSConfig(mfConfig, isServer);
|
|
139
|
+
injectRuntimePlugins(require.resolve("@module-federation/modern-js/shared-strategy"), runtimePlugins);
|
|
140
|
+
if (isDev) {
|
|
141
|
+
injectRuntimePlugins(require.resolve("@module-federation/modern-js/resolve-entry-ipv4"), runtimePlugins);
|
|
142
|
+
}
|
|
143
|
+
if (isServer) {
|
|
144
|
+
injectRuntimePlugins(require.resolve("@module-federation/node/runtimePlugin"), runtimePlugins);
|
|
145
|
+
if (isDev) {
|
|
146
|
+
injectRuntimePlugins(require.resolve("@module-federation/node/record-dynamic-remote-entry-hash-plugin"), runtimePlugins);
|
|
147
|
+
}
|
|
148
|
+
injectRuntimePlugins(require.resolve("@module-federation/modern-js/inject-node-fetch"), runtimePlugins);
|
|
149
|
+
if (!mfConfig.library) {
|
|
150
|
+
mfConfig.library = {
|
|
151
|
+
type: "commonjs-module",
|
|
152
|
+
name: mfConfig.name
|
|
153
|
+
};
|
|
154
|
+
} else {
|
|
155
|
+
if (!mfConfig.library.type) {
|
|
156
|
+
mfConfig.library.type = "commonjs-module";
|
|
157
|
+
}
|
|
158
|
+
if (!mfConfig.library.name) {
|
|
159
|
+
mfConfig.library.name = mfConfig.name;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
mfConfig.runtimePlugins = runtimePlugins;
|
|
164
|
+
if (!isServer) {
|
|
165
|
+
var _mfConfig_library;
|
|
166
|
+
if (((_mfConfig_library = mfConfig.library) === null || _mfConfig_library === void 0 ? void 0 : _mfConfig_library.type) === "commonjs-module") {
|
|
167
|
+
mfConfig.library.type = "global";
|
|
168
|
+
}
|
|
169
|
+
return mfConfig;
|
|
170
|
+
}
|
|
171
|
+
mfConfig.dts = false;
|
|
172
|
+
mfConfig.dev = false;
|
|
173
|
+
return mfConfig;
|
|
174
|
+
};
|
|
175
|
+
function patchIgnoreWarning(chain) {
|
|
176
|
+
var ignoreWarnings = chain.get("ignoreWarnings") || [];
|
|
177
|
+
var ignoredMsgs = [
|
|
178
|
+
"external script",
|
|
179
|
+
"process.env.WS_NO_BUFFER_UTIL",
|
|
180
|
+
"Can't resolve 'utf-8-validate"
|
|
181
|
+
];
|
|
182
|
+
ignoreWarnings.push(function(warning) {
|
|
183
|
+
if (ignoredMsgs.some(function(msg) {
|
|
184
|
+
return warning.message.includes(msg);
|
|
185
|
+
})) {
|
|
186
|
+
return true;
|
|
187
|
+
}
|
|
188
|
+
return false;
|
|
189
|
+
});
|
|
190
|
+
chain.ignoreWarnings(ignoreWarnings);
|
|
191
|
+
}
|
|
192
|
+
function addMyTypes2Ignored(chain, mfConfig) {
|
|
193
|
+
var watchOptions = chain.get("watchOptions");
|
|
194
|
+
if (!watchOptions || !watchOptions.ignored) {
|
|
195
|
+
chain.watchOptions({
|
|
196
|
+
ignored: /[\\/](?:\.git|node_modules|@mf-types)[\\/]/
|
|
197
|
+
});
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
var ignored = watchOptions.ignored;
|
|
201
|
+
var DEFAULT_IGNORED_GLOB = "**/@mf-types/**";
|
|
202
|
+
if (Array.isArray(ignored)) {
|
|
203
|
+
if (mfConfig.dts !== false && _type_of(mfConfig.dts) === "object" && _type_of(mfConfig.dts.consumeTypes) === "object" && mfConfig.dts.consumeTypes.remoteTypesFolder) {
|
|
204
|
+
chain.watchOptions(_object_spread_props(_object_spread({}, watchOptions), {
|
|
205
|
+
ignored: ignored.concat("**/".concat(mfConfig.dts.consumeTypes.remoteTypesFolder, "/**"))
|
|
206
|
+
}));
|
|
207
|
+
} else {
|
|
208
|
+
chain.watchOptions(_object_spread_props(_object_spread({}, watchOptions), {
|
|
209
|
+
ignored: ignored.concat(DEFAULT_IGNORED_GLOB)
|
|
210
|
+
}));
|
|
211
|
+
}
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
if (typeof ignored !== "string") {
|
|
215
|
+
chain.watchOptions(_object_spread_props(_object_spread({}, watchOptions), {
|
|
216
|
+
ignored: /[\\/](?:\.git|node_modules|@mf-types)[\\/]/
|
|
217
|
+
}));
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
chain.watchOptions(_object_spread_props(_object_spread({}, watchOptions), {
|
|
221
|
+
ignored: ignored.concat(DEFAULT_IGNORED_GLOB)
|
|
222
|
+
}));
|
|
223
|
+
}
|
|
224
|
+
function patchBundlerConfig(options) {
|
|
225
|
+
var _modernjsConfig_deploy;
|
|
226
|
+
var chain = options.chain, modernjsConfig = options.modernjsConfig, isServer = options.isServer, mfConfig = options.mfConfig, enableSSR = options.enableSSR;
|
|
227
|
+
chain.optimization.delete("runtimeChunk");
|
|
228
|
+
patchIgnoreWarning(chain);
|
|
229
|
+
if (!chain.output.get("chunkLoadingGlobal")) {
|
|
230
|
+
chain.output.chunkLoadingGlobal("chunk_".concat(mfConfig.name));
|
|
231
|
+
}
|
|
232
|
+
if (!chain.output.get("uniqueName")) {
|
|
233
|
+
chain.output.uniqueName(mfConfig.name);
|
|
234
|
+
}
|
|
235
|
+
var splitChunkConfig = chain.optimization.splitChunks.entries();
|
|
236
|
+
if (!isServer) {
|
|
237
|
+
autoDeleteSplitChunkCacheGroups(mfConfig, splitChunkConfig);
|
|
238
|
+
}
|
|
239
|
+
if (!isServer && enableSSR && splitChunkConfig && (typeof splitChunkConfig === "undefined" ? "undefined" : _type_of(splitChunkConfig)) === "object" && splitChunkConfig.cacheGroups) {
|
|
240
|
+
splitChunkConfig.chunks = "async";
|
|
241
|
+
logger.warn('splitChunks.chunks = async is not allowed with stream SSR mode, it will auto changed to "async"');
|
|
242
|
+
}
|
|
243
|
+
if (isDev && chain.output.get("publicPath") === "auto") {
|
|
244
|
+
var _modernjsConfig_dev, _modernjsConfig_server;
|
|
245
|
+
var port = ((_modernjsConfig_dev = modernjsConfig.dev) === null || _modernjsConfig_dev === void 0 ? void 0 : _modernjsConfig_dev.port) || ((_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.port) || 8080;
|
|
246
|
+
var publicPath = "http://localhost:".concat(port, "/");
|
|
247
|
+
chain.output.publicPath(publicPath);
|
|
248
|
+
}
|
|
249
|
+
if (isServer && enableSSR) {
|
|
250
|
+
var uniqueName = mfConfig.name || chain.output.get("uniqueName");
|
|
251
|
+
var chunkFileName = chain.output.get("chunkFilename");
|
|
252
|
+
if (typeof chunkFileName === "string" && uniqueName && !chunkFileName.includes(uniqueName)) {
|
|
253
|
+
var suffix = "".concat(encodeName(uniqueName), "-[chunkhash].js");
|
|
254
|
+
chain.output.chunkFilename(chunkFileName.replace(".js", suffix));
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
if (isDev && enableSSR && !isServer) {
|
|
258
|
+
chain.resolve.fallback.set("crypto", false).set("stream", false).set("vm", false);
|
|
259
|
+
}
|
|
260
|
+
if (((_modernjsConfig_deploy = modernjsConfig.deploy) === null || _modernjsConfig_deploy === void 0 ? void 0 : _modernjsConfig_deploy.microFrontend) && Object.keys(mfConfig.exposes || {}).length) {
|
|
261
|
+
chain.optimization.usedExports(false);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
11
264
|
var moduleFederationConfigPlugin = function(userConfig) {
|
|
12
265
|
return {
|
|
13
266
|
name: "@modern-js/plugin-module-federation-config",
|
|
@@ -34,7 +287,7 @@ var moduleFederationConfigPlugin = function(userConfig) {
|
|
|
34
287
|
ssrConfig = userConfig.ssrConfig || JSON.parse(JSON.stringify(mfConfig));
|
|
35
288
|
userConfig.ssrConfig = ssrConfig;
|
|
36
289
|
userConfig.csrConfig = csrConfig;
|
|
37
|
-
enableSSR = (_userConfig_userConfig_ssr = (_userConfig_userConfig = userConfig.userConfig) === null || _userConfig_userConfig === void 0 ? void 0 : _userConfig_userConfig.ssr) !== null && _userConfig_userConfig_ssr !== void 0 ? _userConfig_userConfig_ssr : Boolean(modernjsConfig === null || modernjsConfig === void 0 ? void 0 : (_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
|
|
290
|
+
enableSSR = Boolean((_userConfig_userConfig_ssr = (_userConfig_userConfig = userConfig.userConfig) === null || _userConfig_userConfig === void 0 ? void 0 : _userConfig_userConfig.ssr) !== null && _userConfig_userConfig_ssr !== void 0 ? _userConfig_userConfig_ssr : Boolean(modernjsConfig === null || modernjsConfig === void 0 ? void 0 : (_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr));
|
|
38
291
|
api.modifyBundlerChain(function(chain) {
|
|
39
292
|
var target = chain.get("target");
|
|
40
293
|
if (skipByTarget(target)) {
|
|
@@ -55,7 +308,7 @@ var moduleFederationConfigPlugin = function(userConfig) {
|
|
|
55
308
|
userConfig.distOutputDir = chain.output.get("path") || path.resolve(process.cwd(), "dist");
|
|
56
309
|
});
|
|
57
310
|
api.config(function() {
|
|
58
|
-
var _modernjsConfig_source, _modernjsConfig_source1, _modernjsConfig_dev;
|
|
311
|
+
var _modernjsConfig_tools, _userConfig_csrConfig, _modernjsConfig_source, _modernjsConfig_source1, _modernjsConfig_dev;
|
|
59
312
|
var bundlerType = api.getAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
|
|
60
313
|
var ipv4 = getIPV4();
|
|
61
314
|
if (userConfig.remoteIpStrategy === void 0) {
|
|
@@ -65,15 +318,28 @@ var moduleFederationConfigPlugin = function(userConfig) {
|
|
|
65
318
|
userConfig.remoteIpStrategy = "ipv4";
|
|
66
319
|
}
|
|
67
320
|
}
|
|
321
|
+
var devServerConfig = (_modernjsConfig_tools = modernjsConfig.tools) === null || _modernjsConfig_tools === void 0 ? void 0 : _modernjsConfig_tools.devServer;
|
|
322
|
+
var corsWarnMsgs = [
|
|
323
|
+
"View https://module-federation.io/guide/troubleshooting/other.html#cors-warn for more details."
|
|
324
|
+
];
|
|
325
|
+
if ((typeof devServerConfig === "undefined" ? "undefined" : _type_of(devServerConfig)) !== "object" || !("headers" in devServerConfig)) {
|
|
326
|
+
corsWarnMsgs.unshift('Detect devServer.headers is empty, mf modern plugin will add default cors header: devServer.headers["Access-Control-Allow-Headers"] = "*". It is recommended to specify an allowlist of trusted origins instead.');
|
|
327
|
+
}
|
|
328
|
+
var exposes = (_userConfig_csrConfig = userConfig.csrConfig) === null || _userConfig_csrConfig === void 0 ? void 0 : _userConfig_csrConfig.exposes;
|
|
329
|
+
var hasExposes = exposes && Array.isArray(exposes) ? exposes.length : Object.keys(exposes !== null && exposes !== void 0 ? exposes : {}).length;
|
|
330
|
+
if (corsWarnMsgs.length > 1 && hasExposes) {
|
|
331
|
+
logger.warn(corsWarnMsgs.join("\n"));
|
|
332
|
+
}
|
|
333
|
+
var corsHeaders = hasExposes ? {
|
|
334
|
+
"Access-Control-Allow-Origin": "*",
|
|
335
|
+
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, PATCH, OPTIONS",
|
|
336
|
+
"Access-Control-Allow-Headers": "*"
|
|
337
|
+
} : void 0;
|
|
68
338
|
var _modernjsConfig_source_enableAsyncEntry;
|
|
69
339
|
return {
|
|
70
340
|
tools: {
|
|
71
341
|
devServer: {
|
|
72
|
-
headers:
|
|
73
|
-
"Access-Control-Allow-Origin": "*",
|
|
74
|
-
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, PATCH, OPTIONS",
|
|
75
|
-
"Access-Control-Allow-Headers": "*"
|
|
76
|
-
}
|
|
342
|
+
headers: corsHeaders
|
|
77
343
|
}
|
|
78
344
|
},
|
|
79
345
|
source: {
|
|
@@ -105,9 +371,13 @@ var moduleFederationConfigPlugin = function(userConfig) {
|
|
|
105
371
|
};
|
|
106
372
|
var configPlugin_default = moduleFederationConfigPlugin;
|
|
107
373
|
export {
|
|
374
|
+
addMyTypes2Ignored,
|
|
108
375
|
configPlugin_default as default,
|
|
376
|
+
getMFConfig,
|
|
109
377
|
isWebTarget,
|
|
110
378
|
moduleFederationConfigPlugin,
|
|
379
|
+
patchBundlerConfig,
|
|
380
|
+
patchMFConfig,
|
|
111
381
|
setEnv,
|
|
112
382
|
skipByTarget
|
|
113
383
|
};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
2
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
3
3
|
import { it, expect, describe } from "vitest";
|
|
4
|
-
import { patchMFConfig
|
|
4
|
+
import { patchMFConfig } from "./configPlugin";
|
|
5
|
+
import { getIPV4 } from "./utils";
|
|
5
6
|
var mfConfig = {
|
|
6
7
|
name: "host",
|
|
7
8
|
filename: "remoteEntry.js",
|
package/dist/esm/cli/index.js
CHANGED
|
@@ -16,7 +16,7 @@ var moduleFederationPlugin = function() {
|
|
|
16
16
|
distOutputDir: "",
|
|
17
17
|
originPluginOptions: userConfig,
|
|
18
18
|
remoteIpStrategy: userConfig === null || userConfig === void 0 ? void 0 : userConfig.remoteIpStrategy,
|
|
19
|
-
userConfig
|
|
19
|
+
userConfig: userConfig || {}
|
|
20
20
|
};
|
|
21
21
|
return {
|
|
22
22
|
name: "@modern-js/plugin-module-federation",
|
package/dist/esm/cli/manifest.js
CHANGED
|
@@ -1,25 +1,29 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import { fs } from "@modern-js/utils";
|
|
3
|
-
function mergeStats(browserStats, nodeStats
|
|
3
|
+
function mergeStats(browserStats, nodeStats) {
|
|
4
4
|
var ssrRemoteEntry = nodeStats.metaData.remoteEntry;
|
|
5
|
-
ssrRemoteEntry.path = ssrDir;
|
|
6
5
|
browserStats.metaData.ssrRemoteEntry = ssrRemoteEntry;
|
|
6
|
+
if ("publicPath" in browserStats.metaData) {
|
|
7
|
+
browserStats.metaData.ssrPublicPath = nodeStats.metaData.publicPath;
|
|
8
|
+
}
|
|
7
9
|
return browserStats;
|
|
8
10
|
}
|
|
9
|
-
function mergeManifest(browserManifest, nodeManifest
|
|
11
|
+
function mergeManifest(browserManifest, nodeManifest) {
|
|
10
12
|
var ssrRemoteEntry = nodeManifest.metaData.remoteEntry;
|
|
11
|
-
ssrRemoteEntry.path = ssrDir;
|
|
12
13
|
browserManifest.metaData.ssrRemoteEntry = ssrRemoteEntry;
|
|
14
|
+
if ("publicPath" in browserManifest.metaData) {
|
|
15
|
+
browserManifest.metaData.ssrPublicPath = nodeManifest.metaData.publicPath;
|
|
16
|
+
}
|
|
13
17
|
return browserManifest;
|
|
14
18
|
}
|
|
15
|
-
function mergeStatsAndManifest(nodePlugin, browserPlugin
|
|
19
|
+
function mergeStatsAndManifest(nodePlugin, browserPlugin) {
|
|
16
20
|
var nodeResourceInfo = nodePlugin.statsResourceInfo;
|
|
17
21
|
var browserResourceInfo = browserPlugin.statsResourceInfo;
|
|
18
22
|
if (!browserResourceInfo || !nodeResourceInfo || !browserResourceInfo.stats || !nodeResourceInfo.stats || !browserResourceInfo.manifest || !nodeResourceInfo.manifest) {
|
|
19
23
|
throw new Error("can not get browserResourceInfo or nodeResourceInfo");
|
|
20
24
|
}
|
|
21
|
-
var mergedStats = mergeStats(browserResourceInfo.stats.stats, nodeResourceInfo.stats.stats
|
|
22
|
-
var mergedManifest = mergeManifest(browserResourceInfo.manifest.manifest, nodeResourceInfo.manifest.manifest
|
|
25
|
+
var mergedStats = mergeStats(browserResourceInfo.stats.stats, nodeResourceInfo.stats.stats);
|
|
26
|
+
var mergedManifest = mergeManifest(browserResourceInfo.manifest.manifest, nodeResourceInfo.manifest.manifest);
|
|
23
27
|
return {
|
|
24
28
|
mergedStats,
|
|
25
29
|
mergedStatsFilePath: browserResourceInfo.stats.filename,
|
|
@@ -27,8 +31,8 @@ function mergeStatsAndManifest(nodePlugin, browserPlugin, ssrDir) {
|
|
|
27
31
|
mergedManifestFilePath: browserResourceInfo.manifest.filename
|
|
28
32
|
};
|
|
29
33
|
}
|
|
30
|
-
function updateStatsAndManifest(nodePlugin, browserPlugin, outputDir
|
|
31
|
-
var _mergeStatsAndManifest = mergeStatsAndManifest(nodePlugin, browserPlugin
|
|
34
|
+
function updateStatsAndManifest(nodePlugin, browserPlugin, outputDir) {
|
|
35
|
+
var _mergeStatsAndManifest = mergeStatsAndManifest(nodePlugin, browserPlugin), mergedStats = _mergeStatsAndManifest.mergedStats, mergedStatsFilePath = _mergeStatsAndManifest.mergedStatsFilePath, mergedManifest = _mergeStatsAndManifest.mergedManifest, mergedManifestFilePath = _mergeStatsAndManifest.mergedManifestFilePath;
|
|
32
36
|
fs.writeFileSync(path.resolve(outputDir, mergedStatsFilePath), JSON.stringify(mergedStats, null, 2));
|
|
33
37
|
fs.writeFileSync(path.resolve(outputDir, mergedManifestFilePath), JSON.stringify(mergedManifest, null, 2));
|
|
34
38
|
}
|