@module-federation/modern-js 0.0.0-next-20250401085244 → 0.0.0-next-20250403063151
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 +243 -25
- package/dist/cjs/cli/{utils.spec.js → configPlugin.spec.js} +3 -2
- package/dist/cjs/cli/manifest.js +13 -9
- package/dist/cjs/cli/ssrPlugin.js +49 -10
- package/dist/cjs/cli/utils.js +0 -235
- package/dist/cjs/constant.js +0 -3
- package/dist/esm/cli/configPlugin.js +262 -22
- package/dist/esm/cli/{utils.spec.js → configPlugin.spec.js} +2 -1
- package/dist/esm/cli/manifest.js +13 -9
- package/dist/esm/cli/ssrPlugin.js +51 -11
- package/dist/esm/cli/utils.js +0 -260
- package/dist/esm/constant.js +0 -2
- package/dist/esm-node/cli/configPlugin.js +236 -22
- package/dist/esm-node/cli/{utils.spec.js → configPlugin.spec.js} +2 -1
- package/dist/esm-node/cli/manifest.js +13 -9
- package/dist/esm-node/cli/ssrPlugin.js +49 -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/package.json +8 -7
- /package/dist/types/cli/{utils.spec.d.ts → configPlugin.spec.d.ts} +0 -0
|
@@ -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
|
const 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
|
const 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
|
const nodeResourceInfo = nodePlugin.statsResourceInfo;
|
|
17
21
|
const 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
|
-
const mergedStats = mergeStats(browserResourceInfo.stats.stats, nodeResourceInfo.stats.stats
|
|
22
|
-
const mergedManifest = mergeManifest(browserResourceInfo.manifest.manifest, nodeResourceInfo.manifest.manifest
|
|
25
|
+
const mergedStats = mergeStats(browserResourceInfo.stats.stats, nodeResourceInfo.stats.stats);
|
|
26
|
+
const 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
|
-
const { mergedStats, mergedStatsFilePath, mergedManifest, mergedManifestFilePath } = mergeStatsAndManifest(nodePlugin, browserPlugin
|
|
34
|
+
function updateStatsAndManifest(nodePlugin, browserPlugin, outputDir) {
|
|
35
|
+
const { mergedStats, mergedStatsFilePath, mergedManifest, mergedManifestFilePath } = mergeStatsAndManifest(nodePlugin, browserPlugin);
|
|
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
|
}
|
|
@@ -5,7 +5,6 @@ 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
|
import { isWebTarget, skipByTarget } from "./utils";
|
|
11
10
|
function setEnv() {
|
|
@@ -13,6 +12,50 @@ function setEnv() {
|
|
|
13
12
|
process.env["MF_SSR_PRJ"] = "true";
|
|
14
13
|
}
|
|
15
14
|
const CHAIN_MF_PLUGIN_ID = "plugin-module-federation-server";
|
|
15
|
+
const mfSSRRsbuildPlugin = (pluginOptions) => {
|
|
16
|
+
return {
|
|
17
|
+
name: "@modern-js/plugin-mf-post-config",
|
|
18
|
+
pre: [
|
|
19
|
+
"@modern-js/builder-plugin-ssr"
|
|
20
|
+
],
|
|
21
|
+
setup(api) {
|
|
22
|
+
if (pluginOptions.csrConfig.getPublicPath) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
let csrOutputPath = "";
|
|
26
|
+
let ssrOutputPath = "";
|
|
27
|
+
let ssrEnv = "";
|
|
28
|
+
api.modifyEnvironmentConfig((config, { name }) => {
|
|
29
|
+
const target = config.output.target;
|
|
30
|
+
if (skipByTarget(target)) {
|
|
31
|
+
return config;
|
|
32
|
+
}
|
|
33
|
+
if (isWebTarget(target)) {
|
|
34
|
+
csrOutputPath = config.output.distPath.root;
|
|
35
|
+
} else {
|
|
36
|
+
ssrOutputPath = config.output.distPath.root;
|
|
37
|
+
ssrEnv = name;
|
|
38
|
+
}
|
|
39
|
+
return config;
|
|
40
|
+
});
|
|
41
|
+
const modifySSRPublicPath = (config, utils) => {
|
|
42
|
+
if (ssrEnv !== utils.environment.name) {
|
|
43
|
+
return config;
|
|
44
|
+
}
|
|
45
|
+
config.output.publicPath = `${config.output.publicPath}${path.relative(csrOutputPath, ssrOutputPath)}/`;
|
|
46
|
+
return config;
|
|
47
|
+
};
|
|
48
|
+
api.modifyWebpackConfig((config, utils) => {
|
|
49
|
+
modifySSRPublicPath(config, utils);
|
|
50
|
+
return config;
|
|
51
|
+
});
|
|
52
|
+
api.modifyRspackConfig((config, utils) => {
|
|
53
|
+
modifySSRPublicPath(config, utils);
|
|
54
|
+
return config;
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
};
|
|
16
59
|
const moduleFederationSSRPlugin = (pluginOptions) => ({
|
|
17
60
|
name: "@modern-js/plugin-module-federation-ssr",
|
|
18
61
|
pre: [
|
|
@@ -24,8 +67,6 @@ const moduleFederationSSRPlugin = (pluginOptions) => ({
|
|
|
24
67
|
const modernjsConfig = api.getConfig();
|
|
25
68
|
var _pluginOptions_userConfig_ssr;
|
|
26
69
|
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);
|
|
27
|
-
let csrOutputPath = "";
|
|
28
|
-
let ssrOutputPath = "";
|
|
29
70
|
if (!enableSSR) {
|
|
30
71
|
return;
|
|
31
72
|
}
|
|
@@ -76,14 +117,12 @@ const moduleFederationSSRPlugin = (pluginOptions) => ({
|
|
|
76
117
|
"@module-federation/node/utils": "NOT_USED_IN_BROWSER"
|
|
77
118
|
});
|
|
78
119
|
}
|
|
79
|
-
if (!isWeb) {
|
|
80
|
-
ssrOutputPath = chain.output.get("path") || path.resolve(process.cwd(), `dist/${MODERN_JS_SERVER_DIR}`);
|
|
81
|
-
} else {
|
|
82
|
-
csrOutputPath = chain.output.get("path") || path.resolve(process.cwd(), "dist");
|
|
83
|
-
}
|
|
84
120
|
});
|
|
85
121
|
api.config(() => {
|
|
86
122
|
return {
|
|
123
|
+
builderPlugins: [
|
|
124
|
+
mfSSRRsbuildPlugin(pluginOptions)
|
|
125
|
+
],
|
|
87
126
|
tools: {
|
|
88
127
|
devServer: {
|
|
89
128
|
before: [
|
|
@@ -116,11 +155,11 @@ const moduleFederationSSRPlugin = (pluginOptions) => ({
|
|
|
116
155
|
});
|
|
117
156
|
api.onAfterBuild(() => {
|
|
118
157
|
const { nodePlugin, browserPlugin, distOutputDir } = pluginOptions;
|
|
119
|
-
updateStatsAndManifest(nodePlugin, browserPlugin, distOutputDir
|
|
158
|
+
updateStatsAndManifest(nodePlugin, browserPlugin, distOutputDir);
|
|
120
159
|
});
|
|
121
160
|
api.onDevCompileDone(() => {
|
|
122
161
|
const { nodePlugin, browserPlugin, distOutputDir } = pluginOptions;
|
|
123
|
-
updateStatsAndManifest(nodePlugin, browserPlugin, distOutputDir
|
|
162
|
+
updateStatsAndManifest(nodePlugin, browserPlugin, distOutputDir);
|
|
124
163
|
});
|
|
125
164
|
}
|
|
126
165
|
});
|
|
@@ -1,231 +1,4 @@
|
|
|
1
1
|
import os from "os";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import { encodeName } from "@module-federation/sdk";
|
|
4
|
-
import { bundle } from "@modern-js/node-bundle-require";
|
|
5
|
-
import { LOCALHOST, PLUGIN_IDENTIFIER } from "../constant";
|
|
6
|
-
import logger from "./logger";
|
|
7
|
-
import { autoDeleteSplitChunkCacheGroups } from "@module-federation/rsbuild-plugin/utils";
|
|
8
|
-
const defaultPath = path.resolve(process.cwd(), "module-federation.config.ts");
|
|
9
|
-
const isDev = process.env.NODE_ENV === "development";
|
|
10
|
-
const getMFConfig = async (userConfig) => {
|
|
11
|
-
const { config, configPath } = userConfig;
|
|
12
|
-
if (config) {
|
|
13
|
-
return config;
|
|
14
|
-
}
|
|
15
|
-
const mfConfigPath = configPath ? configPath : defaultPath;
|
|
16
|
-
const preBundlePath = await bundle(mfConfigPath);
|
|
17
|
-
const mfConfig = (await import(preBundlePath)).default;
|
|
18
|
-
return mfConfig;
|
|
19
|
-
};
|
|
20
|
-
const injectRuntimePlugins = (runtimePlugin, runtimePlugins) => {
|
|
21
|
-
if (!runtimePlugins.includes(runtimePlugin)) {
|
|
22
|
-
runtimePlugins.push(runtimePlugin);
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
const replaceRemoteUrl = (mfConfig, remoteIpStrategy) => {
|
|
26
|
-
if (remoteIpStrategy && remoteIpStrategy === "inherit") {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
if (!mfConfig.remotes) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
const ipv4 = getIPV4();
|
|
33
|
-
const handleRemoteObject = (remoteObject) => {
|
|
34
|
-
Object.keys(remoteObject).forEach((remoteKey) => {
|
|
35
|
-
const remote = remoteObject[remoteKey];
|
|
36
|
-
if (Array.isArray(remote)) {
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
if (typeof remote === "string" && remote.includes(LOCALHOST)) {
|
|
40
|
-
remoteObject[remoteKey] = remote.replace(LOCALHOST, ipv4);
|
|
41
|
-
}
|
|
42
|
-
if (typeof remote === "object" && !Array.isArray(remote.external) && remote.external.includes(LOCALHOST)) {
|
|
43
|
-
remote.external = remote.external.replace(LOCALHOST, ipv4);
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
};
|
|
47
|
-
if (Array.isArray(mfConfig.remotes)) {
|
|
48
|
-
mfConfig.remotes.forEach((remoteObject) => {
|
|
49
|
-
if (typeof remoteObject === "string") {
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
handleRemoteObject(remoteObject);
|
|
53
|
-
});
|
|
54
|
-
} else if (typeof mfConfig.remotes !== "string") {
|
|
55
|
-
handleRemoteObject(mfConfig.remotes);
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
const patchDTSConfig = (mfConfig, isServer) => {
|
|
59
|
-
if (isServer) {
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
const ModernJSRuntime = "@modern-js/runtime/mf";
|
|
63
|
-
if (mfConfig.dts !== false) {
|
|
64
|
-
var _mfConfig_dts, _mfConfig_dts1;
|
|
65
|
-
if (typeof mfConfig.dts === "boolean" || mfConfig.dts === void 0) {
|
|
66
|
-
mfConfig.dts = {
|
|
67
|
-
consumeTypes: {
|
|
68
|
-
runtimePkgs: [
|
|
69
|
-
ModernJSRuntime
|
|
70
|
-
]
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
} 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) {
|
|
74
|
-
var _mfConfig_dts2;
|
|
75
|
-
if (typeof mfConfig.dts.consumeTypes === "boolean" || ((_mfConfig_dts2 = mfConfig.dts) === null || _mfConfig_dts2 === void 0 ? void 0 : _mfConfig_dts2.consumeTypes) === void 0) {
|
|
76
|
-
mfConfig.dts.consumeTypes = {
|
|
77
|
-
runtimePkgs: [
|
|
78
|
-
ModernJSRuntime
|
|
79
|
-
]
|
|
80
|
-
};
|
|
81
|
-
} else {
|
|
82
|
-
mfConfig.dts.consumeTypes.runtimePkgs = mfConfig.dts.consumeTypes.runtimePkgs || [];
|
|
83
|
-
if (!mfConfig.dts.consumeTypes.runtimePkgs.includes(ModernJSRuntime)) {
|
|
84
|
-
mfConfig.dts.consumeTypes.runtimePkgs.push(ModernJSRuntime);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
const patchMFConfig = (mfConfig, isServer, remoteIpStrategy) => {
|
|
91
|
-
replaceRemoteUrl(mfConfig, remoteIpStrategy);
|
|
92
|
-
if (mfConfig.remoteType === void 0) {
|
|
93
|
-
mfConfig.remoteType = "script";
|
|
94
|
-
}
|
|
95
|
-
if (!mfConfig.name) {
|
|
96
|
-
throw new Error(`${PLUGIN_IDENTIFIER} mfConfig.name can not be empty!`);
|
|
97
|
-
}
|
|
98
|
-
const runtimePlugins = [
|
|
99
|
-
...mfConfig.runtimePlugins || []
|
|
100
|
-
];
|
|
101
|
-
patchDTSConfig(mfConfig, isServer);
|
|
102
|
-
injectRuntimePlugins(require.resolve("@module-federation/modern-js/shared-strategy"), runtimePlugins);
|
|
103
|
-
if (isDev) {
|
|
104
|
-
injectRuntimePlugins(require.resolve("@module-federation/modern-js/resolve-entry-ipv4"), runtimePlugins);
|
|
105
|
-
}
|
|
106
|
-
if (isServer) {
|
|
107
|
-
injectRuntimePlugins(require.resolve("@module-federation/node/runtimePlugin"), runtimePlugins);
|
|
108
|
-
if (isDev) {
|
|
109
|
-
injectRuntimePlugins(require.resolve("@module-federation/node/record-dynamic-remote-entry-hash-plugin"), runtimePlugins);
|
|
110
|
-
}
|
|
111
|
-
injectRuntimePlugins(require.resolve("@module-federation/modern-js/inject-node-fetch"), runtimePlugins);
|
|
112
|
-
if (!mfConfig.library) {
|
|
113
|
-
mfConfig.library = {
|
|
114
|
-
type: "commonjs-module",
|
|
115
|
-
name: mfConfig.name
|
|
116
|
-
};
|
|
117
|
-
} else {
|
|
118
|
-
if (!mfConfig.library.type) {
|
|
119
|
-
mfConfig.library.type = "commonjs-module";
|
|
120
|
-
}
|
|
121
|
-
if (!mfConfig.library.name) {
|
|
122
|
-
mfConfig.library.name = mfConfig.name;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
mfConfig.runtimePlugins = runtimePlugins;
|
|
127
|
-
if (!isServer) {
|
|
128
|
-
var _mfConfig_library;
|
|
129
|
-
if (((_mfConfig_library = mfConfig.library) === null || _mfConfig_library === void 0 ? void 0 : _mfConfig_library.type) === "commonjs-module") {
|
|
130
|
-
mfConfig.library.type = "global";
|
|
131
|
-
}
|
|
132
|
-
return mfConfig;
|
|
133
|
-
}
|
|
134
|
-
mfConfig.dts = false;
|
|
135
|
-
mfConfig.dev = false;
|
|
136
|
-
return mfConfig;
|
|
137
|
-
};
|
|
138
|
-
function patchIgnoreWarning(chain) {
|
|
139
|
-
const ignoreWarnings = chain.get("ignoreWarnings") || [];
|
|
140
|
-
const ignoredMsgs = [
|
|
141
|
-
"external script",
|
|
142
|
-
"process.env.WS_NO_BUFFER_UTIL",
|
|
143
|
-
`Can't resolve 'utf-8-validate`
|
|
144
|
-
];
|
|
145
|
-
ignoreWarnings.push((warning) => {
|
|
146
|
-
if (ignoredMsgs.some((msg) => warning.message.includes(msg))) {
|
|
147
|
-
return true;
|
|
148
|
-
}
|
|
149
|
-
return false;
|
|
150
|
-
});
|
|
151
|
-
chain.ignoreWarnings(ignoreWarnings);
|
|
152
|
-
}
|
|
153
|
-
function addMyTypes2Ignored(chain, mfConfig) {
|
|
154
|
-
const watchOptions = chain.get("watchOptions");
|
|
155
|
-
if (!watchOptions || !watchOptions.ignored) {
|
|
156
|
-
chain.watchOptions({
|
|
157
|
-
ignored: /[\\/](?:\.git|node_modules|@mf-types)[\\/]/
|
|
158
|
-
});
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
const ignored = watchOptions.ignored;
|
|
162
|
-
const DEFAULT_IGNORED_GLOB = "**/@mf-types/**";
|
|
163
|
-
if (Array.isArray(ignored)) {
|
|
164
|
-
if (mfConfig.dts !== false && typeof mfConfig.dts === "object" && typeof mfConfig.dts.consumeTypes === "object" && mfConfig.dts.consumeTypes.remoteTypesFolder) {
|
|
165
|
-
chain.watchOptions({
|
|
166
|
-
...watchOptions,
|
|
167
|
-
ignored: ignored.concat(`**/${mfConfig.dts.consumeTypes.remoteTypesFolder}/**`)
|
|
168
|
-
});
|
|
169
|
-
} else {
|
|
170
|
-
chain.watchOptions({
|
|
171
|
-
...watchOptions,
|
|
172
|
-
ignored: ignored.concat(DEFAULT_IGNORED_GLOB)
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
return;
|
|
176
|
-
}
|
|
177
|
-
if (typeof ignored !== "string") {
|
|
178
|
-
chain.watchOptions({
|
|
179
|
-
...watchOptions,
|
|
180
|
-
ignored: /[\\/](?:\.git|node_modules|@mf-types)[\\/]/
|
|
181
|
-
});
|
|
182
|
-
return;
|
|
183
|
-
}
|
|
184
|
-
chain.watchOptions({
|
|
185
|
-
...watchOptions,
|
|
186
|
-
ignored: ignored.concat(DEFAULT_IGNORED_GLOB)
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
function patchBundlerConfig(options) {
|
|
190
|
-
var _modernjsConfig_deploy;
|
|
191
|
-
const { chain, modernjsConfig, isServer, mfConfig, enableSSR } = options;
|
|
192
|
-
chain.optimization.delete("runtimeChunk");
|
|
193
|
-
patchIgnoreWarning(chain);
|
|
194
|
-
if (!chain.output.get("chunkLoadingGlobal")) {
|
|
195
|
-
chain.output.chunkLoadingGlobal(`chunk_${mfConfig.name}`);
|
|
196
|
-
}
|
|
197
|
-
if (!chain.output.get("uniqueName")) {
|
|
198
|
-
chain.output.uniqueName(mfConfig.name);
|
|
199
|
-
}
|
|
200
|
-
const splitChunkConfig = chain.optimization.splitChunks.entries();
|
|
201
|
-
if (!isServer) {
|
|
202
|
-
autoDeleteSplitChunkCacheGroups(mfConfig, splitChunkConfig);
|
|
203
|
-
}
|
|
204
|
-
if (!isServer && enableSSR && splitChunkConfig && typeof splitChunkConfig === "object" && splitChunkConfig.cacheGroups) {
|
|
205
|
-
splitChunkConfig.chunks = "async";
|
|
206
|
-
logger.warn(`splitChunks.chunks = async is not allowed with stream SSR mode, it will auto changed to "async"`);
|
|
207
|
-
}
|
|
208
|
-
if (isDev && chain.output.get("publicPath") === "auto") {
|
|
209
|
-
var _modernjsConfig_dev, _modernjsConfig_server;
|
|
210
|
-
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;
|
|
211
|
-
const publicPath = `http://localhost:${port}/`;
|
|
212
|
-
chain.output.publicPath(publicPath);
|
|
213
|
-
}
|
|
214
|
-
if (isServer && enableSSR) {
|
|
215
|
-
const uniqueName = mfConfig.name || chain.output.get("uniqueName");
|
|
216
|
-
const chunkFileName = chain.output.get("chunkFilename");
|
|
217
|
-
if (typeof chunkFileName === "string" && uniqueName && !chunkFileName.includes(uniqueName)) {
|
|
218
|
-
const suffix = `${encodeName(uniqueName)}-[chunkhash].js`;
|
|
219
|
-
chain.output.chunkFilename(chunkFileName.replace(".js", suffix));
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
if (isDev && enableSSR && !isServer) {
|
|
223
|
-
chain.resolve.fallback.set("crypto", false).set("stream", false).set("vm", false);
|
|
224
|
-
}
|
|
225
|
-
if (((_modernjsConfig_deploy = modernjsConfig.deploy) === null || _modernjsConfig_deploy === void 0 ? void 0 : _modernjsConfig_deploy.microFrontend) && Object.keys(mfConfig.exposes || {}).length) {
|
|
226
|
-
chain.optimization.usedExports(false);
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
2
|
const localIpv4 = "127.0.0.1";
|
|
230
3
|
const getIpv4Interfaces = () => {
|
|
231
4
|
try {
|
|
@@ -270,11 +43,7 @@ const skipByTarget = (target) => {
|
|
|
270
43
|
return false;
|
|
271
44
|
};
|
|
272
45
|
export {
|
|
273
|
-
addMyTypes2Ignored,
|
|
274
46
|
getIPV4,
|
|
275
|
-
getMFConfig,
|
|
276
47
|
isWebTarget,
|
|
277
|
-
patchBundlerConfig,
|
|
278
|
-
patchMFConfig,
|
|
279
48
|
skipByTarget
|
|
280
49
|
};
|
|
@@ -1,7 +1,21 @@
|
|
|
1
|
-
import type { CliPluginFuture, AppTools } from '@modern-js/app-tools';
|
|
2
|
-
import type { InternalModernPluginOptions } from '../types';
|
|
3
1
|
import { isWebTarget, skipByTarget } from './utils';
|
|
2
|
+
import { moduleFederationPlugin } from '@module-federation/sdk';
|
|
3
|
+
import { PluginOptions } from '../types';
|
|
4
|
+
import type { InternalModernPluginOptions } from '../types';
|
|
5
|
+
import type { AppTools, webpack, UserConfig, Rspack, CliPluginFuture } from '@modern-js/app-tools';
|
|
6
|
+
import type { BundlerChainConfig } from '../interfaces/bundler';
|
|
7
|
+
export type ConfigType<T> = T extends 'webpack' ? webpack.Configuration : T extends 'rspack' ? Rspack.Configuration : never;
|
|
4
8
|
export declare function setEnv(enableSSR: boolean): void;
|
|
9
|
+
export declare const getMFConfig: (userConfig: PluginOptions) => Promise<moduleFederationPlugin.ModuleFederationPluginOptions>;
|
|
10
|
+
export declare const patchMFConfig: (mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions, isServer: boolean, remoteIpStrategy?: "ipv4" | "inherit") => moduleFederationPlugin.ModuleFederationPluginOptions;
|
|
11
|
+
export declare function addMyTypes2Ignored(chain: BundlerChainConfig, mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions): void;
|
|
12
|
+
export declare function patchBundlerConfig(options: {
|
|
13
|
+
chain: BundlerChainConfig;
|
|
14
|
+
isServer: boolean;
|
|
15
|
+
modernjsConfig: UserConfig<AppTools>;
|
|
16
|
+
mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions;
|
|
17
|
+
enableSSR: boolean;
|
|
18
|
+
}): void;
|
|
5
19
|
export declare const moduleFederationConfigPlugin: (userConfig: InternalModernPluginOptions) => CliPluginFuture<AppTools>;
|
|
6
20
|
export default moduleFederationConfigPlugin;
|
|
7
21
|
export { isWebTarget, skipByTarget };
|
|
@@ -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,18 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { PluginOptions } from '../types';
|
|
3
|
-
import type { BundlerChainConfig } from '../interfaces/bundler';
|
|
4
|
-
import type { webpack, UserConfig, AppTools, Rspack } from '@modern-js/app-tools';
|
|
1
|
+
import type { webpack, Rspack } from '@modern-js/app-tools';
|
|
5
2
|
export type ConfigType<T> = T extends 'webpack' ? webpack.Configuration : T extends 'rspack' ? Rspack.Configuration : never;
|
|
6
|
-
export declare const getMFConfig: (userConfig: PluginOptions) => Promise<moduleFederationPlugin.ModuleFederationPluginOptions>;
|
|
7
|
-
export declare const patchMFConfig: (mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions, isServer: boolean, remoteIpStrategy?: "ipv4" | "inherit") => moduleFederationPlugin.ModuleFederationPluginOptions;
|
|
8
|
-
export declare function addMyTypes2Ignored(chain: BundlerChainConfig, mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions): void;
|
|
9
|
-
export declare function patchBundlerConfig(options: {
|
|
10
|
-
chain: BundlerChainConfig;
|
|
11
|
-
isServer: boolean;
|
|
12
|
-
modernjsConfig: UserConfig<AppTools>;
|
|
13
|
-
mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions;
|
|
14
|
-
enableSSR: boolean;
|
|
15
|
-
}): void;
|
|
16
3
|
export declare const getIPV4: () => string;
|
|
17
4
|
export declare const isWebTarget: (target: string[] | string) => boolean;
|
|
18
5
|
export declare const skipByTarget: (target: string[] | string) => boolean;
|
package/dist/types/constant.d.ts
CHANGED
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-20250403063151",
|
|
4
4
|
"files": [
|
|
5
5
|
"dist/",
|
|
6
6
|
"types.d.ts",
|
|
@@ -89,19 +89,20 @@
|
|
|
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-
|
|
96
|
-
"@module-federation/cli": "0.0.0-next-
|
|
92
|
+
"@module-federation/rsbuild-plugin": "0.0.0-next-20250403063151",
|
|
93
|
+
"@module-federation/enhanced": "0.0.0-next-20250403063151",
|
|
94
|
+
"@module-federation/node": "0.0.0-next-20250403063151",
|
|
95
|
+
"@module-federation/sdk": "0.0.0-next-20250403063151",
|
|
96
|
+
"@module-federation/cli": "0.0.0-next-20250403063151"
|
|
97
97
|
},
|
|
98
98
|
"devDependencies": {
|
|
99
|
+
"@rsbuild/core": "1.2.8",
|
|
99
100
|
"@modern-js/app-tools": "2.65.1",
|
|
100
101
|
"@modern-js/core": "2.65.1",
|
|
101
102
|
"@modern-js/module-tools": "2.65.1",
|
|
102
103
|
"@modern-js/runtime": "2.65.1",
|
|
103
104
|
"@modern-js/tsconfig": "2.65.1",
|
|
104
|
-
"@module-federation/manifest": "0.0.0-next-
|
|
105
|
+
"@module-federation/manifest": "0.0.0-next-20250403063151"
|
|
105
106
|
},
|
|
106
107
|
"peerDependencies": {
|
|
107
108
|
"react": ">=17",
|
|
File without changes
|