@module-federation/modern-js 0.0.0-next-20250221090527 → 0.0.0-next-20250221091229
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 +42 -18
- package/dist/cjs/cli/index.js +30 -24
- package/dist/cjs/cli/manifest.js +10 -9
- package/dist/cjs/cli/ssrPlugin.js +40 -40
- package/dist/cjs/cli/utils.js +62 -27
- package/dist/cjs/cli/utils.spec.js +60 -0
- package/dist/esm/cli/configPlugin.js +45 -18
- package/dist/esm/cli/index.js +35 -28
- package/dist/esm/cli/manifest.js +10 -9
- package/dist/esm/cli/ssrPlugin.js +44 -40
- package/dist/esm/cli/utils.js +60 -27
- package/dist/esm/cli/utils.spec.js +78 -1
- package/dist/esm-node/cli/configPlugin.js +41 -18
- package/dist/esm-node/cli/index.js +30 -24
- package/dist/esm-node/cli/manifest.js +10 -9
- package/dist/esm-node/cli/ssrPlugin.js +40 -39
- package/dist/esm-node/cli/utils.js +61 -27
- package/dist/esm-node/cli/utils.spec.js +61 -1
- package/dist/types/cli/configPlugin.d.ts +11 -1
- package/dist/types/cli/manifest.d.ts +1 -1
- package/dist/types/cli/ssrPlugin.d.ts +0 -1
- package/dist/types/cli/utils.d.ts +6 -5
- package/dist/types/types/index.d.ts +1 -1
- package/package.json +13 -13
|
@@ -6,6 +6,17 @@ function setEnv(enableSSR) {
|
|
|
6
6
|
process.env["MF_SSR_PRJ"] = "true";
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
|
+
function modifyBundlerConfig(options) {
|
|
10
|
+
const { mfConfig, config, isServer, modernjsConfig, remoteIpStrategy = "ipv4", bundlerType } = options;
|
|
11
|
+
patchMFConfig(mfConfig, isServer, remoteIpStrategy);
|
|
12
|
+
patchBundlerConfig({
|
|
13
|
+
bundlerType,
|
|
14
|
+
bundlerConfig: config,
|
|
15
|
+
isServer,
|
|
16
|
+
modernjsConfig,
|
|
17
|
+
mfConfig
|
|
18
|
+
});
|
|
19
|
+
}
|
|
9
20
|
const moduleFederationConfigPlugin = (userConfig) => ({
|
|
10
21
|
name: "@modern-js/plugin-module-federation-config",
|
|
11
22
|
pre: [
|
|
@@ -15,33 +26,17 @@ const moduleFederationConfigPlugin = (userConfig) => ({
|
|
|
15
26
|
"@modern-js/plugin-module-federation"
|
|
16
27
|
],
|
|
17
28
|
setup: async (api) => {
|
|
18
|
-
var _userConfig_userConfig, _modernjsConfig_server;
|
|
19
29
|
const modernjsConfig = api.getConfig();
|
|
20
30
|
const mfConfig = await getMFConfig(userConfig.originPluginOptions);
|
|
21
31
|
const csrConfig = userConfig.csrConfig || JSON.parse(JSON.stringify(mfConfig));
|
|
22
32
|
const ssrConfig = userConfig.ssrConfig || JSON.parse(JSON.stringify(mfConfig));
|
|
23
33
|
userConfig.ssrConfig = ssrConfig;
|
|
24
34
|
userConfig.csrConfig = csrConfig;
|
|
25
|
-
var _userConfig_userConfig_ssr;
|
|
26
|
-
const 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);
|
|
27
|
-
api.modifyBundlerChain((chain, { isProd, isServer }) => {
|
|
28
|
-
addMyTypes2Ignored(chain, isServer ? ssrConfig : csrConfig);
|
|
29
|
-
const targetMFConfig = isServer ? ssrConfig : csrConfig;
|
|
30
|
-
patchMFConfig(targetMFConfig, isServer, userConfig.remoteIpStrategy || "ipv4");
|
|
31
|
-
patchBundlerConfig({
|
|
32
|
-
// @ts-expect-error chain type is not correct
|
|
33
|
-
chain,
|
|
34
|
-
isServer,
|
|
35
|
-
modernjsConfig,
|
|
36
|
-
mfConfig,
|
|
37
|
-
enableSSR
|
|
38
|
-
});
|
|
39
|
-
userConfig.distOutputDir = chain.output.get("path") || path.resolve(process.cwd(), "dist");
|
|
40
|
-
});
|
|
41
35
|
api.config(() => {
|
|
42
|
-
var _modernjsConfig_source, _modernjsConfig_source1, _modernjsConfig_dev;
|
|
36
|
+
var _userConfig_userConfig, _modernjsConfig_server, _modernjsConfig_source, _modernjsConfig_source1, _modernjsConfig_dev;
|
|
43
37
|
const bundlerType = api.getAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
|
|
44
38
|
const ipv4 = getIPV4();
|
|
39
|
+
const 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);
|
|
45
40
|
if (userConfig.remoteIpStrategy === void 0) {
|
|
46
41
|
if (!enableSSR) {
|
|
47
42
|
userConfig.remoteIpStrategy = "inherit";
|
|
@@ -52,6 +47,33 @@ const moduleFederationConfigPlugin = (userConfig) => ({
|
|
|
52
47
|
var _modernjsConfig_source_enableAsyncEntry;
|
|
53
48
|
return {
|
|
54
49
|
tools: {
|
|
50
|
+
bundlerChain(chain, { isServer }) {
|
|
51
|
+
addMyTypes2Ignored(chain, isServer ? ssrConfig : csrConfig);
|
|
52
|
+
},
|
|
53
|
+
rspack(config, { isServer }) {
|
|
54
|
+
var _config_output;
|
|
55
|
+
modifyBundlerConfig({
|
|
56
|
+
bundlerType,
|
|
57
|
+
mfConfig: isServer ? ssrConfig : csrConfig,
|
|
58
|
+
config,
|
|
59
|
+
isServer,
|
|
60
|
+
modernjsConfig,
|
|
61
|
+
remoteIpStrategy: userConfig.remoteIpStrategy
|
|
62
|
+
});
|
|
63
|
+
userConfig.distOutputDir = ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.path) || path.resolve(process.cwd(), "dist");
|
|
64
|
+
},
|
|
65
|
+
webpack(config, { isServer }) {
|
|
66
|
+
var _config_output;
|
|
67
|
+
modifyBundlerConfig({
|
|
68
|
+
bundlerType,
|
|
69
|
+
mfConfig: isServer ? ssrConfig : csrConfig,
|
|
70
|
+
config,
|
|
71
|
+
isServer,
|
|
72
|
+
modernjsConfig,
|
|
73
|
+
remoteIpStrategy: userConfig.remoteIpStrategy
|
|
74
|
+
});
|
|
75
|
+
userConfig.distOutputDir = ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.path) || path.resolve(process.cwd(), "dist");
|
|
76
|
+
},
|
|
55
77
|
devServer: {
|
|
56
78
|
headers: {
|
|
57
79
|
"Access-Control-Allow-Origin": "*",
|
|
@@ -80,6 +102,7 @@ const moduleFederationConfigPlugin = (userConfig) => ({
|
|
|
80
102
|
var configPlugin_default = moduleFederationConfigPlugin;
|
|
81
103
|
export {
|
|
82
104
|
configPlugin_default as default,
|
|
105
|
+
modifyBundlerConfig,
|
|
83
106
|
moduleFederationConfigPlugin,
|
|
84
107
|
setEnv
|
|
85
108
|
};
|
|
@@ -17,31 +17,37 @@ const moduleFederationPlugin = (userConfig = {}) => {
|
|
|
17
17
|
name: "@modern-js/plugin-module-federation",
|
|
18
18
|
setup: async (api) => {
|
|
19
19
|
const modernjsConfig = api.getConfig();
|
|
20
|
-
api.
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
20
|
+
api.config(() => {
|
|
21
|
+
return {
|
|
22
|
+
tools: {
|
|
23
|
+
rspack(config, { isServer }) {
|
|
24
|
+
const browserPluginOptions = internalModernPluginOptions.csrConfig;
|
|
25
|
+
if (!isServer) {
|
|
26
|
+
var _config_plugins;
|
|
27
|
+
internalModernPluginOptions.browserPlugin = new RspackModuleFederationPlugin(browserPluginOptions);
|
|
28
|
+
(_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(internalModernPluginOptions.browserPlugin);
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
webpack(config, { isServer }) {
|
|
32
|
+
var _modernjsConfig_source;
|
|
33
|
+
const browserPluginOptions = internalModernPluginOptions.csrConfig;
|
|
34
|
+
if (!isServer) {
|
|
35
|
+
var _config_plugins;
|
|
36
|
+
internalModernPluginOptions.browserPlugin = new WebpackModuleFederationPlugin(browserPluginOptions);
|
|
37
|
+
(_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(internalModernPluginOptions.browserPlugin);
|
|
38
|
+
}
|
|
39
|
+
const enableAsyncEntry = (_modernjsConfig_source = modernjsConfig.source) === null || _modernjsConfig_source === void 0 ? void 0 : _modernjsConfig_source.enableAsyncEntry;
|
|
40
|
+
if (!enableAsyncEntry && browserPluginOptions.async !== false) {
|
|
41
|
+
var _config_plugins1;
|
|
42
|
+
const asyncBoundaryPluginOptions = typeof browserPluginOptions.async === "object" ? browserPluginOptions.async : {
|
|
43
|
+
eager: (module) => module && /\.federation/.test((module === null || module === void 0 ? void 0 : module.request) || ""),
|
|
44
|
+
excludeChunk: (chunk) => chunk.name === browserPluginOptions.name
|
|
45
|
+
};
|
|
46
|
+
(_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(new AsyncBoundaryPlugin(asyncBoundaryPluginOptions));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
43
49
|
}
|
|
44
|
-
}
|
|
50
|
+
};
|
|
45
51
|
});
|
|
46
52
|
},
|
|
47
53
|
usePlugins: [
|
|
@@ -1,25 +1,26 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import { fs } from "@modern-js/utils";
|
|
3
|
-
|
|
3
|
+
import { MODERN_JS_SERVER_DIR } from "../constant";
|
|
4
|
+
function mergeStats(browserStats, nodeStats) {
|
|
4
5
|
const ssrRemoteEntry = nodeStats.metaData.remoteEntry;
|
|
5
|
-
ssrRemoteEntry.path =
|
|
6
|
+
ssrRemoteEntry.path = MODERN_JS_SERVER_DIR;
|
|
6
7
|
browserStats.metaData.ssrRemoteEntry = ssrRemoteEntry;
|
|
7
8
|
return browserStats;
|
|
8
9
|
}
|
|
9
|
-
function mergeManifest(browserManifest, nodeManifest
|
|
10
|
+
function mergeManifest(browserManifest, nodeManifest) {
|
|
10
11
|
const ssrRemoteEntry = nodeManifest.metaData.remoteEntry;
|
|
11
|
-
ssrRemoteEntry.path =
|
|
12
|
+
ssrRemoteEntry.path = MODERN_JS_SERVER_DIR;
|
|
12
13
|
browserManifest.metaData.ssrRemoteEntry = ssrRemoteEntry;
|
|
13
14
|
return browserManifest;
|
|
14
15
|
}
|
|
15
|
-
function mergeStatsAndManifest(nodePlugin, browserPlugin
|
|
16
|
+
function mergeStatsAndManifest(nodePlugin, browserPlugin) {
|
|
16
17
|
const nodeResourceInfo = nodePlugin.statsResourceInfo;
|
|
17
18
|
const browserResourceInfo = browserPlugin.statsResourceInfo;
|
|
18
19
|
if (!browserResourceInfo || !nodeResourceInfo || !browserResourceInfo.stats || !nodeResourceInfo.stats || !browserResourceInfo.manifest || !nodeResourceInfo.manifest) {
|
|
19
20
|
throw new Error("can not get browserResourceInfo or nodeResourceInfo");
|
|
20
21
|
}
|
|
21
|
-
const mergedStats = mergeStats(browserResourceInfo.stats.stats, nodeResourceInfo.stats.stats
|
|
22
|
-
const mergedManifest = mergeManifest(browserResourceInfo.manifest.manifest, nodeResourceInfo.manifest.manifest
|
|
22
|
+
const mergedStats = mergeStats(browserResourceInfo.stats.stats, nodeResourceInfo.stats.stats);
|
|
23
|
+
const mergedManifest = mergeManifest(browserResourceInfo.manifest.manifest, nodeResourceInfo.manifest.manifest);
|
|
23
24
|
return {
|
|
24
25
|
mergedStats,
|
|
25
26
|
mergedStatsFilePath: browserResourceInfo.stats.filename,
|
|
@@ -27,8 +28,8 @@ function mergeStatsAndManifest(nodePlugin, browserPlugin, ssrDir) {
|
|
|
27
28
|
mergedManifestFilePath: browserResourceInfo.manifest.filename
|
|
28
29
|
};
|
|
29
30
|
}
|
|
30
|
-
function updateStatsAndManifest(nodePlugin, browserPlugin, outputDir
|
|
31
|
-
const { mergedStats, mergedStatsFilePath, mergedManifest, mergedManifestFilePath } = mergeStatsAndManifest(nodePlugin, browserPlugin
|
|
31
|
+
function updateStatsAndManifest(nodePlugin, browserPlugin, outputDir) {
|
|
32
|
+
const { mergedStats, mergedStatsFilePath, mergedManifest, mergedManifestFilePath } = mergeStatsAndManifest(nodePlugin, browserPlugin);
|
|
32
33
|
fs.writeFileSync(path.resolve(outputDir, mergedStatsFilePath), JSON.stringify(mergedStats, null, 2));
|
|
33
34
|
fs.writeFileSync(path.resolve(outputDir, mergedManifestFilePath), JSON.stringify(mergedManifest, null, 2));
|
|
34
35
|
}
|
|
@@ -5,13 +5,11 @@ import { ModuleFederationPlugin as RspackModuleFederationPlugin } from "@module-
|
|
|
5
5
|
import UniverseEntryChunkTrackerPlugin from "@module-federation/node/universe-entry-chunk-tracker-plugin";
|
|
6
6
|
import { updateStatsAndManifest } from "./manifest";
|
|
7
7
|
import { isDev } from "./constant";
|
|
8
|
-
import { MODERN_JS_SERVER_DIR } from "../constant";
|
|
9
8
|
import logger from "./logger";
|
|
10
9
|
function setEnv() {
|
|
11
10
|
process.env["MF_DISABLE_EMIT_STATS"] = "true";
|
|
12
11
|
process.env["MF_SSR_PRJ"] = "true";
|
|
13
12
|
}
|
|
14
|
-
const CHAIN_MF_PLUGIN_ID = "plugin-module-federation-server";
|
|
15
13
|
const moduleFederationSSRPlugin = (pluginOptions) => ({
|
|
16
14
|
name: "@modern-js/plugin-module-federation-ssr",
|
|
17
15
|
pre: [
|
|
@@ -21,10 +19,7 @@ const moduleFederationSSRPlugin = (pluginOptions) => ({
|
|
|
21
19
|
setup: async (api) => {
|
|
22
20
|
var _pluginOptions_userConfig, _modernjsConfig_server;
|
|
23
21
|
const modernjsConfig = api.getConfig();
|
|
24
|
-
|
|
25
|
-
const 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);
|
|
26
|
-
let csrOutputPath = "";
|
|
27
|
-
let ssrOutputPath = "";
|
|
22
|
+
const enableSSR = ((_pluginOptions_userConfig = pluginOptions.userConfig) === null || _pluginOptions_userConfig === void 0 ? void 0 : _pluginOptions_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);
|
|
28
23
|
if (!enableSSR) {
|
|
29
24
|
return;
|
|
30
25
|
}
|
|
@@ -46,39 +41,33 @@ const moduleFederationSSRPlugin = (pluginOptions) => ({
|
|
|
46
41
|
plugins
|
|
47
42
|
};
|
|
48
43
|
});
|
|
49
|
-
api.modifyBundlerChain((chain, { isServer }) => {
|
|
50
|
-
const bundlerType = api.getAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
|
|
51
|
-
const MFPlugin = bundlerType === "webpack" ? ModuleFederationPlugin : RspackModuleFederationPlugin;
|
|
52
|
-
if (isServer) {
|
|
53
|
-
if (!chain.plugins.has(CHAIN_MF_PLUGIN_ID)) {
|
|
54
|
-
chain.plugin(CHAIN_MF_PLUGIN_ID).use(MFPlugin, [
|
|
55
|
-
pluginOptions.ssrConfig
|
|
56
|
-
]).init((Plugin, args) => {
|
|
57
|
-
pluginOptions.nodePlugin = new Plugin(args[0]);
|
|
58
|
-
return pluginOptions.nodePlugin;
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
if (isServer) {
|
|
63
|
-
chain.target("async-node");
|
|
64
|
-
if (isDev) {
|
|
65
|
-
chain.plugin("UniverseEntryChunkTrackerPlugin").use(UniverseEntryChunkTrackerPlugin);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
if (isDev && !isServer) {
|
|
69
|
-
chain.externals({
|
|
70
|
-
"@module-federation/node/utils": "NOT_USED_IN_BROWSER"
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
if (isServer) {
|
|
74
|
-
ssrOutputPath = chain.output.get("path") || path.resolve(process.cwd(), `dist/${MODERN_JS_SERVER_DIR}`);
|
|
75
|
-
} else {
|
|
76
|
-
csrOutputPath = chain.output.get("path") || path.resolve(process.cwd(), "dist");
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
44
|
api.config(() => {
|
|
80
45
|
return {
|
|
81
46
|
tools: {
|
|
47
|
+
rspack(config, { isServer }) {
|
|
48
|
+
if (isServer) {
|
|
49
|
+
if (!pluginOptions.nodePlugin) {
|
|
50
|
+
var _config_plugins;
|
|
51
|
+
pluginOptions.nodePlugin = new RspackModuleFederationPlugin(pluginOptions.ssrConfig);
|
|
52
|
+
(_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(pluginOptions.nodePlugin);
|
|
53
|
+
}
|
|
54
|
+
} else {
|
|
55
|
+
var _config_output;
|
|
56
|
+
pluginOptions.distOutputDir = pluginOptions.distOutputDir || ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.path) || path.resolve(process.cwd(), "dist");
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
webpack(config, { isServer }) {
|
|
60
|
+
if (isServer) {
|
|
61
|
+
if (!pluginOptions.nodePlugin) {
|
|
62
|
+
var _config_plugins;
|
|
63
|
+
pluginOptions.nodePlugin = new ModuleFederationPlugin(pluginOptions.ssrConfig);
|
|
64
|
+
(_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(pluginOptions.nodePlugin);
|
|
65
|
+
}
|
|
66
|
+
} else {
|
|
67
|
+
var _config_output;
|
|
68
|
+
pluginOptions.distOutputDir = pluginOptions.distOutputDir || ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.path) || path.resolve(process.cwd(), "dist");
|
|
69
|
+
}
|
|
70
|
+
},
|
|
82
71
|
devServer: {
|
|
83
72
|
before: [
|
|
84
73
|
(req, res, next) => {
|
|
@@ -104,23 +93,35 @@ const moduleFederationSSRPlugin = (pluginOptions) => ({
|
|
|
104
93
|
}
|
|
105
94
|
}
|
|
106
95
|
]
|
|
96
|
+
},
|
|
97
|
+
bundlerChain(chain, { isServer }) {
|
|
98
|
+
if (isServer) {
|
|
99
|
+
chain.target("async-node");
|
|
100
|
+
if (isDev) {
|
|
101
|
+
chain.plugin("UniverseEntryChunkTrackerPlugin").use(UniverseEntryChunkTrackerPlugin);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (isDev && !isServer) {
|
|
105
|
+
chain.externals({
|
|
106
|
+
"@module-federation/node/utils": "NOT_USED_IN_BROWSER"
|
|
107
|
+
});
|
|
108
|
+
}
|
|
107
109
|
}
|
|
108
110
|
}
|
|
109
111
|
};
|
|
110
112
|
});
|
|
111
113
|
api.onAfterBuild(() => {
|
|
112
114
|
const { nodePlugin, browserPlugin, distOutputDir } = pluginOptions;
|
|
113
|
-
updateStatsAndManifest(nodePlugin, browserPlugin, distOutputDir
|
|
115
|
+
updateStatsAndManifest(nodePlugin, browserPlugin, distOutputDir);
|
|
114
116
|
});
|
|
115
117
|
api.onDevCompileDone(() => {
|
|
116
118
|
const { nodePlugin, browserPlugin, distOutputDir } = pluginOptions;
|
|
117
|
-
updateStatsAndManifest(nodePlugin, browserPlugin, distOutputDir
|
|
119
|
+
updateStatsAndManifest(nodePlugin, browserPlugin, distOutputDir);
|
|
118
120
|
});
|
|
119
121
|
}
|
|
120
122
|
});
|
|
121
123
|
var ssrPlugin_default = moduleFederationSSRPlugin;
|
|
122
124
|
export {
|
|
123
|
-
CHAIN_MF_PLUGIN_ID,
|
|
124
125
|
ssrPlugin_default as default,
|
|
125
126
|
moduleFederationSSRPlugin,
|
|
126
127
|
setEnv
|
|
@@ -135,20 +135,19 @@ const patchMFConfig = (mfConfig, isServer, remoteIpStrategy) => {
|
|
|
135
135
|
mfConfig.dev = false;
|
|
136
136
|
return mfConfig;
|
|
137
137
|
};
|
|
138
|
-
function patchIgnoreWarning(
|
|
139
|
-
|
|
138
|
+
function patchIgnoreWarning(bundlerConfig) {
|
|
139
|
+
bundlerConfig.ignoreWarnings = bundlerConfig.ignoreWarnings || [];
|
|
140
140
|
const ignoredMsgs = [
|
|
141
141
|
"external script",
|
|
142
142
|
"process.env.WS_NO_BUFFER_UTIL",
|
|
143
143
|
`Can't resolve 'utf-8-validate`
|
|
144
144
|
];
|
|
145
|
-
ignoreWarnings.push((warning) => {
|
|
145
|
+
bundlerConfig.ignoreWarnings.push((warning) => {
|
|
146
146
|
if (ignoredMsgs.some((msg) => warning.message.includes(msg))) {
|
|
147
147
|
return true;
|
|
148
148
|
}
|
|
149
149
|
return false;
|
|
150
150
|
});
|
|
151
|
-
chain.ignoreWarnings(ignoreWarnings);
|
|
152
151
|
}
|
|
153
152
|
function addMyTypes2Ignored(chain, mfConfig) {
|
|
154
153
|
const watchOptions = chain.get("watchOptions");
|
|
@@ -187,43 +186,55 @@ function addMyTypes2Ignored(chain, mfConfig) {
|
|
|
187
186
|
});
|
|
188
187
|
}
|
|
189
188
|
function patchBundlerConfig(options) {
|
|
190
|
-
var _modernjsConfig_deploy;
|
|
191
|
-
const {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
189
|
+
var _modernjsConfig_server, _bundlerConfig_optimization, _bundlerConfig_optimization1, _bundlerConfig_output, _modernjsConfig_deploy;
|
|
190
|
+
const { bundlerConfig, modernjsConfig, isServer, mfConfig, bundlerType } = options;
|
|
191
|
+
const enableSSR = Boolean((_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
|
|
192
|
+
(_bundlerConfig_optimization = bundlerConfig.optimization) === null || _bundlerConfig_optimization === void 0 ? true : delete _bundlerConfig_optimization.runtimeChunk;
|
|
193
|
+
patchIgnoreWarning(bundlerConfig);
|
|
194
|
+
if (bundlerConfig.output) {
|
|
195
|
+
var _bundlerConfig_output1, _bundlerConfig_output2;
|
|
196
|
+
if (!((_bundlerConfig_output1 = bundlerConfig.output) === null || _bundlerConfig_output1 === void 0 ? void 0 : _bundlerConfig_output1.chunkLoadingGlobal)) {
|
|
197
|
+
bundlerConfig.output.chunkLoadingGlobal = `chunk_${mfConfig.name}`;
|
|
198
|
+
}
|
|
199
|
+
if (!((_bundlerConfig_output2 = bundlerConfig.output) === null || _bundlerConfig_output2 === void 0 ? void 0 : _bundlerConfig_output2.uniqueName)) {
|
|
200
|
+
bundlerConfig.output.uniqueName = mfConfig.name;
|
|
201
|
+
}
|
|
199
202
|
}
|
|
200
|
-
const splitChunkConfig = chain.optimization.splitChunks.entries();
|
|
201
203
|
if (!isServer) {
|
|
202
|
-
autoDeleteSplitChunkCacheGroups(mfConfig,
|
|
204
|
+
autoDeleteSplitChunkCacheGroups(mfConfig, bundlerConfig);
|
|
203
205
|
}
|
|
204
|
-
if (!isServer && enableSSR &&
|
|
205
|
-
|
|
206
|
+
if (!isServer && enableSSR && typeof ((_bundlerConfig_optimization1 = bundlerConfig.optimization) === null || _bundlerConfig_optimization1 === void 0 ? void 0 : _bundlerConfig_optimization1.splitChunks) === "object" && bundlerConfig.optimization.splitChunks.cacheGroups) {
|
|
207
|
+
bundlerConfig.optimization.splitChunks.chunks = "async";
|
|
206
208
|
logger.warn(`splitChunks.chunks = async is not allowed with stream SSR mode, it will auto changed to "async"`);
|
|
207
209
|
}
|
|
208
|
-
if (isDev &&
|
|
209
|
-
var _modernjsConfig_dev,
|
|
210
|
-
const port = ((_modernjsConfig_dev = modernjsConfig.dev) === null || _modernjsConfig_dev === void 0 ? void 0 : _modernjsConfig_dev.port) || ((
|
|
210
|
+
if (isDev && ((_bundlerConfig_output = bundlerConfig.output) === null || _bundlerConfig_output === void 0 ? void 0 : _bundlerConfig_output.publicPath) === "auto") {
|
|
211
|
+
var _modernjsConfig_dev, _modernjsConfig_server1;
|
|
212
|
+
const port = ((_modernjsConfig_dev = modernjsConfig.dev) === null || _modernjsConfig_dev === void 0 ? void 0 : _modernjsConfig_dev.port) || ((_modernjsConfig_server1 = modernjsConfig.server) === null || _modernjsConfig_server1 === void 0 ? void 0 : _modernjsConfig_server1.port) || 8080;
|
|
211
213
|
const publicPath = `http://localhost:${port}/`;
|
|
212
|
-
|
|
214
|
+
bundlerConfig.output.publicPath = publicPath;
|
|
213
215
|
}
|
|
214
216
|
if (isServer && enableSSR) {
|
|
215
|
-
const
|
|
216
|
-
const
|
|
217
|
-
|
|
217
|
+
const { output } = bundlerConfig;
|
|
218
|
+
const uniqueName = mfConfig.name || (output === null || output === void 0 ? void 0 : output.uniqueName);
|
|
219
|
+
const chunkFileName = output === null || output === void 0 ? void 0 : output.chunkFilename;
|
|
220
|
+
if (output && typeof chunkFileName === "string" && uniqueName && !chunkFileName.includes(uniqueName)) {
|
|
218
221
|
const suffix = `${encodeName(uniqueName)}-[chunkhash].js`;
|
|
219
|
-
|
|
222
|
+
output.chunkFilename = chunkFileName.replace(".js", suffix);
|
|
220
223
|
}
|
|
221
224
|
}
|
|
222
225
|
if (isDev && enableSSR && !isServer) {
|
|
223
|
-
|
|
226
|
+
bundlerConfig.resolve.fallback = {
|
|
227
|
+
...bundlerConfig.resolve.fallback,
|
|
228
|
+
crypto: false,
|
|
229
|
+
stream: false,
|
|
230
|
+
vm: false
|
|
231
|
+
};
|
|
224
232
|
}
|
|
225
233
|
if (((_modernjsConfig_deploy = modernjsConfig.deploy) === null || _modernjsConfig_deploy === void 0 ? void 0 : _modernjsConfig_deploy.microFrontend) && Object.keys(mfConfig.exposes || {}).length) {
|
|
226
|
-
|
|
234
|
+
if (!bundlerConfig.optimization) {
|
|
235
|
+
bundlerConfig.optimization = {};
|
|
236
|
+
}
|
|
237
|
+
bundlerConfig.optimization.usedExports = false;
|
|
227
238
|
}
|
|
228
239
|
}
|
|
229
240
|
const localIpv4 = "127.0.0.1";
|
|
@@ -251,10 +262,33 @@ const getIPV4 = () => {
|
|
|
251
262
|
};
|
|
252
263
|
return ipv4Interface.address;
|
|
253
264
|
};
|
|
265
|
+
const SPLIT_CHUNK_MAP = {
|
|
266
|
+
REACT: "react",
|
|
267
|
+
ROUTER: "router",
|
|
268
|
+
LODASH: "lib-lodash",
|
|
269
|
+
ANTD: "lib-antd",
|
|
270
|
+
ARCO: "lib-arco",
|
|
271
|
+
SEMI: "lib-semi",
|
|
272
|
+
AXIOS: "lib-axios"
|
|
273
|
+
};
|
|
274
|
+
const SHARED_SPLIT_CHUNK_MAP = {
|
|
275
|
+
react: SPLIT_CHUNK_MAP.REACT,
|
|
276
|
+
"react-dom": SPLIT_CHUNK_MAP.REACT,
|
|
277
|
+
"react-router": SPLIT_CHUNK_MAP.ROUTER,
|
|
278
|
+
"react-router-dom": SPLIT_CHUNK_MAP.ROUTER,
|
|
279
|
+
"@remix-run/router": SPLIT_CHUNK_MAP.ROUTER,
|
|
280
|
+
lodash: SPLIT_CHUNK_MAP.LODASH,
|
|
281
|
+
"lodash-es": SPLIT_CHUNK_MAP.LODASH,
|
|
282
|
+
antd: SPLIT_CHUNK_MAP.ANTD,
|
|
283
|
+
"@arco-design/web-react": SPLIT_CHUNK_MAP.ARCO,
|
|
284
|
+
"@douyinfe/semi-ui": SPLIT_CHUNK_MAP.SEMI,
|
|
285
|
+
axios: SPLIT_CHUNK_MAP.AXIOS
|
|
286
|
+
};
|
|
254
287
|
export {
|
|
255
288
|
addMyTypes2Ignored,
|
|
256
289
|
getIPV4,
|
|
257
290
|
getMFConfig,
|
|
258
291
|
patchBundlerConfig,
|
|
292
|
+
patchIgnoreWarning,
|
|
259
293
|
patchMFConfig
|
|
260
294
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { it, expect, describe } from "vitest";
|
|
2
|
-
import { patchMFConfig, getIPV4 } from "./utils";
|
|
2
|
+
import { patchMFConfig, patchBundlerConfig, getIPV4 } from "./utils";
|
|
3
3
|
const mfConfig = {
|
|
4
4
|
name: "host",
|
|
5
5
|
filename: "remoteEntry.js",
|
|
@@ -86,3 +86,63 @@ describe("patchMFConfig", async () => {
|
|
|
86
86
|
});
|
|
87
87
|
});
|
|
88
88
|
});
|
|
89
|
+
describe("patchBundlerConfig", async () => {
|
|
90
|
+
it("patchBundlerConfig: server", async () => {
|
|
91
|
+
const bundlerConfig = {
|
|
92
|
+
output: {
|
|
93
|
+
publicPath: "auto"
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
patchBundlerConfig({
|
|
97
|
+
bundlerType: "webpack",
|
|
98
|
+
bundlerConfig,
|
|
99
|
+
isServer: true,
|
|
100
|
+
modernjsConfig: {
|
|
101
|
+
server: {
|
|
102
|
+
ssr: {
|
|
103
|
+
mode: "stream"
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
mfConfig
|
|
108
|
+
});
|
|
109
|
+
const expectedConfig = {
|
|
110
|
+
output: {
|
|
111
|
+
chunkLoadingGlobal: "chunk_host",
|
|
112
|
+
publicPath: "auto",
|
|
113
|
+
uniqueName: "host"
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
bundlerConfig === null || bundlerConfig === void 0 ? true : delete bundlerConfig.ignoreWarnings;
|
|
117
|
+
expect(bundlerConfig).toStrictEqual(expectedConfig);
|
|
118
|
+
});
|
|
119
|
+
it("patchBundlerConfig: client", async () => {
|
|
120
|
+
const bundlerConfig = {
|
|
121
|
+
output: {
|
|
122
|
+
publicPath: "auto"
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
patchBundlerConfig({
|
|
126
|
+
bundlerType: "webpack",
|
|
127
|
+
bundlerConfig,
|
|
128
|
+
isServer: false,
|
|
129
|
+
modernjsConfig: {
|
|
130
|
+
server: {
|
|
131
|
+
ssr: {
|
|
132
|
+
mode: "stream"
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
mfConfig
|
|
137
|
+
});
|
|
138
|
+
const expectedConfig = {
|
|
139
|
+
output: {
|
|
140
|
+
chunkLoadingGlobal: "chunk_host",
|
|
141
|
+
publicPath: "auto",
|
|
142
|
+
uniqueName: "host"
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
bundlerConfig === null || bundlerConfig === void 0 ? true : delete bundlerConfig.ignoreWarnings;
|
|
146
|
+
expect(bundlerConfig).toStrictEqual(expectedConfig);
|
|
147
|
+
});
|
|
148
|
+
});
|
|
@@ -1,5 +1,15 @@
|
|
|
1
|
-
import type { CliPluginFuture, AppTools } from '@modern-js/app-tools';
|
|
1
|
+
import type { CliPluginFuture, AppTools, UserConfig, Bundler } from '@modern-js/app-tools';
|
|
2
|
+
import type { BundlerConfig } from '../interfaces/bundler';
|
|
2
3
|
import type { InternalModernPluginOptions } from '../types';
|
|
4
|
+
import { moduleFederationPlugin } from '@module-federation/sdk';
|
|
3
5
|
export declare function setEnv(enableSSR: boolean): void;
|
|
6
|
+
export declare function modifyBundlerConfig<T extends Bundler>(options: {
|
|
7
|
+
bundlerType: Bundler;
|
|
8
|
+
mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions;
|
|
9
|
+
config: BundlerConfig<T>;
|
|
10
|
+
isServer: boolean;
|
|
11
|
+
modernjsConfig: UserConfig<AppTools>;
|
|
12
|
+
remoteIpStrategy?: 'ipv4' | 'inherit';
|
|
13
|
+
}): void;
|
|
4
14
|
export declare const moduleFederationConfigPlugin: (userConfig: InternalModernPluginOptions) => CliPluginFuture<AppTools>;
|
|
5
15
|
export default moduleFederationConfigPlugin;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { BundlerPlugin } from '../types';
|
|
2
|
-
export declare function updateStatsAndManifest(nodePlugin: BundlerPlugin, browserPlugin: BundlerPlugin, outputDir: string
|
|
2
|
+
export declare function updateStatsAndManifest(nodePlugin: BundlerPlugin, browserPlugin: BundlerPlugin, outputDir: string): void;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { CliPluginFuture, AppTools } from '@modern-js/app-tools';
|
|
2
2
|
import type { InternalModernPluginOptions } from '../types';
|
|
3
3
|
export declare function setEnv(): void;
|
|
4
|
-
export declare const CHAIN_MF_PLUGIN_ID = "plugin-module-federation-server";
|
|
5
4
|
export declare const moduleFederationSSRPlugin: (pluginOptions: Required<InternalModernPluginOptions>) => CliPluginFuture<AppTools>;
|
|
6
5
|
export default moduleFederationSSRPlugin;
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { moduleFederationPlugin } from '@module-federation/sdk';
|
|
2
2
|
import { PluginOptions } from '../types';
|
|
3
|
-
import type { BundlerChainConfig } from '../interfaces/bundler';
|
|
4
|
-
import type { webpack, UserConfig, AppTools, Rspack } from '@modern-js/app-tools';
|
|
3
|
+
import type { BundlerConfig, BundlerChainConfig } from '../interfaces/bundler';
|
|
4
|
+
import type { webpack, UserConfig, AppTools, Rspack, Bundler } from '@modern-js/app-tools';
|
|
5
5
|
export type ConfigType<T> = T extends 'webpack' ? webpack.Configuration : T extends 'rspack' ? Rspack.Configuration : never;
|
|
6
6
|
export declare const getMFConfig: (userConfig: PluginOptions) => Promise<moduleFederationPlugin.ModuleFederationPluginOptions>;
|
|
7
7
|
export declare const patchMFConfig: (mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions, isServer: boolean, remoteIpStrategy?: "ipv4" | "inherit") => moduleFederationPlugin.ModuleFederationPluginOptions;
|
|
8
|
+
export declare function patchIgnoreWarning<T extends Bundler>(bundlerConfig: BundlerConfig<T>): void;
|
|
8
9
|
export declare function addMyTypes2Ignored(chain: BundlerChainConfig, mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions): void;
|
|
9
|
-
export declare function patchBundlerConfig(options: {
|
|
10
|
-
|
|
10
|
+
export declare function patchBundlerConfig<T extends Bundler>(options: {
|
|
11
|
+
bundlerConfig: BundlerConfig<T>;
|
|
11
12
|
isServer: boolean;
|
|
12
13
|
modernjsConfig: UserConfig<AppTools>;
|
|
14
|
+
bundlerType: Bundler;
|
|
13
15
|
mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions;
|
|
14
|
-
enableSSR: boolean;
|
|
15
16
|
}): void;
|
|
16
17
|
export declare const getIPV4: () => string;
|
|
@@ -4,7 +4,7 @@ import type { ModuleFederationPlugin as RspackModuleFederationPlugin } from '@mo
|
|
|
4
4
|
export interface PluginOptions {
|
|
5
5
|
config?: moduleFederationPlugin.ModuleFederationPluginOptions;
|
|
6
6
|
configPath?: string;
|
|
7
|
-
ssr?:
|
|
7
|
+
ssr?: false;
|
|
8
8
|
remoteIpStrategy?: 'ipv4' | 'inherit';
|
|
9
9
|
}
|
|
10
10
|
export interface InternalModernPluginOptions {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/modern-js",
|
|
3
|
-
"version": "0.0.0-next-
|
|
3
|
+
"version": "0.0.0-next-20250221091229",
|
|
4
4
|
"files": [
|
|
5
5
|
"dist/",
|
|
6
6
|
"types.d.ts",
|
|
@@ -84,23 +84,23 @@
|
|
|
84
84
|
"author": "hanric <hanric.zhang@gmail.com>",
|
|
85
85
|
"license": "MIT",
|
|
86
86
|
"dependencies": {
|
|
87
|
-
"@modern-js/node-bundle-require": "2.64.
|
|
88
|
-
"@modern-js/utils": "2.64.
|
|
87
|
+
"@modern-js/node-bundle-require": "2.64.0",
|
|
88
|
+
"@modern-js/utils": "2.64.0",
|
|
89
89
|
"@swc/helpers": "0.5.13",
|
|
90
90
|
"node-fetch": "~3.3.0",
|
|
91
91
|
"react-error-boundary": "4.1.2",
|
|
92
|
-
"@module-federation/rsbuild-plugin": "0.0.0-next-
|
|
93
|
-
"@module-federation/enhanced": "0.0.0-next-
|
|
94
|
-
"@module-federation/node": "0.0.0-next-
|
|
95
|
-
"@module-federation/sdk": "0.0.0-next-
|
|
92
|
+
"@module-federation/rsbuild-plugin": "0.0.0-next-20250221091229",
|
|
93
|
+
"@module-federation/enhanced": "0.0.0-next-20250221091229",
|
|
94
|
+
"@module-federation/node": "0.0.0-next-20250221091229",
|
|
95
|
+
"@module-federation/sdk": "0.0.0-next-20250221091229"
|
|
96
96
|
},
|
|
97
97
|
"devDependencies": {
|
|
98
|
-
"@modern-js/app-tools": "2.64.
|
|
99
|
-
"@modern-js/core": "2.64.
|
|
100
|
-
"@modern-js/module-tools": "2.64.
|
|
101
|
-
"@modern-js/runtime": "2.64.
|
|
102
|
-
"@modern-js/tsconfig": "2.64.
|
|
103
|
-
"@module-federation/manifest": "0.0.0-next-
|
|
98
|
+
"@modern-js/app-tools": "2.64.0",
|
|
99
|
+
"@modern-js/core": "2.64.0",
|
|
100
|
+
"@modern-js/module-tools": "2.64.0",
|
|
101
|
+
"@modern-js/runtime": "2.64.0",
|
|
102
|
+
"@modern-js/tsconfig": "2.64.0",
|
|
103
|
+
"@module-federation/manifest": "0.0.0-next-20250221091229"
|
|
104
104
|
},
|
|
105
105
|
"peerDependencies": {
|
|
106
106
|
"react": ">=17",
|