@module-federation/modern-js 0.0.0-next-20250218022700 → 0.0.0-next-20250218110948
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 +14 -40
- package/dist/cjs/cli/index.js +24 -30
- package/dist/cjs/cli/ssrPlugin.js +16 -24
- package/dist/cjs/cli/utils.js +25 -37
- package/dist/cjs/cli/utils.spec.js +0 -60
- package/dist/esm/cli/configPlugin.js +15 -42
- package/dist/esm/cli/index.js +28 -35
- package/dist/esm/cli/ssrPlugin.js +17 -26
- package/dist/esm/cli/utils.js +25 -35
- package/dist/esm/cli/utils.spec.js +1 -78
- package/dist/esm-node/cli/configPlugin.js +14 -39
- package/dist/esm-node/cli/index.js +24 -30
- package/dist/esm-node/cli/ssrPlugin.js +16 -24
- package/dist/esm-node/cli/utils.js +25 -36
- package/dist/esm-node/cli/utils.spec.js +1 -61
- package/dist/types/cli/configPlugin.d.ts +1 -11
- package/dist/types/cli/utils.d.ts +2 -4
- package/package.json +6 -6
|
@@ -29,7 +29,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
29
29
|
var configPlugin_exports = {};
|
|
30
30
|
__export(configPlugin_exports, {
|
|
31
31
|
default: () => configPlugin_default,
|
|
32
|
-
modifyBundlerConfig: () => modifyBundlerConfig,
|
|
33
32
|
moduleFederationConfigPlugin: () => moduleFederationConfigPlugin,
|
|
34
33
|
setEnv: () => setEnv
|
|
35
34
|
});
|
|
@@ -42,17 +41,6 @@ function setEnv(enableSSR) {
|
|
|
42
41
|
process.env["MF_SSR_PRJ"] = "true";
|
|
43
42
|
}
|
|
44
43
|
}
|
|
45
|
-
function modifyBundlerConfig(options) {
|
|
46
|
-
const { mfConfig, config, isServer, modernjsConfig, remoteIpStrategy = "ipv4", bundlerType } = options;
|
|
47
|
-
(0, import_utils.patchMFConfig)(mfConfig, isServer, remoteIpStrategy);
|
|
48
|
-
(0, import_utils.patchBundlerConfig)({
|
|
49
|
-
bundlerType,
|
|
50
|
-
bundlerConfig: config,
|
|
51
|
-
isServer,
|
|
52
|
-
modernjsConfig,
|
|
53
|
-
mfConfig
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
44
|
const moduleFederationConfigPlugin = (userConfig) => ({
|
|
57
45
|
name: "@modern-js/plugin-module-federation-config",
|
|
58
46
|
pre: [
|
|
@@ -68,6 +56,20 @@ const moduleFederationConfigPlugin = (userConfig) => ({
|
|
|
68
56
|
const ssrConfig = userConfig.ssrConfig || JSON.parse(JSON.stringify(mfConfig));
|
|
69
57
|
userConfig.ssrConfig = ssrConfig;
|
|
70
58
|
userConfig.csrConfig = csrConfig;
|
|
59
|
+
api.modifyBundlerChain((chain, { isProd, isServer }) => {
|
|
60
|
+
const bundlerType = api.getAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
|
|
61
|
+
(0, import_utils.addMyTypes2Ignored)(chain, isServer ? ssrConfig : csrConfig);
|
|
62
|
+
const targetMFConfig = isServer ? ssrConfig : csrConfig;
|
|
63
|
+
(0, import_utils.patchMFConfig)(targetMFConfig, isServer, userConfig.remoteIpStrategy || "ipv4");
|
|
64
|
+
(0, import_utils.patchBundlerConfig)({
|
|
65
|
+
// @ts-expect-error chain type is not correct
|
|
66
|
+
chain,
|
|
67
|
+
isServer,
|
|
68
|
+
modernjsConfig,
|
|
69
|
+
mfConfig
|
|
70
|
+
});
|
|
71
|
+
userConfig.distOutputDir = chain.output.get("path") || import_path.default.resolve(process.cwd(), "dist");
|
|
72
|
+
});
|
|
71
73
|
api.config(() => {
|
|
72
74
|
var _userConfig_userConfig, _modernjsConfig_server, _modernjsConfig_source, _modernjsConfig_source1, _modernjsConfig_dev;
|
|
73
75
|
const bundlerType = api.getAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
|
|
@@ -83,33 +85,6 @@ const moduleFederationConfigPlugin = (userConfig) => ({
|
|
|
83
85
|
var _modernjsConfig_source_enableAsyncEntry;
|
|
84
86
|
return {
|
|
85
87
|
tools: {
|
|
86
|
-
bundlerChain(chain, { isServer }) {
|
|
87
|
-
(0, import_utils.addMyTypes2Ignored)(chain, isServer ? ssrConfig : csrConfig);
|
|
88
|
-
},
|
|
89
|
-
rspack(config, { isServer }) {
|
|
90
|
-
var _config_output;
|
|
91
|
-
modifyBundlerConfig({
|
|
92
|
-
bundlerType,
|
|
93
|
-
mfConfig: isServer ? ssrConfig : csrConfig,
|
|
94
|
-
config,
|
|
95
|
-
isServer,
|
|
96
|
-
modernjsConfig,
|
|
97
|
-
remoteIpStrategy: userConfig.remoteIpStrategy
|
|
98
|
-
});
|
|
99
|
-
userConfig.distOutputDir = ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.path) || import_path.default.resolve(process.cwd(), "dist");
|
|
100
|
-
},
|
|
101
|
-
webpack(config, { isServer }) {
|
|
102
|
-
var _config_output;
|
|
103
|
-
modifyBundlerConfig({
|
|
104
|
-
bundlerType,
|
|
105
|
-
mfConfig: isServer ? ssrConfig : csrConfig,
|
|
106
|
-
config,
|
|
107
|
-
isServer,
|
|
108
|
-
modernjsConfig,
|
|
109
|
-
remoteIpStrategy: userConfig.remoteIpStrategy
|
|
110
|
-
});
|
|
111
|
-
userConfig.distOutputDir = ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.path) || import_path.default.resolve(process.cwd(), "dist");
|
|
112
|
-
},
|
|
113
88
|
devServer: {
|
|
114
89
|
headers: {
|
|
115
90
|
"Access-Control-Allow-Origin": "*",
|
|
@@ -138,7 +113,6 @@ const moduleFederationConfigPlugin = (userConfig) => ({
|
|
|
138
113
|
var configPlugin_default = moduleFederationConfigPlugin;
|
|
139
114
|
// Annotate the CommonJS export names for ESM import in node:
|
|
140
115
|
0 && (module.exports = {
|
|
141
|
-
modifyBundlerConfig,
|
|
142
116
|
moduleFederationConfigPlugin,
|
|
143
117
|
setEnv
|
|
144
118
|
});
|
package/dist/cjs/cli/index.js
CHANGED
|
@@ -43,37 +43,31 @@ const moduleFederationPlugin = (userConfig = {}) => {
|
|
|
43
43
|
name: "@modern-js/plugin-module-federation",
|
|
44
44
|
setup: async (api) => {
|
|
45
45
|
const modernjsConfig = api.getConfig();
|
|
46
|
-
api.
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
eager: (module2) => module2 && /\.federation/.test((module2 === null || module2 === void 0 ? void 0 : module2.request) || ""),
|
|
70
|
-
excludeChunk: (chunk) => chunk.name === browserPluginOptions.name
|
|
71
|
-
};
|
|
72
|
-
(_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(new import_enhanced.AsyncBoundaryPlugin(asyncBoundaryPluginOptions));
|
|
73
|
-
}
|
|
74
|
-
}
|
|
46
|
+
api.modifyBundlerChain((chain, { isProd, isServer }) => {
|
|
47
|
+
const bundlerType = api.getAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
|
|
48
|
+
const browserPluginOptions = internalModernPluginOptions.csrConfig;
|
|
49
|
+
const MFPlugin = bundlerType === "webpack" ? import_enhanced.ModuleFederationPlugin : import_rspack.ModuleFederationPlugin;
|
|
50
|
+
if (!isServer) {
|
|
51
|
+
chain.plugin("plugin-module-federation").use(MFPlugin, [
|
|
52
|
+
browserPluginOptions
|
|
53
|
+
]).init((Plugin, args) => {
|
|
54
|
+
internalModernPluginOptions.browserPlugin = new Plugin(args[0]);
|
|
55
|
+
return internalModernPluginOptions.browserPlugin;
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
if (bundlerType === "webpack") {
|
|
59
|
+
var _modernjsConfig_source;
|
|
60
|
+
const enableAsyncEntry = (_modernjsConfig_source = modernjsConfig.source) === null || _modernjsConfig_source === void 0 ? void 0 : _modernjsConfig_source.enableAsyncEntry;
|
|
61
|
+
if (!enableAsyncEntry && browserPluginOptions.async !== false) {
|
|
62
|
+
const asyncBoundaryPluginOptions = typeof browserPluginOptions.async === "object" ? browserPluginOptions.async : {
|
|
63
|
+
eager: (module2) => module2 && /\.federation/.test((module2 === null || module2 === void 0 ? void 0 : module2.request) || ""),
|
|
64
|
+
excludeChunk: (chunk) => chunk.name === browserPluginOptions.name
|
|
65
|
+
};
|
|
66
|
+
chain.plugin("async-boundary-plugin").use(import_enhanced.AsyncBoundaryPlugin, [
|
|
67
|
+
asyncBoundaryPluginOptions
|
|
68
|
+
]);
|
|
75
69
|
}
|
|
76
|
-
}
|
|
70
|
+
}
|
|
77
71
|
});
|
|
78
72
|
},
|
|
79
73
|
usePlugins: [
|
|
@@ -76,33 +76,25 @@ const moduleFederationSSRPlugin = (pluginOptions) => ({
|
|
|
76
76
|
plugins
|
|
77
77
|
};
|
|
78
78
|
});
|
|
79
|
+
api.modifyBundlerChain((chain, { isProd, isServer }) => {
|
|
80
|
+
const bundlerType = api.getAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
|
|
81
|
+
const MFPlugin = bundlerType === "webpack" ? import_webpack.ModuleFederationPlugin : import_rspack.ModuleFederationPlugin;
|
|
82
|
+
if (isServer) {
|
|
83
|
+
if (!pluginOptions.nodePlugin) {
|
|
84
|
+
chain.plugin("plugin-module-federation-server").use(MFPlugin, [
|
|
85
|
+
pluginOptions.ssrConfig
|
|
86
|
+
]).init((Plugin, args) => {
|
|
87
|
+
pluginOptions.nodePlugin = new Plugin(args[0]);
|
|
88
|
+
return pluginOptions.nodePlugin;
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
} else {
|
|
92
|
+
pluginOptions.distOutputDir = pluginOptions.distOutputDir || chain.output.get("path") || import_path.default.resolve(process.cwd(), "dist");
|
|
93
|
+
}
|
|
94
|
+
});
|
|
79
95
|
api.config(() => {
|
|
80
96
|
return {
|
|
81
97
|
tools: {
|
|
82
|
-
rspack(config, { isServer }) {
|
|
83
|
-
if (isServer) {
|
|
84
|
-
if (!pluginOptions.nodePlugin) {
|
|
85
|
-
var _config_plugins;
|
|
86
|
-
pluginOptions.nodePlugin = new import_rspack.ModuleFederationPlugin(pluginOptions.ssrConfig);
|
|
87
|
-
(_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(pluginOptions.nodePlugin);
|
|
88
|
-
}
|
|
89
|
-
} else {
|
|
90
|
-
var _config_output;
|
|
91
|
-
pluginOptions.distOutputDir = pluginOptions.distOutputDir || ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.path) || import_path.default.resolve(process.cwd(), "dist");
|
|
92
|
-
}
|
|
93
|
-
},
|
|
94
|
-
webpack(config, { isServer }) {
|
|
95
|
-
if (isServer) {
|
|
96
|
-
if (!pluginOptions.nodePlugin) {
|
|
97
|
-
var _config_plugins;
|
|
98
|
-
pluginOptions.nodePlugin = new import_webpack.ModuleFederationPlugin(pluginOptions.ssrConfig);
|
|
99
|
-
(_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(pluginOptions.nodePlugin);
|
|
100
|
-
}
|
|
101
|
-
} else {
|
|
102
|
-
var _config_output;
|
|
103
|
-
pluginOptions.distOutputDir = pluginOptions.distOutputDir || ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.path) || import_path.default.resolve(process.cwd(), "dist");
|
|
104
|
-
}
|
|
105
|
-
},
|
|
106
98
|
devServer: {
|
|
107
99
|
before: [
|
|
108
100
|
(req, res, next) => {
|
package/dist/cjs/cli/utils.js
CHANGED
|
@@ -32,7 +32,6 @@ __export(utils_exports, {
|
|
|
32
32
|
getIPV4: () => getIPV4,
|
|
33
33
|
getMFConfig: () => getMFConfig,
|
|
34
34
|
patchBundlerConfig: () => patchBundlerConfig,
|
|
35
|
-
patchIgnoreWarning: () => patchIgnoreWarning,
|
|
36
35
|
patchMFConfig: () => patchMFConfig
|
|
37
36
|
});
|
|
38
37
|
module.exports = __toCommonJS(utils_exports);
|
|
@@ -173,19 +172,20 @@ const patchMFConfig = (mfConfig, isServer, remoteIpStrategy) => {
|
|
|
173
172
|
mfConfig.dev = false;
|
|
174
173
|
return mfConfig;
|
|
175
174
|
};
|
|
176
|
-
function patchIgnoreWarning(
|
|
177
|
-
|
|
175
|
+
function patchIgnoreWarning(chain) {
|
|
176
|
+
const ignoreWarnings = chain.get("ignoreWarnings") || [];
|
|
178
177
|
const ignoredMsgs = [
|
|
179
178
|
"external script",
|
|
180
179
|
"process.env.WS_NO_BUFFER_UTIL",
|
|
181
180
|
`Can't resolve 'utf-8-validate`
|
|
182
181
|
];
|
|
183
|
-
|
|
182
|
+
ignoreWarnings.push((warning) => {
|
|
184
183
|
if (ignoredMsgs.some((msg) => warning.message.includes(msg))) {
|
|
185
184
|
return true;
|
|
186
185
|
}
|
|
187
186
|
return false;
|
|
188
187
|
});
|
|
188
|
+
chain.ignoreWarnings(ignoreWarnings);
|
|
189
189
|
}
|
|
190
190
|
function addMyTypes2Ignored(chain, mfConfig) {
|
|
191
191
|
const watchOptions = chain.get("watchOptions");
|
|
@@ -224,55 +224,44 @@ function addMyTypes2Ignored(chain, mfConfig) {
|
|
|
224
224
|
});
|
|
225
225
|
}
|
|
226
226
|
function patchBundlerConfig(options) {
|
|
227
|
-
var _modernjsConfig_server,
|
|
228
|
-
const {
|
|
227
|
+
var _modernjsConfig_server, _modernjsConfig_deploy;
|
|
228
|
+
const { chain, modernjsConfig, isServer, mfConfig } = options;
|
|
229
229
|
const enableSSR = Boolean((_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
|
|
230
|
-
|
|
231
|
-
patchIgnoreWarning(
|
|
232
|
-
if (
|
|
233
|
-
|
|
234
|
-
if (!((_bundlerConfig_output1 = bundlerConfig.output) === null || _bundlerConfig_output1 === void 0 ? void 0 : _bundlerConfig_output1.chunkLoadingGlobal)) {
|
|
235
|
-
bundlerConfig.output.chunkLoadingGlobal = `chunk_${mfConfig.name}`;
|
|
236
|
-
}
|
|
237
|
-
if (!((_bundlerConfig_output2 = bundlerConfig.output) === null || _bundlerConfig_output2 === void 0 ? void 0 : _bundlerConfig_output2.uniqueName)) {
|
|
238
|
-
bundlerConfig.output.uniqueName = mfConfig.name;
|
|
239
|
-
}
|
|
230
|
+
chain.optimization.runtimeChunk(false);
|
|
231
|
+
patchIgnoreWarning(chain);
|
|
232
|
+
if (!chain.output.get("chunkLoadingGlobal")) {
|
|
233
|
+
chain.output.chunkLoadingGlobal(`chunk_${mfConfig.name}`);
|
|
240
234
|
}
|
|
235
|
+
if (!chain.output.get("uniqueName")) {
|
|
236
|
+
chain.output.uniqueName(mfConfig.name);
|
|
237
|
+
}
|
|
238
|
+
const optimizationConfig = chain.optimization.entries();
|
|
241
239
|
if (!isServer) {
|
|
242
|
-
(0, import_utils.autoDeleteSplitChunkCacheGroups)(mfConfig,
|
|
240
|
+
(0, import_utils.autoDeleteSplitChunkCacheGroups)(mfConfig, optimizationConfig);
|
|
243
241
|
}
|
|
244
|
-
if (!isServer && enableSSR && typeof (
|
|
245
|
-
|
|
242
|
+
if (!isServer && enableSSR && typeof (optimizationConfig === null || optimizationConfig === void 0 ? void 0 : optimizationConfig.splitChunks) === "object" && optimizationConfig.splitChunks.cacheGroups) {
|
|
243
|
+
optimizationConfig.splitChunks.chunks = "async";
|
|
246
244
|
import_logger.default.warn(`splitChunks.chunks = async is not allowed with stream SSR mode, it will auto changed to "async"`);
|
|
247
245
|
}
|
|
248
|
-
if (isDev &&
|
|
246
|
+
if (isDev && chain.output.get("publicPath") === "auto") {
|
|
249
247
|
var _modernjsConfig_dev, _modernjsConfig_server1;
|
|
250
248
|
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;
|
|
251
249
|
const publicPath = `http://localhost:${port}/`;
|
|
252
|
-
|
|
250
|
+
chain.output.publicPath(publicPath);
|
|
253
251
|
}
|
|
254
252
|
if (isServer && enableSSR) {
|
|
255
|
-
const
|
|
256
|
-
const
|
|
257
|
-
|
|
258
|
-
if (output && typeof chunkFileName === "string" && uniqueName && !chunkFileName.includes(uniqueName)) {
|
|
253
|
+
const uniqueName = mfConfig.name || chain.output.get("uniqueName");
|
|
254
|
+
const chunkFileName = chain.output.get("chunkFilename");
|
|
255
|
+
if (typeof chunkFileName === "string" && uniqueName && !chunkFileName.includes(uniqueName)) {
|
|
259
256
|
const suffix = `${(0, import_sdk.encodeName)(uniqueName)}-[chunkhash].js`;
|
|
260
|
-
output.chunkFilename
|
|
257
|
+
chain.output.chunkFilename(chunkFileName.replace(".js", suffix));
|
|
261
258
|
}
|
|
262
259
|
}
|
|
263
260
|
if (isDev && enableSSR && !isServer) {
|
|
264
|
-
|
|
265
|
-
...bundlerConfig.resolve.fallback,
|
|
266
|
-
crypto: false,
|
|
267
|
-
stream: false,
|
|
268
|
-
vm: false
|
|
269
|
-
};
|
|
261
|
+
chain.resolve.fallback.set("crypto", false).set("stream", false).set("vm", false);
|
|
270
262
|
}
|
|
271
263
|
if (((_modernjsConfig_deploy = modernjsConfig.deploy) === null || _modernjsConfig_deploy === void 0 ? void 0 : _modernjsConfig_deploy.microFrontend) && Object.keys(mfConfig.exposes || {}).length) {
|
|
272
|
-
|
|
273
|
-
bundlerConfig.optimization = {};
|
|
274
|
-
}
|
|
275
|
-
bundlerConfig.optimization.usedExports = false;
|
|
264
|
+
chain.optimization.usedExports(false);
|
|
276
265
|
}
|
|
277
266
|
}
|
|
278
267
|
const localIpv4 = "127.0.0.1";
|
|
@@ -328,6 +317,5 @@ const SHARED_SPLIT_CHUNK_MAP = {
|
|
|
328
317
|
getIPV4,
|
|
329
318
|
getMFConfig,
|
|
330
319
|
patchBundlerConfig,
|
|
331
|
-
patchIgnoreWarning,
|
|
332
320
|
patchMFConfig
|
|
333
321
|
});
|
|
@@ -109,63 +109,3 @@ const mfConfig = {
|
|
|
109
109
|
});
|
|
110
110
|
});
|
|
111
111
|
});
|
|
112
|
-
(0, import_vitest.describe)("patchBundlerConfig", async () => {
|
|
113
|
-
(0, import_vitest.it)("patchBundlerConfig: server", async () => {
|
|
114
|
-
const bundlerConfig = {
|
|
115
|
-
output: {
|
|
116
|
-
publicPath: "auto"
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
(0, import_utils.patchBundlerConfig)({
|
|
120
|
-
bundlerType: "webpack",
|
|
121
|
-
bundlerConfig,
|
|
122
|
-
isServer: true,
|
|
123
|
-
modernjsConfig: {
|
|
124
|
-
server: {
|
|
125
|
-
ssr: {
|
|
126
|
-
mode: "stream"
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
},
|
|
130
|
-
mfConfig
|
|
131
|
-
});
|
|
132
|
-
const expectedConfig = {
|
|
133
|
-
output: {
|
|
134
|
-
chunkLoadingGlobal: "chunk_host",
|
|
135
|
-
publicPath: "auto",
|
|
136
|
-
uniqueName: "host"
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
bundlerConfig === null || bundlerConfig === void 0 ? true : delete bundlerConfig.ignoreWarnings;
|
|
140
|
-
(0, import_vitest.expect)(bundlerConfig).toStrictEqual(expectedConfig);
|
|
141
|
-
});
|
|
142
|
-
(0, import_vitest.it)("patchBundlerConfig: client", async () => {
|
|
143
|
-
const bundlerConfig = {
|
|
144
|
-
output: {
|
|
145
|
-
publicPath: "auto"
|
|
146
|
-
}
|
|
147
|
-
};
|
|
148
|
-
(0, import_utils.patchBundlerConfig)({
|
|
149
|
-
bundlerType: "webpack",
|
|
150
|
-
bundlerConfig,
|
|
151
|
-
isServer: false,
|
|
152
|
-
modernjsConfig: {
|
|
153
|
-
server: {
|
|
154
|
-
ssr: {
|
|
155
|
-
mode: "stream"
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
},
|
|
159
|
-
mfConfig
|
|
160
|
-
});
|
|
161
|
-
const expectedConfig = {
|
|
162
|
-
output: {
|
|
163
|
-
chunkLoadingGlobal: "chunk_host",
|
|
164
|
-
publicPath: "auto",
|
|
165
|
-
uniqueName: "host"
|
|
166
|
-
}
|
|
167
|
-
};
|
|
168
|
-
bundlerConfig === null || bundlerConfig === void 0 ? true : delete bundlerConfig.ignoreWarnings;
|
|
169
|
-
(0, import_vitest.expect)(bundlerConfig).toStrictEqual(expectedConfig);
|
|
170
|
-
});
|
|
171
|
-
});
|
|
@@ -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",
|
|
@@ -45,6 +34,21 @@ 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
|
+
api.modifyBundlerChain(function(chain, param) {
|
|
38
|
+
var isProd = param.isProd, isServer = param.isServer;
|
|
39
|
+
var bundlerType = api.getAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
|
|
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
|
+
});
|
|
50
|
+
userConfig.distOutputDir = chain.output.get("path") || path.resolve(process.cwd(), "dist");
|
|
51
|
+
});
|
|
48
52
|
api.config(function() {
|
|
49
53
|
var _userConfig_userConfig, _modernjsConfig_server, _modernjsConfig_source, _modernjsConfig_source1, _modernjsConfig_dev;
|
|
50
54
|
var bundlerType = api.getAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
|
|
@@ -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
|
@@ -24,43 +24,36 @@ var moduleFederationPlugin = function() {
|
|
|
24
24
|
var modernjsConfig;
|
|
25
25
|
return _ts_generator(this, function(_state) {
|
|
26
26
|
modernjsConfig = api.getConfig();
|
|
27
|
-
api.
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
27
|
+
api.modifyBundlerChain(function(chain, param) {
|
|
28
|
+
var isProd = param.isProd, isServer = param.isServer;
|
|
29
|
+
var bundlerType = api.getAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
|
|
30
|
+
var browserPluginOptions = internalModernPluginOptions.csrConfig;
|
|
31
|
+
var MFPlugin = bundlerType === "webpack" ? WebpackModuleFederationPlugin : RspackModuleFederationPlugin;
|
|
32
|
+
if (!isServer) {
|
|
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
|
|
@@ -49,35 +49,26 @@ var moduleFederationSSRPlugin = function(pluginOptions) {
|
|
|
49
49
|
plugins
|
|
50
50
|
};
|
|
51
51
|
});
|
|
52
|
+
api.modifyBundlerChain(function(chain, param) {
|
|
53
|
+
var isProd = param.isProd, isServer = param.isServer;
|
|
54
|
+
var bundlerType = api.getAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
|
|
55
|
+
var MFPlugin = bundlerType === "webpack" ? ModuleFederationPlugin : RspackModuleFederationPlugin;
|
|
56
|
+
if (isServer) {
|
|
57
|
+
if (!pluginOptions.nodePlugin) {
|
|
58
|
+
chain.plugin("plugin-module-federation-server").use(MFPlugin, [
|
|
59
|
+
pluginOptions.ssrConfig
|
|
60
|
+
]).init(function(Plugin, args) {
|
|
61
|
+
pluginOptions.nodePlugin = new Plugin(args[0]);
|
|
62
|
+
return pluginOptions.nodePlugin;
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
} else {
|
|
66
|
+
pluginOptions.distOutputDir = pluginOptions.distOutputDir || chain.output.get("path") || path.resolve(process.cwd(), "dist");
|
|
67
|
+
}
|
|
68
|
+
});
|
|
52
69
|
api.config(function() {
|
|
53
70
|
return {
|
|
54
71
|
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
72
|
devServer: {
|
|
82
73
|
before: [
|
|
83
74
|
function(req, res, next) {
|
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,44 @@ function addMyTypes2Ignored(chain, mfConfig) {
|
|
|
215
216
|
}));
|
|
216
217
|
}
|
|
217
218
|
function patchBundlerConfig(options) {
|
|
218
|
-
var _modernjsConfig_server,
|
|
219
|
-
var
|
|
219
|
+
var _modernjsConfig_server, _modernjsConfig_deploy;
|
|
220
|
+
var chain = options.chain, modernjsConfig = options.modernjsConfig, isServer = options.isServer, mfConfig = options.mfConfig;
|
|
220
221
|
var enableSSR = Boolean((_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
|
|
221
|
-
|
|
222
|
-
patchIgnoreWarning(
|
|
223
|
-
if (
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
if (!((_bundlerConfig_output2 = bundlerConfig.output) === null || _bundlerConfig_output2 === void 0 ? void 0 : _bundlerConfig_output2.uniqueName)) {
|
|
229
|
-
bundlerConfig.output.uniqueName = mfConfig.name;
|
|
230
|
-
}
|
|
222
|
+
chain.optimization.runtimeChunk(false);
|
|
223
|
+
patchIgnoreWarning(chain);
|
|
224
|
+
if (!chain.output.get("chunkLoadingGlobal")) {
|
|
225
|
+
chain.output.chunkLoadingGlobal("chunk_".concat(mfConfig.name));
|
|
226
|
+
}
|
|
227
|
+
if (!chain.output.get("uniqueName")) {
|
|
228
|
+
chain.output.uniqueName(mfConfig.name);
|
|
231
229
|
}
|
|
230
|
+
var optimizationConfig = chain.optimization.entries();
|
|
232
231
|
if (!isServer) {
|
|
233
|
-
autoDeleteSplitChunkCacheGroups(mfConfig,
|
|
232
|
+
autoDeleteSplitChunkCacheGroups(mfConfig, optimizationConfig);
|
|
234
233
|
}
|
|
235
|
-
if (!isServer && enableSSR && _type_of(
|
|
236
|
-
|
|
234
|
+
if (!isServer && enableSSR && _type_of(optimizationConfig === null || optimizationConfig === void 0 ? void 0 : optimizationConfig.splitChunks) === "object" && optimizationConfig.splitChunks.cacheGroups) {
|
|
235
|
+
optimizationConfig.splitChunks.chunks = "async";
|
|
237
236
|
logger.warn('splitChunks.chunks = async is not allowed with stream SSR mode, it will auto changed to "async"');
|
|
238
237
|
}
|
|
239
|
-
if (isDev &&
|
|
238
|
+
if (isDev && chain.output.get("publicPath") === "auto") {
|
|
240
239
|
var _modernjsConfig_dev, _modernjsConfig_server1;
|
|
241
240
|
var 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;
|
|
242
241
|
var publicPath = "http://localhost:".concat(port, "/");
|
|
243
|
-
|
|
242
|
+
chain.output.publicPath(publicPath);
|
|
244
243
|
}
|
|
245
244
|
if (isServer && enableSSR) {
|
|
246
|
-
var
|
|
247
|
-
var
|
|
248
|
-
|
|
249
|
-
if (output && typeof chunkFileName === "string" && uniqueName && !chunkFileName.includes(uniqueName)) {
|
|
245
|
+
var uniqueName = mfConfig.name || chain.output.get("uniqueName");
|
|
246
|
+
var chunkFileName = chain.output.get("chunkFilename");
|
|
247
|
+
if (typeof chunkFileName === "string" && uniqueName && !chunkFileName.includes(uniqueName)) {
|
|
250
248
|
var suffix = "".concat(encodeName(uniqueName), "-[chunkhash].js");
|
|
251
|
-
output.chunkFilename
|
|
249
|
+
chain.output.chunkFilename(chunkFileName.replace(".js", suffix));
|
|
252
250
|
}
|
|
253
251
|
}
|
|
254
252
|
if (isDev && enableSSR && !isServer) {
|
|
255
|
-
|
|
256
|
-
crypto: false,
|
|
257
|
-
stream: false,
|
|
258
|
-
vm: false
|
|
259
|
-
});
|
|
253
|
+
chain.resolve.fallback.set("crypto", false).set("stream", false).set("vm", false);
|
|
260
254
|
}
|
|
261
255
|
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;
|
|
256
|
+
chain.optimization.usedExports(false);
|
|
266
257
|
}
|
|
267
258
|
}
|
|
268
259
|
var localIpv4 = "127.0.0.1";
|
|
@@ -317,6 +308,5 @@ export {
|
|
|
317
308
|
getIPV4,
|
|
318
309
|
getMFConfig,
|
|
319
310
|
patchBundlerConfig,
|
|
320
|
-
patchIgnoreWarning,
|
|
321
311
|
patchMFConfig
|
|
322
312
|
};
|
|
@@ -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
|
-
}));
|
|
@@ -6,17 +6,6 @@ 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
|
-
}
|
|
20
9
|
const moduleFederationConfigPlugin = (userConfig) => ({
|
|
21
10
|
name: "@modern-js/plugin-module-federation-config",
|
|
22
11
|
pre: [
|
|
@@ -32,6 +21,20 @@ const moduleFederationConfigPlugin = (userConfig) => ({
|
|
|
32
21
|
const ssrConfig = userConfig.ssrConfig || JSON.parse(JSON.stringify(mfConfig));
|
|
33
22
|
userConfig.ssrConfig = ssrConfig;
|
|
34
23
|
userConfig.csrConfig = csrConfig;
|
|
24
|
+
api.modifyBundlerChain((chain, { isProd, isServer }) => {
|
|
25
|
+
const bundlerType = api.getAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
|
|
26
|
+
addMyTypes2Ignored(chain, isServer ? ssrConfig : csrConfig);
|
|
27
|
+
const targetMFConfig = isServer ? ssrConfig : csrConfig;
|
|
28
|
+
patchMFConfig(targetMFConfig, isServer, userConfig.remoteIpStrategy || "ipv4");
|
|
29
|
+
patchBundlerConfig({
|
|
30
|
+
// @ts-expect-error chain type is not correct
|
|
31
|
+
chain,
|
|
32
|
+
isServer,
|
|
33
|
+
modernjsConfig,
|
|
34
|
+
mfConfig
|
|
35
|
+
});
|
|
36
|
+
userConfig.distOutputDir = chain.output.get("path") || path.resolve(process.cwd(), "dist");
|
|
37
|
+
});
|
|
35
38
|
api.config(() => {
|
|
36
39
|
var _userConfig_userConfig, _modernjsConfig_server, _modernjsConfig_source, _modernjsConfig_source1, _modernjsConfig_dev;
|
|
37
40
|
const bundlerType = api.getAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
|
|
@@ -47,33 +50,6 @@ const moduleFederationConfigPlugin = (userConfig) => ({
|
|
|
47
50
|
var _modernjsConfig_source_enableAsyncEntry;
|
|
48
51
|
return {
|
|
49
52
|
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
|
-
},
|
|
77
53
|
devServer: {
|
|
78
54
|
headers: {
|
|
79
55
|
"Access-Control-Allow-Origin": "*",
|
|
@@ -102,7 +78,6 @@ const moduleFederationConfigPlugin = (userConfig) => ({
|
|
|
102
78
|
var configPlugin_default = moduleFederationConfigPlugin;
|
|
103
79
|
export {
|
|
104
80
|
configPlugin_default as default,
|
|
105
|
-
modifyBundlerConfig,
|
|
106
81
|
moduleFederationConfigPlugin,
|
|
107
82
|
setEnv
|
|
108
83
|
};
|
|
@@ -17,37 +17,31 @@ 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
|
-
|
|
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
|
-
}
|
|
20
|
+
api.modifyBundlerChain((chain, { isProd, isServer }) => {
|
|
21
|
+
const bundlerType = api.getAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
|
|
22
|
+
const browserPluginOptions = internalModernPluginOptions.csrConfig;
|
|
23
|
+
const MFPlugin = bundlerType === "webpack" ? WebpackModuleFederationPlugin : RspackModuleFederationPlugin;
|
|
24
|
+
if (!isServer) {
|
|
25
|
+
chain.plugin("plugin-module-federation").use(MFPlugin, [
|
|
26
|
+
browserPluginOptions
|
|
27
|
+
]).init((Plugin, args) => {
|
|
28
|
+
internalModernPluginOptions.browserPlugin = new Plugin(args[0]);
|
|
29
|
+
return internalModernPluginOptions.browserPlugin;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
if (bundlerType === "webpack") {
|
|
33
|
+
var _modernjsConfig_source;
|
|
34
|
+
const enableAsyncEntry = (_modernjsConfig_source = modernjsConfig.source) === null || _modernjsConfig_source === void 0 ? void 0 : _modernjsConfig_source.enableAsyncEntry;
|
|
35
|
+
if (!enableAsyncEntry && browserPluginOptions.async !== false) {
|
|
36
|
+
const asyncBoundaryPluginOptions = typeof browserPluginOptions.async === "object" ? browserPluginOptions.async : {
|
|
37
|
+
eager: (module) => module && /\.federation/.test((module === null || module === void 0 ? void 0 : module.request) || ""),
|
|
38
|
+
excludeChunk: (chunk) => chunk.name === browserPluginOptions.name
|
|
39
|
+
};
|
|
40
|
+
chain.plugin("async-boundary-plugin").use(AsyncBoundaryPlugin, [
|
|
41
|
+
asyncBoundaryPluginOptions
|
|
42
|
+
]);
|
|
49
43
|
}
|
|
50
|
-
}
|
|
44
|
+
}
|
|
51
45
|
});
|
|
52
46
|
},
|
|
53
47
|
usePlugins: [
|
|
@@ -41,33 +41,25 @@ const moduleFederationSSRPlugin = (pluginOptions) => ({
|
|
|
41
41
|
plugins
|
|
42
42
|
};
|
|
43
43
|
});
|
|
44
|
+
api.modifyBundlerChain((chain, { isProd, isServer }) => {
|
|
45
|
+
const bundlerType = api.getAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
|
|
46
|
+
const MFPlugin = bundlerType === "webpack" ? ModuleFederationPlugin : RspackModuleFederationPlugin;
|
|
47
|
+
if (isServer) {
|
|
48
|
+
if (!pluginOptions.nodePlugin) {
|
|
49
|
+
chain.plugin("plugin-module-federation-server").use(MFPlugin, [
|
|
50
|
+
pluginOptions.ssrConfig
|
|
51
|
+
]).init((Plugin, args) => {
|
|
52
|
+
pluginOptions.nodePlugin = new Plugin(args[0]);
|
|
53
|
+
return pluginOptions.nodePlugin;
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
} else {
|
|
57
|
+
pluginOptions.distOutputDir = pluginOptions.distOutputDir || chain.output.get("path") || path.resolve(process.cwd(), "dist");
|
|
58
|
+
}
|
|
59
|
+
});
|
|
44
60
|
api.config(() => {
|
|
45
61
|
return {
|
|
46
62
|
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
|
-
},
|
|
71
63
|
devServer: {
|
|
72
64
|
before: [
|
|
73
65
|
(req, res, next) => {
|
|
@@ -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,44 @@ 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
|
-
patchIgnoreWarning(
|
|
194
|
-
if (
|
|
195
|
-
|
|
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
|
-
}
|
|
193
|
+
chain.optimization.runtimeChunk(false);
|
|
194
|
+
patchIgnoreWarning(chain);
|
|
195
|
+
if (!chain.output.get("chunkLoadingGlobal")) {
|
|
196
|
+
chain.output.chunkLoadingGlobal(`chunk_${mfConfig.name}`);
|
|
202
197
|
}
|
|
198
|
+
if (!chain.output.get("uniqueName")) {
|
|
199
|
+
chain.output.uniqueName(mfConfig.name);
|
|
200
|
+
}
|
|
201
|
+
const optimizationConfig = chain.optimization.entries();
|
|
203
202
|
if (!isServer) {
|
|
204
|
-
autoDeleteSplitChunkCacheGroups(mfConfig,
|
|
203
|
+
autoDeleteSplitChunkCacheGroups(mfConfig, optimizationConfig);
|
|
205
204
|
}
|
|
206
|
-
if (!isServer && enableSSR && typeof (
|
|
207
|
-
|
|
205
|
+
if (!isServer && enableSSR && typeof (optimizationConfig === null || optimizationConfig === void 0 ? void 0 : optimizationConfig.splitChunks) === "object" && optimizationConfig.splitChunks.cacheGroups) {
|
|
206
|
+
optimizationConfig.splitChunks.chunks = "async";
|
|
208
207
|
logger.warn(`splitChunks.chunks = async is not allowed with stream SSR mode, it will auto changed to "async"`);
|
|
209
208
|
}
|
|
210
|
-
if (isDev &&
|
|
209
|
+
if (isDev && chain.output.get("publicPath") === "auto") {
|
|
211
210
|
var _modernjsConfig_dev, _modernjsConfig_server1;
|
|
212
211
|
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
212
|
const publicPath = `http://localhost:${port}/`;
|
|
214
|
-
|
|
213
|
+
chain.output.publicPath(publicPath);
|
|
215
214
|
}
|
|
216
215
|
if (isServer && enableSSR) {
|
|
217
|
-
const
|
|
218
|
-
const
|
|
219
|
-
|
|
220
|
-
if (output && typeof chunkFileName === "string" && uniqueName && !chunkFileName.includes(uniqueName)) {
|
|
216
|
+
const uniqueName = mfConfig.name || chain.output.get("uniqueName");
|
|
217
|
+
const chunkFileName = chain.output.get("chunkFilename");
|
|
218
|
+
if (typeof chunkFileName === "string" && uniqueName && !chunkFileName.includes(uniqueName)) {
|
|
221
219
|
const suffix = `${encodeName(uniqueName)}-[chunkhash].js`;
|
|
222
|
-
output.chunkFilename
|
|
220
|
+
chain.output.chunkFilename(chunkFileName.replace(".js", suffix));
|
|
223
221
|
}
|
|
224
222
|
}
|
|
225
223
|
if (isDev && enableSSR && !isServer) {
|
|
226
|
-
|
|
227
|
-
...bundlerConfig.resolve.fallback,
|
|
228
|
-
crypto: false,
|
|
229
|
-
stream: false,
|
|
230
|
-
vm: false
|
|
231
|
-
};
|
|
224
|
+
chain.resolve.fallback.set("crypto", false).set("stream", false).set("vm", false);
|
|
232
225
|
}
|
|
233
226
|
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;
|
|
227
|
+
chain.optimization.usedExports(false);
|
|
238
228
|
}
|
|
239
229
|
}
|
|
240
230
|
const localIpv4 = "127.0.0.1";
|
|
@@ -289,6 +279,5 @@ export {
|
|
|
289
279
|
getIPV4,
|
|
290
280
|
getMFConfig,
|
|
291
281
|
patchBundlerConfig,
|
|
292
|
-
patchIgnoreWarning,
|
|
293
282
|
patchMFConfig
|
|
294
283
|
};
|
|
@@ -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,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-20250218110948",
|
|
4
4
|
"files": [
|
|
5
5
|
"dist/",
|
|
6
6
|
"types.d.ts",
|
|
@@ -89,10 +89,10 @@
|
|
|
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-20250218110948",
|
|
93
|
+
"@module-federation/enhanced": "0.0.0-next-20250218110948",
|
|
94
|
+
"@module-federation/node": "0.0.0-next-20250218110948",
|
|
95
|
+
"@module-federation/sdk": "0.0.0-next-20250218110948"
|
|
96
96
|
},
|
|
97
97
|
"devDependencies": {
|
|
98
98
|
"@modern-js/app-tools": "2.64.0",
|
|
@@ -100,7 +100,7 @@
|
|
|
100
100
|
"@modern-js/module-tools": "2.64.0",
|
|
101
101
|
"@modern-js/runtime": "2.64.0",
|
|
102
102
|
"@modern-js/tsconfig": "2.64.0",
|
|
103
|
-
"@module-federation/manifest": "0.0.0-next-
|
|
103
|
+
"@module-federation/manifest": "0.0.0-next-20250218110948"
|
|
104
104
|
},
|
|
105
105
|
"peerDependencies": {
|
|
106
106
|
"react": ">=17",
|