@module-federation/modern-js 0.14.2 → 0.14.3
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/LICENSE +21 -0
- package/dist/cjs/cli/configPlugin.js +377 -0
- package/dist/cjs/cli/configPlugin.spec.js +112 -0
- package/dist/cjs/cli/constant.js +28 -0
- package/dist/cjs/cli/index.js +93 -0
- package/dist/cjs/cli/logger.js +27 -0
- package/dist/cjs/cli/manifest.js +75 -0
- package/dist/cjs/cli/mfRuntimePlugins/inject-node-fetch.js +44 -0
- package/dist/cjs/cli/mfRuntimePlugins/resolve-entry-ipv4.js +82 -0
- package/dist/cjs/cli/mfRuntimePlugins/shared-strategy.js +43 -0
- package/dist/cjs/cli/ssrPlugin.js +217 -0
- package/dist/cjs/cli/utils.js +85 -0
- package/dist/cjs/constant.js +31 -0
- package/dist/cjs/interfaces/bundler.js +16 -0
- package/dist/cjs/runtime/createRemoteSSRComponent.js +201 -0
- package/dist/cjs/runtime/index.js +38 -0
- package/dist/cjs/server/fileCache.js +84 -0
- package/dist/cjs/server/fileCache.spec.js +28 -0
- package/dist/cjs/server/index.js +58 -0
- package/dist/cjs/server/staticMiddleware.js +77 -0
- package/dist/cjs/server/staticMiddleware.spec.js +185 -0
- package/dist/cjs/ssr-runtime/SSRLiveReload.js +43 -0
- package/dist/cjs/ssr-runtime/index.js +22 -0
- package/dist/cjs/ssr-runtime/plugin.js +68 -0
- package/dist/cjs/types/index.js +16 -0
- package/dist/esm/cli/configPlugin.js +384 -0
- package/dist/esm/cli/configPlugin.spec.js +108 -0
- package/dist/esm/cli/constant.js +4 -0
- package/dist/esm/cli/index.js +88 -0
- package/dist/esm/cli/logger.js +7 -0
- package/dist/esm/cli/manifest.js +41 -0
- package/dist/esm/cli/mfRuntimePlugins/inject-node-fetch.js +16 -0
- package/dist/esm/cli/mfRuntimePlugins/resolve-entry-ipv4.js +74 -0
- package/dist/esm/cli/mfRuntimePlugins/shared-strategy.js +25 -0
- package/dist/esm/cli/ssrPlugin.js +199 -0
- package/dist/esm/cli/utils.js +49 -0
- package/dist/esm/constant.js +6 -0
- package/dist/esm/interfaces/bundler.js +0 -0
- package/dist/esm/runtime/createRemoteSSRComponent.js +191 -0
- package/dist/esm/runtime/index.js +12 -0
- package/dist/esm/server/fileCache.js +98 -0
- package/dist/esm/server/fileCache.spec.js +50 -0
- package/dist/esm/server/index.js +36 -0
- package/dist/esm/server/staticMiddleware.js +81 -0
- package/dist/esm/server/staticMiddleware.spec.js +328 -0
- package/dist/esm/ssr-runtime/SSRLiveReload.js +26 -0
- package/dist/esm/ssr-runtime/index.js +1 -0
- package/dist/esm/ssr-runtime/plugin.js +70 -0
- package/dist/esm/types/index.js +0 -0
- package/dist/esm-node/cli/configPlugin.js +336 -0
- package/dist/esm-node/cli/configPlugin.spec.js +89 -0
- package/dist/esm-node/cli/constant.js +4 -0
- package/dist/esm-node/cli/index.js +68 -0
- package/dist/esm-node/cli/logger.js +7 -0
- package/dist/esm-node/cli/manifest.js +41 -0
- package/dist/esm-node/cli/mfRuntimePlugins/inject-node-fetch.js +14 -0
- package/dist/esm-node/cli/mfRuntimePlugins/resolve-entry-ipv4.js +62 -0
- package/dist/esm-node/cli/mfRuntimePlugins/shared-strategy.js +23 -0
- package/dist/esm-node/cli/ssrPlugin.js +181 -0
- package/dist/esm-node/cli/utils.js +49 -0
- package/dist/esm-node/constant.js +6 -0
- package/dist/esm-node/interfaces/bundler.js +0 -0
- package/dist/esm-node/runtime/createRemoteSSRComponent.js +166 -0
- package/dist/esm-node/runtime/index.js +12 -0
- package/dist/esm-node/server/fileCache.js +49 -0
- package/dist/esm-node/server/fileCache.spec.js +27 -0
- package/dist/esm-node/server/index.js +34 -0
- package/dist/esm-node/server/staticMiddleware.js +43 -0
- package/dist/esm-node/server/staticMiddleware.spec.js +162 -0
- package/dist/esm-node/ssr-runtime/SSRLiveReload.js +19 -0
- package/dist/esm-node/ssr-runtime/index.js +1 -0
- package/dist/esm-node/ssr-runtime/plugin.js +34 -0
- package/dist/esm-node/types/index.js +0 -0
- package/dist/types/cli/configPlugin.d.ts +21 -0
- package/dist/types/cli/configPlugin.spec.d.ts +1 -0
- package/dist/types/cli/constant.d.ts +1 -0
- package/dist/types/cli/index.d.ts +5 -0
- package/dist/types/cli/logger.d.ts +2 -0
- package/dist/types/cli/manifest.d.ts +2 -0
- package/dist/types/cli/mfRuntimePlugins/inject-node-fetch.d.ts +3 -0
- package/dist/types/cli/mfRuntimePlugins/resolve-entry-ipv4.d.ts +3 -0
- package/dist/types/cli/mfRuntimePlugins/shared-strategy.d.ts +3 -0
- package/dist/types/cli/ssrPlugin.d.ts +6 -0
- package/dist/types/cli/utils.d.ts +5 -0
- package/dist/types/constant.d.ts +2 -0
- package/dist/types/interfaces/bundler.d.ts +18 -0
- package/dist/types/runtime/createRemoteSSRComponent.d.ts +18 -0
- package/dist/types/runtime/index.d.ts +5 -0
- package/dist/types/server/fileCache.d.ts +14 -0
- package/dist/types/server/fileCache.spec.d.ts +1 -0
- package/dist/types/server/index.d.ts +4 -0
- package/dist/types/server/staticMiddleware.d.ts +6 -0
- package/dist/types/server/staticMiddleware.spec.d.ts +1 -0
- package/dist/types/ssr-runtime/SSRLiveReload.d.ts +1 -0
- package/dist/types/ssr-runtime/index.d.ts +1 -0
- package/dist/types/ssr-runtime/plugin.d.ts +2 -0
- package/dist/types/types/index.d.ts +22 -0
- package/package.json +7 -7
|
@@ -0,0 +1,88 @@
|
|
|
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 { ModuleFederationPlugin as WebpackModuleFederationPlugin, AsyncBoundaryPlugin } from "@module-federation/enhanced";
|
|
5
|
+
import { ModuleFederationPlugin as RspackModuleFederationPlugin } from "@module-federation/enhanced/rspack";
|
|
6
|
+
import { moduleFederationConfigPlugin } from "./configPlugin";
|
|
7
|
+
import { moduleFederationSSRPlugin } from "./ssrPlugin";
|
|
8
|
+
import { isWebTarget } from "./utils";
|
|
9
|
+
var moduleFederationPlugin = function() {
|
|
10
|
+
var userConfig = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
11
|
+
var internalModernPluginOptions = {
|
|
12
|
+
csrConfig: void 0,
|
|
13
|
+
ssrConfig: void 0,
|
|
14
|
+
browserPlugin: void 0,
|
|
15
|
+
nodePlugin: void 0,
|
|
16
|
+
distOutputDir: "",
|
|
17
|
+
originPluginOptions: userConfig,
|
|
18
|
+
remoteIpStrategy: userConfig === null || userConfig === void 0 ? void 0 : userConfig.remoteIpStrategy,
|
|
19
|
+
userConfig: userConfig || {}
|
|
20
|
+
};
|
|
21
|
+
return {
|
|
22
|
+
name: "@modern-js/plugin-module-federation",
|
|
23
|
+
setup: function() {
|
|
24
|
+
var _ref = _async_to_generator(function(api) {
|
|
25
|
+
var modernjsConfig;
|
|
26
|
+
return _ts_generator(this, function(_state) {
|
|
27
|
+
modernjsConfig = api.getConfig();
|
|
28
|
+
api.modifyBundlerChain(function(chain) {
|
|
29
|
+
var bundlerType = api.getAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
|
|
30
|
+
var browserPluginOptions = internalModernPluginOptions.csrConfig;
|
|
31
|
+
var MFPlugin = bundlerType === "webpack" ? WebpackModuleFederationPlugin : RspackModuleFederationPlugin;
|
|
32
|
+
if (isWebTarget(chain.get("target"))) {
|
|
33
|
+
chain.plugin("plugin-module-federation").use(MFPlugin, [
|
|
34
|
+
browserPluginOptions
|
|
35
|
+
]).init(function(Plugin, args) {
|
|
36
|
+
internalModernPluginOptions.browserPlugin = new Plugin(args[0]);
|
|
37
|
+
return internalModernPluginOptions.browserPlugin;
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
if (bundlerType === "webpack") {
|
|
41
|
+
var _modernjsConfig_source;
|
|
42
|
+
var enableAsyncEntry = (_modernjsConfig_source = modernjsConfig.source) === null || _modernjsConfig_source === void 0 ? void 0 : _modernjsConfig_source.enableAsyncEntry;
|
|
43
|
+
if (!enableAsyncEntry && browserPluginOptions.async !== false) {
|
|
44
|
+
var asyncBoundaryPluginOptions = _type_of(browserPluginOptions.async) === "object" ? browserPluginOptions.async : {
|
|
45
|
+
eager: function(module) {
|
|
46
|
+
return module && /\.federation/.test((module === null || module === void 0 ? void 0 : module.request) || "");
|
|
47
|
+
},
|
|
48
|
+
excludeChunk: function(chunk) {
|
|
49
|
+
return chunk.name === browserPluginOptions.name;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
chain.plugin("async-boundary-plugin").use(AsyncBoundaryPlugin, [
|
|
53
|
+
asyncBoundaryPluginOptions
|
|
54
|
+
]);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
api._internalServerPlugins(function(param) {
|
|
59
|
+
var plugins = param.plugins;
|
|
60
|
+
plugins.push({
|
|
61
|
+
name: "@module-federation/modern-js/server"
|
|
62
|
+
});
|
|
63
|
+
return {
|
|
64
|
+
plugins
|
|
65
|
+
};
|
|
66
|
+
});
|
|
67
|
+
return [
|
|
68
|
+
2
|
|
69
|
+
];
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
return function(api) {
|
|
73
|
+
return _ref.apply(this, arguments);
|
|
74
|
+
};
|
|
75
|
+
}(),
|
|
76
|
+
usePlugins: [
|
|
77
|
+
moduleFederationConfigPlugin(internalModernPluginOptions),
|
|
78
|
+
moduleFederationSSRPlugin(internalModernPluginOptions)
|
|
79
|
+
]
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
var cli_default = moduleFederationPlugin;
|
|
83
|
+
import { createModuleFederationConfig } from "@module-federation/enhanced";
|
|
84
|
+
export {
|
|
85
|
+
createModuleFederationConfig,
|
|
86
|
+
cli_default as default,
|
|
87
|
+
moduleFederationPlugin
|
|
88
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import fs from "fs-extra";
|
|
3
|
+
function mergeStats(browserStats, nodeStats) {
|
|
4
|
+
var ssrRemoteEntry = nodeStats.metaData.remoteEntry;
|
|
5
|
+
browserStats.metaData.ssrRemoteEntry = ssrRemoteEntry;
|
|
6
|
+
if ("publicPath" in browserStats.metaData) {
|
|
7
|
+
browserStats.metaData.ssrPublicPath = nodeStats.metaData.publicPath;
|
|
8
|
+
}
|
|
9
|
+
return browserStats;
|
|
10
|
+
}
|
|
11
|
+
function mergeManifest(browserManifest, nodeManifest) {
|
|
12
|
+
var ssrRemoteEntry = nodeManifest.metaData.remoteEntry;
|
|
13
|
+
browserManifest.metaData.ssrRemoteEntry = ssrRemoteEntry;
|
|
14
|
+
if ("publicPath" in browserManifest.metaData) {
|
|
15
|
+
browserManifest.metaData.ssrPublicPath = nodeManifest.metaData.publicPath;
|
|
16
|
+
}
|
|
17
|
+
return browserManifest;
|
|
18
|
+
}
|
|
19
|
+
function mergeStatsAndManifest(nodePlugin, browserPlugin) {
|
|
20
|
+
var nodeResourceInfo = nodePlugin.statsResourceInfo;
|
|
21
|
+
var browserResourceInfo = browserPlugin.statsResourceInfo;
|
|
22
|
+
if (!browserResourceInfo || !nodeResourceInfo || !browserResourceInfo.stats || !nodeResourceInfo.stats || !browserResourceInfo.manifest || !nodeResourceInfo.manifest) {
|
|
23
|
+
throw new Error("can not get browserResourceInfo or nodeResourceInfo");
|
|
24
|
+
}
|
|
25
|
+
var mergedStats = mergeStats(browserResourceInfo.stats.stats, nodeResourceInfo.stats.stats);
|
|
26
|
+
var mergedManifest = mergeManifest(browserResourceInfo.manifest.manifest, nodeResourceInfo.manifest.manifest);
|
|
27
|
+
return {
|
|
28
|
+
mergedStats,
|
|
29
|
+
mergedStatsFilePath: browserResourceInfo.stats.filename,
|
|
30
|
+
mergedManifest,
|
|
31
|
+
mergedManifestFilePath: browserResourceInfo.manifest.filename
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function updateStatsAndManifest(nodePlugin, browserPlugin, outputDir) {
|
|
35
|
+
var _mergeStatsAndManifest = mergeStatsAndManifest(nodePlugin, browserPlugin), mergedStats = _mergeStatsAndManifest.mergedStats, mergedStatsFilePath = _mergeStatsAndManifest.mergedStatsFilePath, mergedManifest = _mergeStatsAndManifest.mergedManifest, mergedManifestFilePath = _mergeStatsAndManifest.mergedManifestFilePath;
|
|
36
|
+
fs.writeFileSync(path.resolve(outputDir, mergedStatsFilePath), JSON.stringify(mergedStats, null, 2));
|
|
37
|
+
fs.writeFileSync(path.resolve(outputDir, mergedManifestFilePath), JSON.stringify(mergedManifest, null, 2));
|
|
38
|
+
}
|
|
39
|
+
export {
|
|
40
|
+
updateStatsAndManifest
|
|
41
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import nodeFetch from "node-fetch";
|
|
2
|
+
var injectNodeFetchPlugin = function() {
|
|
3
|
+
return {
|
|
4
|
+
name: "inject-node-fetch-plugin",
|
|
5
|
+
beforeInit: function beforeInit(args) {
|
|
6
|
+
if (!globalThis.fetch) {
|
|
7
|
+
globalThis.fetch = nodeFetch;
|
|
8
|
+
}
|
|
9
|
+
return args;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
var inject_node_fetch_default = injectNodeFetchPlugin;
|
|
14
|
+
export {
|
|
15
|
+
inject_node_fetch_default as default
|
|
16
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,199 @@
|
|
|
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 "fs-extra";
|
|
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
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
};
|
|
File without changes
|