@module-federation/modern-js 0.0.0-next-20250228220829 → 0.0.0-next-20250303114903
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 +18 -42
- package/dist/cjs/cli/index.js +25 -30
- package/dist/cjs/cli/manifest.js +9 -10
- package/dist/cjs/cli/ssrPlugin.js +42 -40
- package/dist/cjs/cli/utils.js +37 -61
- package/dist/cjs/cli/utils.spec.js +0 -60
- package/dist/esm/cli/configPlugin.js +18 -45
- package/dist/esm/cli/index.js +28 -35
- package/dist/esm/cli/manifest.js +9 -10
- package/dist/esm/cli/ssrPlugin.js +42 -44
- package/dist/esm/cli/utils.js +36 -59
- package/dist/esm/cli/utils.spec.js +1 -78
- package/dist/esm-node/cli/configPlugin.js +18 -41
- package/dist/esm-node/cli/index.js +25 -30
- package/dist/esm-node/cli/manifest.js +9 -10
- package/dist/esm-node/cli/ssrPlugin.js +41 -40
- package/dist/esm-node/cli/utils.js +36 -60
- package/dist/esm-node/cli/utils.spec.js +1 -61
- package/dist/types/cli/configPlugin.d.ts +1 -11
- package/dist/types/cli/manifest.d.ts +1 -1
- package/dist/types/cli/ssrPlugin.d.ts +1 -0
- package/dist/types/cli/utils.d.ts +6 -6
- package/dist/types/types/index.d.ts +1 -1
- package/package.json +14 -14
|
@@ -8,17 +8,6 @@ function setEnv(enableSSR) {
|
|
|
8
8
|
process.env["MF_SSR_PRJ"] = "true";
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
|
-
function modifyBundlerConfig(options) {
|
|
12
|
-
var mfConfig = options.mfConfig, config = options.config, isServer = options.isServer, modernjsConfig = options.modernjsConfig, _options_remoteIpStrategy = options.remoteIpStrategy, remoteIpStrategy = _options_remoteIpStrategy === void 0 ? "ipv4" : _options_remoteIpStrategy, bundlerType = options.bundlerType;
|
|
13
|
-
patchMFConfig(mfConfig, isServer, remoteIpStrategy);
|
|
14
|
-
patchBundlerConfig({
|
|
15
|
-
bundlerType,
|
|
16
|
-
bundlerConfig: config,
|
|
17
|
-
isServer,
|
|
18
|
-
modernjsConfig,
|
|
19
|
-
mfConfig
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
11
|
var moduleFederationConfigPlugin = function(userConfig) {
|
|
23
12
|
return {
|
|
24
13
|
name: "@modern-js/plugin-module-federation-config",
|
|
@@ -30,7 +19,7 @@ var moduleFederationConfigPlugin = function(userConfig) {
|
|
|
30
19
|
],
|
|
31
20
|
setup: function() {
|
|
32
21
|
var _ref = _async_to_generator(function(api) {
|
|
33
|
-
var modernjsConfig, mfConfig, csrConfig, ssrConfig;
|
|
22
|
+
var _userConfig_userConfig, _modernjsConfig_server, modernjsConfig, mfConfig, csrConfig, ssrConfig, _userConfig_userConfig_ssr, enableSSR;
|
|
34
23
|
return _ts_generator(this, function(_state) {
|
|
35
24
|
switch (_state.label) {
|
|
36
25
|
case 0:
|
|
@@ -45,11 +34,26 @@ var moduleFederationConfigPlugin = function(userConfig) {
|
|
|
45
34
|
ssrConfig = userConfig.ssrConfig || JSON.parse(JSON.stringify(mfConfig));
|
|
46
35
|
userConfig.ssrConfig = ssrConfig;
|
|
47
36
|
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);
|
|
38
|
+
api.modifyBundlerChain(function(chain, param) {
|
|
39
|
+
var isServer = param.isServer;
|
|
40
|
+
addMyTypes2Ignored(chain, isServer ? ssrConfig : csrConfig);
|
|
41
|
+
var targetMFConfig = isServer ? ssrConfig : csrConfig;
|
|
42
|
+
patchMFConfig(targetMFConfig, isServer, userConfig.remoteIpStrategy || "ipv4");
|
|
43
|
+
patchBundlerConfig({
|
|
44
|
+
// @ts-expect-error chain type is not correct
|
|
45
|
+
chain,
|
|
46
|
+
isServer,
|
|
47
|
+
modernjsConfig,
|
|
48
|
+
mfConfig,
|
|
49
|
+
enableSSR
|
|
50
|
+
});
|
|
51
|
+
userConfig.distOutputDir = chain.output.get("path") || path.resolve(process.cwd(), "dist");
|
|
52
|
+
});
|
|
48
53
|
api.config(function() {
|
|
49
|
-
var
|
|
54
|
+
var _modernjsConfig_source, _modernjsConfig_source1, _modernjsConfig_dev;
|
|
50
55
|
var bundlerType = api.getAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
|
|
51
56
|
var ipv4 = getIPV4();
|
|
52
|
-
var enableSSR = ((_userConfig_userConfig = userConfig.userConfig) === null || _userConfig_userConfig === void 0 ? void 0 : _userConfig_userConfig.ssr) === false ? false : Boolean(modernjsConfig === null || modernjsConfig === void 0 ? void 0 : (_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
|
|
53
57
|
if (userConfig.remoteIpStrategy === void 0) {
|
|
54
58
|
if (!enableSSR) {
|
|
55
59
|
userConfig.remoteIpStrategy = "inherit";
|
|
@@ -60,36 +64,6 @@ var moduleFederationConfigPlugin = function(userConfig) {
|
|
|
60
64
|
var _modernjsConfig_source_enableAsyncEntry;
|
|
61
65
|
return {
|
|
62
66
|
tools: {
|
|
63
|
-
bundlerChain: function bundlerChain(chain, param) {
|
|
64
|
-
var isServer = param.isServer;
|
|
65
|
-
addMyTypes2Ignored(chain, isServer ? ssrConfig : csrConfig);
|
|
66
|
-
},
|
|
67
|
-
rspack: function rspack(config, param) {
|
|
68
|
-
var isServer = param.isServer;
|
|
69
|
-
var _config_output;
|
|
70
|
-
modifyBundlerConfig({
|
|
71
|
-
bundlerType,
|
|
72
|
-
mfConfig: isServer ? ssrConfig : csrConfig,
|
|
73
|
-
config,
|
|
74
|
-
isServer,
|
|
75
|
-
modernjsConfig,
|
|
76
|
-
remoteIpStrategy: userConfig.remoteIpStrategy
|
|
77
|
-
});
|
|
78
|
-
userConfig.distOutputDir = ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.path) || path.resolve(process.cwd(), "dist");
|
|
79
|
-
},
|
|
80
|
-
webpack: function webpack(config, param) {
|
|
81
|
-
var isServer = param.isServer;
|
|
82
|
-
var _config_output;
|
|
83
|
-
modifyBundlerConfig({
|
|
84
|
-
bundlerType,
|
|
85
|
-
mfConfig: isServer ? ssrConfig : csrConfig,
|
|
86
|
-
config,
|
|
87
|
-
isServer,
|
|
88
|
-
modernjsConfig,
|
|
89
|
-
remoteIpStrategy: userConfig.remoteIpStrategy
|
|
90
|
-
});
|
|
91
|
-
userConfig.distOutputDir = ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.path) || path.resolve(process.cwd(), "dist");
|
|
92
|
-
},
|
|
93
67
|
devServer: {
|
|
94
68
|
headers: {
|
|
95
69
|
"Access-Control-Allow-Origin": "*",
|
|
@@ -128,7 +102,6 @@ var moduleFederationConfigPlugin = function(userConfig) {
|
|
|
128
102
|
var configPlugin_default = moduleFederationConfigPlugin;
|
|
129
103
|
export {
|
|
130
104
|
configPlugin_default as default,
|
|
131
|
-
modifyBundlerConfig,
|
|
132
105
|
moduleFederationConfigPlugin,
|
|
133
106
|
setEnv
|
|
134
107
|
};
|
package/dist/esm/cli/index.js
CHANGED
|
@@ -5,6 +5,7 @@ import { ModuleFederationPlugin as WebpackModuleFederationPlugin, AsyncBoundaryP
|
|
|
5
5
|
import { ModuleFederationPlugin as RspackModuleFederationPlugin } from "@module-federation/enhanced/rspack";
|
|
6
6
|
import { moduleFederationConfigPlugin } from "./configPlugin";
|
|
7
7
|
import { moduleFederationSSRPlugin } from "./ssrPlugin";
|
|
8
|
+
import { isWebTarget } from "./utils";
|
|
8
9
|
var moduleFederationPlugin = function() {
|
|
9
10
|
var userConfig = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
10
11
|
var internalModernPluginOptions = {
|
|
@@ -24,43 +25,35 @@ var moduleFederationPlugin = function() {
|
|
|
24
25
|
var modernjsConfig;
|
|
25
26
|
return _ts_generator(this, function(_state) {
|
|
26
27
|
modernjsConfig = api.getConfig();
|
|
27
|
-
api.
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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;
|
|
37
50
|
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
var browserPluginOptions = internalModernPluginOptions.csrConfig;
|
|
43
|
-
if (!isServer) {
|
|
44
|
-
var _config_plugins;
|
|
45
|
-
internalModernPluginOptions.browserPlugin = new WebpackModuleFederationPlugin(browserPluginOptions);
|
|
46
|
-
(_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(internalModernPluginOptions.browserPlugin);
|
|
47
|
-
}
|
|
48
|
-
var enableAsyncEntry = (_modernjsConfig_source = modernjsConfig.source) === null || _modernjsConfig_source === void 0 ? void 0 : _modernjsConfig_source.enableAsyncEntry;
|
|
49
|
-
if (!enableAsyncEntry && browserPluginOptions.async !== false) {
|
|
50
|
-
var _config_plugins1;
|
|
51
|
-
var asyncBoundaryPluginOptions = _type_of(browserPluginOptions.async) === "object" ? browserPluginOptions.async : {
|
|
52
|
-
eager: function(module) {
|
|
53
|
-
return module && /\.federation/.test((module === null || module === void 0 ? void 0 : module.request) || "");
|
|
54
|
-
},
|
|
55
|
-
excludeChunk: function(chunk) {
|
|
56
|
-
return chunk.name === browserPluginOptions.name;
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
(_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(new AsyncBoundaryPlugin(asyncBoundaryPluginOptions));
|
|
60
|
-
}
|
|
61
|
-
}
|
|
51
|
+
};
|
|
52
|
+
chain.plugin("async-boundary-plugin").use(AsyncBoundaryPlugin, [
|
|
53
|
+
asyncBoundaryPluginOptions
|
|
54
|
+
]);
|
|
62
55
|
}
|
|
63
|
-
}
|
|
56
|
+
}
|
|
64
57
|
});
|
|
65
58
|
return [
|
|
66
59
|
2
|
package/dist/esm/cli/manifest.js
CHANGED
|
@@ -1,26 +1,25 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import { fs } from "@modern-js/utils";
|
|
3
|
-
|
|
4
|
-
function mergeStats(browserStats, nodeStats) {
|
|
3
|
+
function mergeStats(browserStats, nodeStats, ssrDir) {
|
|
5
4
|
var ssrRemoteEntry = nodeStats.metaData.remoteEntry;
|
|
6
|
-
ssrRemoteEntry.path =
|
|
5
|
+
ssrRemoteEntry.path = ssrDir;
|
|
7
6
|
browserStats.metaData.ssrRemoteEntry = ssrRemoteEntry;
|
|
8
7
|
return browserStats;
|
|
9
8
|
}
|
|
10
|
-
function mergeManifest(browserManifest, nodeManifest) {
|
|
9
|
+
function mergeManifest(browserManifest, nodeManifest, ssrDir) {
|
|
11
10
|
var ssrRemoteEntry = nodeManifest.metaData.remoteEntry;
|
|
12
|
-
ssrRemoteEntry.path =
|
|
11
|
+
ssrRemoteEntry.path = ssrDir;
|
|
13
12
|
browserManifest.metaData.ssrRemoteEntry = ssrRemoteEntry;
|
|
14
13
|
return browserManifest;
|
|
15
14
|
}
|
|
16
|
-
function mergeStatsAndManifest(nodePlugin, browserPlugin) {
|
|
15
|
+
function mergeStatsAndManifest(nodePlugin, browserPlugin, ssrDir) {
|
|
17
16
|
var nodeResourceInfo = nodePlugin.statsResourceInfo;
|
|
18
17
|
var browserResourceInfo = browserPlugin.statsResourceInfo;
|
|
19
18
|
if (!browserResourceInfo || !nodeResourceInfo || !browserResourceInfo.stats || !nodeResourceInfo.stats || !browserResourceInfo.manifest || !nodeResourceInfo.manifest) {
|
|
20
19
|
throw new Error("can not get browserResourceInfo or nodeResourceInfo");
|
|
21
20
|
}
|
|
22
|
-
var mergedStats = mergeStats(browserResourceInfo.stats.stats, nodeResourceInfo.stats.stats);
|
|
23
|
-
var mergedManifest = mergeManifest(browserResourceInfo.manifest.manifest, nodeResourceInfo.manifest.manifest);
|
|
21
|
+
var mergedStats = mergeStats(browserResourceInfo.stats.stats, nodeResourceInfo.stats.stats, ssrDir);
|
|
22
|
+
var mergedManifest = mergeManifest(browserResourceInfo.manifest.manifest, nodeResourceInfo.manifest.manifest, ssrDir);
|
|
24
23
|
return {
|
|
25
24
|
mergedStats,
|
|
26
25
|
mergedStatsFilePath: browserResourceInfo.stats.filename,
|
|
@@ -28,8 +27,8 @@ function mergeStatsAndManifest(nodePlugin, browserPlugin) {
|
|
|
28
27
|
mergedManifestFilePath: browserResourceInfo.manifest.filename
|
|
29
28
|
};
|
|
30
29
|
}
|
|
31
|
-
function updateStatsAndManifest(nodePlugin, browserPlugin, outputDir) {
|
|
32
|
-
var _mergeStatsAndManifest = mergeStatsAndManifest(nodePlugin, browserPlugin), mergedStats = _mergeStatsAndManifest.mergedStats, mergedStatsFilePath = _mergeStatsAndManifest.mergedStatsFilePath, mergedManifest = _mergeStatsAndManifest.mergedManifest, mergedManifestFilePath = _mergeStatsAndManifest.mergedManifestFilePath;
|
|
30
|
+
function updateStatsAndManifest(nodePlugin, browserPlugin, outputDir, ssrDir) {
|
|
31
|
+
var _mergeStatsAndManifest = mergeStatsAndManifest(nodePlugin, browserPlugin, ssrDir), mergedStats = _mergeStatsAndManifest.mergedStats, mergedStatsFilePath = _mergeStatsAndManifest.mergedStatsFilePath, mergedManifest = _mergeStatsAndManifest.mergedManifest, mergedManifestFilePath = _mergeStatsAndManifest.mergedManifestFilePath;
|
|
33
32
|
fs.writeFileSync(path.resolve(outputDir, mergedStatsFilePath), JSON.stringify(mergedStats, null, 2));
|
|
34
33
|
fs.writeFileSync(path.resolve(outputDir, mergedManifestFilePath), JSON.stringify(mergedManifest, null, 2));
|
|
35
34
|
}
|
|
@@ -7,11 +7,14 @@ import { ModuleFederationPlugin as RspackModuleFederationPlugin } from "@module-
|
|
|
7
7
|
import UniverseEntryChunkTrackerPlugin from "@module-federation/node/universe-entry-chunk-tracker-plugin";
|
|
8
8
|
import { updateStatsAndManifest } from "./manifest";
|
|
9
9
|
import { isDev } from "./constant";
|
|
10
|
+
import { MODERN_JS_SERVER_DIR } from "../constant";
|
|
10
11
|
import logger from "./logger";
|
|
12
|
+
import { isWebTarget } from "./utils";
|
|
11
13
|
function setEnv() {
|
|
12
14
|
process.env["MF_DISABLE_EMIT_STATS"] = "true";
|
|
13
15
|
process.env["MF_SSR_PRJ"] = "true";
|
|
14
16
|
}
|
|
17
|
+
var CHAIN_MF_PLUGIN_ID = "plugin-module-federation-server";
|
|
15
18
|
var moduleFederationSSRPlugin = function(pluginOptions) {
|
|
16
19
|
return {
|
|
17
20
|
name: "@modern-js/plugin-module-federation-ssr",
|
|
@@ -21,10 +24,12 @@ var moduleFederationSSRPlugin = function(pluginOptions) {
|
|
|
21
24
|
],
|
|
22
25
|
setup: function() {
|
|
23
26
|
var _ref = _async_to_generator(function(api) {
|
|
24
|
-
var _pluginOptions_userConfig, _modernjsConfig_server, modernjsConfig, enableSSR;
|
|
27
|
+
var _pluginOptions_userConfig, _modernjsConfig_server, modernjsConfig, _pluginOptions_userConfig_ssr, enableSSR, csrOutputPath, ssrOutputPath;
|
|
25
28
|
return _ts_generator(this, function(_state) {
|
|
26
29
|
modernjsConfig = api.getConfig();
|
|
27
|
-
enableSSR = ((_pluginOptions_userConfig = pluginOptions.userConfig) === null || _pluginOptions_userConfig === void 0 ? void 0 : _pluginOptions_userConfig.ssr)
|
|
30
|
+
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);
|
|
31
|
+
csrOutputPath = "";
|
|
32
|
+
ssrOutputPath = "";
|
|
28
33
|
if (!enableSSR) {
|
|
29
34
|
return [
|
|
30
35
|
2
|
|
@@ -49,35 +54,41 @@ var moduleFederationSSRPlugin = function(pluginOptions) {
|
|
|
49
54
|
plugins
|
|
50
55
|
};
|
|
51
56
|
});
|
|
57
|
+
api.modifyBundlerChain(function(chain, param) {
|
|
58
|
+
var isServer = param.isServer;
|
|
59
|
+
var bundlerType = api.getAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
|
|
60
|
+
var MFPlugin = bundlerType === "webpack" ? ModuleFederationPlugin : RspackModuleFederationPlugin;
|
|
61
|
+
var isWeb = isWebTarget(chain.get("target"));
|
|
62
|
+
if (!isWeb) {
|
|
63
|
+
if (!chain.plugins.has(CHAIN_MF_PLUGIN_ID)) {
|
|
64
|
+
chain.plugin(CHAIN_MF_PLUGIN_ID).use(MFPlugin, [
|
|
65
|
+
pluginOptions.ssrConfig
|
|
66
|
+
]).init(function(Plugin, args) {
|
|
67
|
+
pluginOptions.nodePlugin = new Plugin(args[0]);
|
|
68
|
+
return pluginOptions.nodePlugin;
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (!isWeb) {
|
|
73
|
+
chain.target("async-node");
|
|
74
|
+
if (isDev) {
|
|
75
|
+
chain.plugin("UniverseEntryChunkTrackerPlugin").use(UniverseEntryChunkTrackerPlugin);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (isDev && !isServer) {
|
|
79
|
+
chain.externals({
|
|
80
|
+
"@module-federation/node/utils": "NOT_USED_IN_BROWSER"
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
if (isServer) {
|
|
84
|
+
ssrOutputPath = chain.output.get("path") || path.resolve(process.cwd(), "dist/".concat(MODERN_JS_SERVER_DIR));
|
|
85
|
+
} else {
|
|
86
|
+
csrOutputPath = chain.output.get("path") || path.resolve(process.cwd(), "dist");
|
|
87
|
+
}
|
|
88
|
+
});
|
|
52
89
|
api.config(function() {
|
|
53
90
|
return {
|
|
54
91
|
tools: {
|
|
55
|
-
rspack: function rspack(config, param) {
|
|
56
|
-
var isServer = param.isServer;
|
|
57
|
-
if (isServer) {
|
|
58
|
-
if (!pluginOptions.nodePlugin) {
|
|
59
|
-
var _config_plugins;
|
|
60
|
-
pluginOptions.nodePlugin = new RspackModuleFederationPlugin(pluginOptions.ssrConfig);
|
|
61
|
-
(_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(pluginOptions.nodePlugin);
|
|
62
|
-
}
|
|
63
|
-
} else {
|
|
64
|
-
var _config_output;
|
|
65
|
-
pluginOptions.distOutputDir = pluginOptions.distOutputDir || ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.path) || path.resolve(process.cwd(), "dist");
|
|
66
|
-
}
|
|
67
|
-
},
|
|
68
|
-
webpack: function webpack(config, param) {
|
|
69
|
-
var isServer = param.isServer;
|
|
70
|
-
if (isServer) {
|
|
71
|
-
if (!pluginOptions.nodePlugin) {
|
|
72
|
-
var _config_plugins;
|
|
73
|
-
pluginOptions.nodePlugin = new ModuleFederationPlugin(pluginOptions.ssrConfig);
|
|
74
|
-
(_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(pluginOptions.nodePlugin);
|
|
75
|
-
}
|
|
76
|
-
} else {
|
|
77
|
-
var _config_output;
|
|
78
|
-
pluginOptions.distOutputDir = pluginOptions.distOutputDir || ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.path) || path.resolve(process.cwd(), "dist");
|
|
79
|
-
}
|
|
80
|
-
},
|
|
81
92
|
devServer: {
|
|
82
93
|
before: [
|
|
83
94
|
function(req, res, next) {
|
|
@@ -103,31 +114,17 @@ var moduleFederationSSRPlugin = function(pluginOptions) {
|
|
|
103
114
|
}
|
|
104
115
|
}
|
|
105
116
|
]
|
|
106
|
-
},
|
|
107
|
-
bundlerChain: function bundlerChain(chain, param) {
|
|
108
|
-
var isServer = param.isServer;
|
|
109
|
-
if (isServer) {
|
|
110
|
-
chain.target("async-node");
|
|
111
|
-
if (isDev) {
|
|
112
|
-
chain.plugin("UniverseEntryChunkTrackerPlugin").use(UniverseEntryChunkTrackerPlugin);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
if (isDev && !isServer) {
|
|
116
|
-
chain.externals({
|
|
117
|
-
"@module-federation/node/utils": "NOT_USED_IN_BROWSER"
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
117
|
}
|
|
121
118
|
}
|
|
122
119
|
};
|
|
123
120
|
});
|
|
124
121
|
api.onAfterBuild(function() {
|
|
125
122
|
var nodePlugin = pluginOptions.nodePlugin, browserPlugin = pluginOptions.browserPlugin, distOutputDir = pluginOptions.distOutputDir;
|
|
126
|
-
updateStatsAndManifest(nodePlugin, browserPlugin, distOutputDir);
|
|
123
|
+
updateStatsAndManifest(nodePlugin, browserPlugin, distOutputDir, path.relative(csrOutputPath, ssrOutputPath));
|
|
127
124
|
});
|
|
128
125
|
api.onDevCompileDone(function() {
|
|
129
126
|
var nodePlugin = pluginOptions.nodePlugin, browserPlugin = pluginOptions.browserPlugin, distOutputDir = pluginOptions.distOutputDir;
|
|
130
|
-
updateStatsAndManifest(nodePlugin, browserPlugin, distOutputDir);
|
|
127
|
+
updateStatsAndManifest(nodePlugin, browserPlugin, distOutputDir, path.relative(csrOutputPath, ssrOutputPath));
|
|
131
128
|
});
|
|
132
129
|
return [
|
|
133
130
|
2
|
|
@@ -142,6 +139,7 @@ var moduleFederationSSRPlugin = function(pluginOptions) {
|
|
|
142
139
|
};
|
|
143
140
|
var ssrPlugin_default = moduleFederationSSRPlugin;
|
|
144
141
|
export {
|
|
142
|
+
CHAIN_MF_PLUGIN_ID,
|
|
145
143
|
ssrPlugin_default as default,
|
|
146
144
|
moduleFederationSSRPlugin,
|
|
147
145
|
setEnv
|
package/dist/esm/cli/utils.js
CHANGED
|
@@ -166,14 +166,14 @@ var patchMFConfig = function(mfConfig, isServer, remoteIpStrategy) {
|
|
|
166
166
|
mfConfig.dev = false;
|
|
167
167
|
return mfConfig;
|
|
168
168
|
};
|
|
169
|
-
function patchIgnoreWarning(
|
|
170
|
-
|
|
169
|
+
function patchIgnoreWarning(chain) {
|
|
170
|
+
var ignoreWarnings = chain.get("ignoreWarnings") || [];
|
|
171
171
|
var ignoredMsgs = [
|
|
172
172
|
"external script",
|
|
173
173
|
"process.env.WS_NO_BUFFER_UTIL",
|
|
174
174
|
"Can't resolve 'utf-8-validate"
|
|
175
175
|
];
|
|
176
|
-
|
|
176
|
+
ignoreWarnings.push(function(warning) {
|
|
177
177
|
if (ignoredMsgs.some(function(msg) {
|
|
178
178
|
return warning.message.includes(msg);
|
|
179
179
|
})) {
|
|
@@ -181,6 +181,7 @@ function patchIgnoreWarning(bundlerConfig) {
|
|
|
181
181
|
}
|
|
182
182
|
return false;
|
|
183
183
|
});
|
|
184
|
+
chain.ignoreWarnings(ignoreWarnings);
|
|
184
185
|
}
|
|
185
186
|
function addMyTypes2Ignored(chain, mfConfig) {
|
|
186
187
|
var watchOptions = chain.get("watchOptions");
|
|
@@ -215,54 +216,43 @@ function addMyTypes2Ignored(chain, mfConfig) {
|
|
|
215
216
|
}));
|
|
216
217
|
}
|
|
217
218
|
function patchBundlerConfig(options) {
|
|
218
|
-
var
|
|
219
|
-
var
|
|
220
|
-
|
|
221
|
-
(
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
var _bundlerConfig_output1, _bundlerConfig_output2;
|
|
225
|
-
if (!((_bundlerConfig_output1 = bundlerConfig.output) === null || _bundlerConfig_output1 === void 0 ? void 0 : _bundlerConfig_output1.chunkLoadingGlobal)) {
|
|
226
|
-
bundlerConfig.output.chunkLoadingGlobal = "chunk_".concat(mfConfig.name);
|
|
227
|
-
}
|
|
228
|
-
if (!((_bundlerConfig_output2 = bundlerConfig.output) === null || _bundlerConfig_output2 === void 0 ? void 0 : _bundlerConfig_output2.uniqueName)) {
|
|
229
|
-
bundlerConfig.output.uniqueName = mfConfig.name;
|
|
230
|
-
}
|
|
219
|
+
var _modernjsConfig_deploy;
|
|
220
|
+
var chain = options.chain, modernjsConfig = options.modernjsConfig, isServer = options.isServer, mfConfig = options.mfConfig, enableSSR = options.enableSSR;
|
|
221
|
+
chain.optimization.delete("runtimeChunk");
|
|
222
|
+
patchIgnoreWarning(chain);
|
|
223
|
+
if (!chain.output.get("chunkLoadingGlobal")) {
|
|
224
|
+
chain.output.chunkLoadingGlobal("chunk_".concat(mfConfig.name));
|
|
231
225
|
}
|
|
226
|
+
if (!chain.output.get("uniqueName")) {
|
|
227
|
+
chain.output.uniqueName(mfConfig.name);
|
|
228
|
+
}
|
|
229
|
+
var splitChunkConfig = chain.optimization.splitChunks.entries();
|
|
232
230
|
if (!isServer) {
|
|
233
|
-
autoDeleteSplitChunkCacheGroups(mfConfig,
|
|
231
|
+
autoDeleteSplitChunkCacheGroups(mfConfig, splitChunkConfig);
|
|
234
232
|
}
|
|
235
|
-
if (!isServer && enableSSR &&
|
|
236
|
-
|
|
233
|
+
if (!isServer && enableSSR && splitChunkConfig && (typeof splitChunkConfig === "undefined" ? "undefined" : _type_of(splitChunkConfig)) === "object" && splitChunkConfig.cacheGroups) {
|
|
234
|
+
splitChunkConfig.chunks = "async";
|
|
237
235
|
logger.warn('splitChunks.chunks = async is not allowed with stream SSR mode, it will auto changed to "async"');
|
|
238
236
|
}
|
|
239
|
-
if (isDev &&
|
|
240
|
-
var _modernjsConfig_dev,
|
|
241
|
-
var port = ((_modernjsConfig_dev = modernjsConfig.dev) === null || _modernjsConfig_dev === void 0 ? void 0 : _modernjsConfig_dev.port) || ((
|
|
237
|
+
if (isDev && chain.output.get("publicPath") === "auto") {
|
|
238
|
+
var _modernjsConfig_dev, _modernjsConfig_server;
|
|
239
|
+
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;
|
|
242
240
|
var publicPath = "http://localhost:".concat(port, "/");
|
|
243
|
-
|
|
241
|
+
chain.output.publicPath(publicPath);
|
|
244
242
|
}
|
|
245
243
|
if (isServer && enableSSR) {
|
|
246
|
-
var
|
|
247
|
-
var
|
|
248
|
-
|
|
249
|
-
if (output && typeof chunkFileName === "string" && uniqueName && !chunkFileName.includes(uniqueName)) {
|
|
244
|
+
var uniqueName = mfConfig.name || chain.output.get("uniqueName");
|
|
245
|
+
var chunkFileName = chain.output.get("chunkFilename");
|
|
246
|
+
if (typeof chunkFileName === "string" && uniqueName && !chunkFileName.includes(uniqueName)) {
|
|
250
247
|
var suffix = "".concat(encodeName(uniqueName), "-[chunkhash].js");
|
|
251
|
-
output.chunkFilename
|
|
248
|
+
chain.output.chunkFilename(chunkFileName.replace(".js", suffix));
|
|
252
249
|
}
|
|
253
250
|
}
|
|
254
251
|
if (isDev && enableSSR && !isServer) {
|
|
255
|
-
|
|
256
|
-
crypto: false,
|
|
257
|
-
stream: false,
|
|
258
|
-
vm: false
|
|
259
|
-
});
|
|
252
|
+
chain.resolve.fallback.set("crypto", false).set("stream", false).set("vm", false);
|
|
260
253
|
}
|
|
261
254
|
if (((_modernjsConfig_deploy = modernjsConfig.deploy) === null || _modernjsConfig_deploy === void 0 ? void 0 : _modernjsConfig_deploy.microFrontend) && Object.keys(mfConfig.exposes || {}).length) {
|
|
262
|
-
|
|
263
|
-
bundlerConfig.optimization = {};
|
|
264
|
-
}
|
|
265
|
-
bundlerConfig.optimization.usedExports = false;
|
|
255
|
+
chain.optimization.usedExports(false);
|
|
266
256
|
}
|
|
267
257
|
}
|
|
268
258
|
var localIpv4 = "127.0.0.1";
|
|
@@ -290,33 +280,20 @@ var getIPV4 = function() {
|
|
|
290
280
|
};
|
|
291
281
|
return ipv4Interface.address;
|
|
292
282
|
};
|
|
293
|
-
var
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
};
|
|
302
|
-
var SHARED_SPLIT_CHUNK_MAP = {
|
|
303
|
-
react: SPLIT_CHUNK_MAP.REACT,
|
|
304
|
-
"react-dom": SPLIT_CHUNK_MAP.REACT,
|
|
305
|
-
"react-router": SPLIT_CHUNK_MAP.ROUTER,
|
|
306
|
-
"react-router-dom": SPLIT_CHUNK_MAP.ROUTER,
|
|
307
|
-
"@remix-run/router": SPLIT_CHUNK_MAP.ROUTER,
|
|
308
|
-
lodash: SPLIT_CHUNK_MAP.LODASH,
|
|
309
|
-
"lodash-es": SPLIT_CHUNK_MAP.LODASH,
|
|
310
|
-
antd: SPLIT_CHUNK_MAP.ANTD,
|
|
311
|
-
"@arco-design/web-react": SPLIT_CHUNK_MAP.ARCO,
|
|
312
|
-
"@douyinfe/semi-ui": SPLIT_CHUNK_MAP.SEMI,
|
|
313
|
-
axios: SPLIT_CHUNK_MAP.AXIOS
|
|
283
|
+
var isWebTarget = function(target) {
|
|
284
|
+
var WEB_TARGET = "web";
|
|
285
|
+
if (Array.isArray(target)) {
|
|
286
|
+
return target.includes(WEB_TARGET);
|
|
287
|
+
} else if (typeof target === "string") {
|
|
288
|
+
return target === WEB_TARGET;
|
|
289
|
+
}
|
|
290
|
+
return false;
|
|
314
291
|
};
|
|
315
292
|
export {
|
|
316
293
|
addMyTypes2Ignored,
|
|
317
294
|
getIPV4,
|
|
318
295
|
getMFConfig,
|
|
296
|
+
isWebTarget,
|
|
319
297
|
patchBundlerConfig,
|
|
320
|
-
patchIgnoreWarning,
|
|
321
298
|
patchMFConfig
|
|
322
299
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
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, getIPV4 } from "./utils";
|
|
5
5
|
var mfConfig = {
|
|
6
6
|
name: "host",
|
|
7
7
|
filename: "remoteEntry.js",
|
|
@@ -105,80 +105,3 @@ describe("patchMFConfig", /* @__PURE__ */ _async_to_generator(function() {
|
|
|
105
105
|
];
|
|
106
106
|
});
|
|
107
107
|
}));
|
|
108
|
-
describe("patchBundlerConfig", /* @__PURE__ */ _async_to_generator(function() {
|
|
109
|
-
return _ts_generator(this, function(_state) {
|
|
110
|
-
it("patchBundlerConfig: server", /* @__PURE__ */ _async_to_generator(function() {
|
|
111
|
-
var bundlerConfig, expectedConfig;
|
|
112
|
-
return _ts_generator(this, function(_state2) {
|
|
113
|
-
bundlerConfig = {
|
|
114
|
-
output: {
|
|
115
|
-
publicPath: "auto"
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
patchBundlerConfig({
|
|
119
|
-
bundlerType: "webpack",
|
|
120
|
-
bundlerConfig,
|
|
121
|
-
isServer: true,
|
|
122
|
-
modernjsConfig: {
|
|
123
|
-
server: {
|
|
124
|
-
ssr: {
|
|
125
|
-
mode: "stream"
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
},
|
|
129
|
-
mfConfig
|
|
130
|
-
});
|
|
131
|
-
expectedConfig = {
|
|
132
|
-
output: {
|
|
133
|
-
chunkLoadingGlobal: "chunk_host",
|
|
134
|
-
publicPath: "auto",
|
|
135
|
-
uniqueName: "host"
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
bundlerConfig === null || bundlerConfig === void 0 ? true : delete bundlerConfig.ignoreWarnings;
|
|
139
|
-
expect(bundlerConfig).toStrictEqual(expectedConfig);
|
|
140
|
-
return [
|
|
141
|
-
2
|
|
142
|
-
];
|
|
143
|
-
});
|
|
144
|
-
}));
|
|
145
|
-
it("patchBundlerConfig: client", /* @__PURE__ */ _async_to_generator(function() {
|
|
146
|
-
var bundlerConfig, expectedConfig;
|
|
147
|
-
return _ts_generator(this, function(_state2) {
|
|
148
|
-
bundlerConfig = {
|
|
149
|
-
output: {
|
|
150
|
-
publicPath: "auto"
|
|
151
|
-
}
|
|
152
|
-
};
|
|
153
|
-
patchBundlerConfig({
|
|
154
|
-
bundlerType: "webpack",
|
|
155
|
-
bundlerConfig,
|
|
156
|
-
isServer: false,
|
|
157
|
-
modernjsConfig: {
|
|
158
|
-
server: {
|
|
159
|
-
ssr: {
|
|
160
|
-
mode: "stream"
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
},
|
|
164
|
-
mfConfig
|
|
165
|
-
});
|
|
166
|
-
expectedConfig = {
|
|
167
|
-
output: {
|
|
168
|
-
chunkLoadingGlobal: "chunk_host",
|
|
169
|
-
publicPath: "auto",
|
|
170
|
-
uniqueName: "host"
|
|
171
|
-
}
|
|
172
|
-
};
|
|
173
|
-
bundlerConfig === null || bundlerConfig === void 0 ? true : delete bundlerConfig.ignoreWarnings;
|
|
174
|
-
expect(bundlerConfig).toStrictEqual(expectedConfig);
|
|
175
|
-
return [
|
|
176
|
-
2
|
|
177
|
-
];
|
|
178
|
-
});
|
|
179
|
-
}));
|
|
180
|
-
return [
|
|
181
|
-
2
|
|
182
|
-
];
|
|
183
|
-
});
|
|
184
|
-
}));
|