@module-federation/modern-js 0.0.0-next-20250219033929 → 0.0.0-next-20250219082408
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 +13 -40
- package/dist/cjs/cli/index.js +26 -30
- package/dist/cjs/cli/ssrPlugin.js +32 -37
- package/dist/cjs/cli/utils.js +24 -59
- package/dist/cjs/cli/utils.spec.js +0 -60
- package/dist/esm/cli/configPlugin.js +14 -42
- package/dist/esm/cli/index.js +30 -35
- package/dist/esm/cli/ssrPlugin.js +32 -40
- package/dist/esm/cli/utils.js +24 -57
- package/dist/esm/cli/utils.spec.js +1 -78
- package/dist/esm-node/cli/configPlugin.js +13 -39
- package/dist/esm-node/cli/index.js +26 -30
- package/dist/esm-node/cli/ssrPlugin.js +31 -37
- package/dist/esm-node/cli/utils.js +24 -58
- package/dist/esm-node/cli/utils.spec.js +1 -61
- package/dist/types/cli/configPlugin.d.ts +1 -11
- package/dist/types/cli/ssrPlugin.d.ts +1 -0
- package/dist/types/cli/utils.d.ts +2 -4
- package/package.json +13 -13
|
@@ -135,19 +135,20 @@ const patchMFConfig = (mfConfig, isServer, remoteIpStrategy) => {
|
|
|
135
135
|
mfConfig.dev = false;
|
|
136
136
|
return mfConfig;
|
|
137
137
|
};
|
|
138
|
-
function patchIgnoreWarning(
|
|
139
|
-
|
|
138
|
+
function patchIgnoreWarning(chain) {
|
|
139
|
+
const ignoreWarnings = chain.get("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
|
-
|
|
145
|
+
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);
|
|
151
152
|
}
|
|
152
153
|
function addMyTypes2Ignored(chain, mfConfig) {
|
|
153
154
|
const watchOptions = chain.get("watchOptions");
|
|
@@ -186,55 +187,43 @@ function addMyTypes2Ignored(chain, mfConfig) {
|
|
|
186
187
|
});
|
|
187
188
|
}
|
|
188
189
|
function patchBundlerConfig(options) {
|
|
189
|
-
var _modernjsConfig_server,
|
|
190
|
-
const {
|
|
190
|
+
var _modernjsConfig_server, _modernjsConfig_deploy;
|
|
191
|
+
const { chain, modernjsConfig, isServer, mfConfig } = options;
|
|
191
192
|
const enableSSR = Boolean((_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
}
|
|
199
|
-
if (!((_bundlerConfig_output2 = bundlerConfig.output) === null || _bundlerConfig_output2 === void 0 ? void 0 : _bundlerConfig_output2.uniqueName)) {
|
|
200
|
-
bundlerConfig.output.uniqueName = mfConfig.name;
|
|
201
|
-
}
|
|
193
|
+
chain.optimization.runtimeChunk(false);
|
|
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);
|
|
202
199
|
}
|
|
200
|
+
const optimizationConfig = chain.optimization.entries();
|
|
203
201
|
if (!isServer) {
|
|
204
|
-
autoDeleteSplitChunkCacheGroups(mfConfig,
|
|
202
|
+
autoDeleteSplitChunkCacheGroups(mfConfig, optimizationConfig);
|
|
205
203
|
}
|
|
206
|
-
if (!isServer && enableSSR && typeof (
|
|
207
|
-
|
|
204
|
+
if (!isServer && enableSSR && typeof (optimizationConfig === null || optimizationConfig === void 0 ? void 0 : optimizationConfig.splitChunks) === "object" && optimizationConfig.splitChunks.cacheGroups) {
|
|
205
|
+
optimizationConfig.splitChunks.chunks = "async";
|
|
208
206
|
logger.warn(`splitChunks.chunks = async is not allowed with stream SSR mode, it will auto changed to "async"`);
|
|
209
207
|
}
|
|
210
|
-
if (isDev &&
|
|
208
|
+
if (isDev && chain.output.get("publicPath") === "auto") {
|
|
211
209
|
var _modernjsConfig_dev, _modernjsConfig_server1;
|
|
212
210
|
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;
|
|
213
211
|
const publicPath = `http://localhost:${port}/`;
|
|
214
|
-
|
|
212
|
+
chain.output.publicPath(publicPath);
|
|
215
213
|
}
|
|
216
214
|
if (isServer && enableSSR) {
|
|
217
|
-
const
|
|
218
|
-
const
|
|
219
|
-
|
|
220
|
-
if (output && typeof chunkFileName === "string" && uniqueName && !chunkFileName.includes(uniqueName)) {
|
|
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)) {
|
|
221
218
|
const suffix = `${encodeName(uniqueName)}-[chunkhash].js`;
|
|
222
|
-
output.chunkFilename
|
|
219
|
+
chain.output.chunkFilename(chunkFileName.replace(".js", suffix));
|
|
223
220
|
}
|
|
224
221
|
}
|
|
225
222
|
if (isDev && enableSSR && !isServer) {
|
|
226
|
-
|
|
227
|
-
...bundlerConfig.resolve.fallback,
|
|
228
|
-
crypto: false,
|
|
229
|
-
stream: false,
|
|
230
|
-
vm: false
|
|
231
|
-
};
|
|
223
|
+
chain.resolve.fallback.set("crypto", false).set("stream", false).set("vm", false);
|
|
232
224
|
}
|
|
233
225
|
if (((_modernjsConfig_deploy = modernjsConfig.deploy) === null || _modernjsConfig_deploy === void 0 ? void 0 : _modernjsConfig_deploy.microFrontend) && Object.keys(mfConfig.exposes || {}).length) {
|
|
234
|
-
|
|
235
|
-
bundlerConfig.optimization = {};
|
|
236
|
-
}
|
|
237
|
-
bundlerConfig.optimization.usedExports = false;
|
|
226
|
+
chain.optimization.usedExports(false);
|
|
238
227
|
}
|
|
239
228
|
}
|
|
240
229
|
const localIpv4 = "127.0.0.1";
|
|
@@ -262,33 +251,10 @@ const getIPV4 = () => {
|
|
|
262
251
|
};
|
|
263
252
|
return ipv4Interface.address;
|
|
264
253
|
};
|
|
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
|
-
};
|
|
287
254
|
export {
|
|
288
255
|
addMyTypes2Ignored,
|
|
289
256
|
getIPV4,
|
|
290
257
|
getMFConfig,
|
|
291
258
|
patchBundlerConfig,
|
|
292
|
-
patchIgnoreWarning,
|
|
293
259
|
patchMFConfig
|
|
294
260
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { it, expect, describe } from "vitest";
|
|
2
|
-
import { patchMFConfig,
|
|
2
|
+
import { patchMFConfig, getIPV4 } from "./utils";
|
|
3
3
|
const mfConfig = {
|
|
4
4
|
name: "host",
|
|
5
5
|
filename: "remoteEntry.js",
|
|
@@ -86,63 +86,3 @@ 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,15 +1,5 @@
|
|
|
1
|
-
import type { CliPluginFuture, AppTools
|
|
2
|
-
import type { BundlerConfig } from '../interfaces/bundler';
|
|
1
|
+
import type { CliPluginFuture, AppTools } from '@modern-js/app-tools';
|
|
3
2
|
import type { InternalModernPluginOptions } from '../types';
|
|
4
|
-
import { moduleFederationPlugin } from '@module-federation/sdk';
|
|
5
3
|
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;
|
|
14
4
|
export declare const moduleFederationConfigPlugin: (userConfig: InternalModernPluginOptions) => CliPluginFuture<AppTools>;
|
|
15
5
|
export default moduleFederationConfigPlugin;
|
|
@@ -1,5 +1,6 @@
|
|
|
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";
|
|
4
5
|
export declare const moduleFederationSSRPlugin: (pluginOptions: Required<InternalModernPluginOptions>) => CliPluginFuture<AppTools>;
|
|
5
6
|
export default moduleFederationSSRPlugin;
|
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
import { moduleFederationPlugin } from '@module-federation/sdk';
|
|
2
2
|
import { PluginOptions } from '../types';
|
|
3
|
-
import type {
|
|
3
|
+
import type { BundlerChainConfig } from '../interfaces/bundler';
|
|
4
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;
|
|
9
8
|
export declare function addMyTypes2Ignored(chain: BundlerChainConfig, mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions): void;
|
|
10
9
|
export declare function patchBundlerConfig<T extends Bundler>(options: {
|
|
11
|
-
|
|
10
|
+
chain: BundlerChainConfig;
|
|
12
11
|
isServer: boolean;
|
|
13
12
|
modernjsConfig: UserConfig<AppTools>;
|
|
14
|
-
bundlerType: Bundler;
|
|
15
13
|
mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions;
|
|
16
14
|
}): void;
|
|
17
15
|
export declare const getIPV4: () => string;
|
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-20250219082408",
|
|
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.3",
|
|
88
|
+
"@modern-js/utils": "2.64.3",
|
|
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-20250219082408",
|
|
93
|
+
"@module-federation/enhanced": "0.0.0-next-20250219082408",
|
|
94
|
+
"@module-federation/node": "0.0.0-next-20250219082408",
|
|
95
|
+
"@module-federation/sdk": "0.0.0-next-20250219082408"
|
|
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.3",
|
|
99
|
+
"@modern-js/core": "2.64.3",
|
|
100
|
+
"@modern-js/module-tools": "2.64.3",
|
|
101
|
+
"@modern-js/runtime": "2.64.3",
|
|
102
|
+
"@modern-js/tsconfig": "2.64.3",
|
|
103
|
+
"@module-federation/manifest": "0.0.0-next-20250219082408"
|
|
104
104
|
},
|
|
105
105
|
"peerDependencies": {
|
|
106
106
|
"react": ">=17",
|