@module-federation/modern-js 0.0.0-next-20250219105538 → 0.0.0-next-20250220101307
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 +40 -13
- package/dist/cjs/cli/index.js +30 -24
- package/dist/cjs/cli/ssrPlugin.js +37 -28
- package/dist/cjs/cli/utils.js +59 -25
- package/dist/cjs/cli/utils.spec.js +60 -0
- package/dist/esm/cli/configPlugin.js +42 -14
- package/dist/esm/cli/index.js +35 -28
- package/dist/esm/cli/ssrPlugin.js +40 -28
- package/dist/esm/cli/utils.js +57 -25
- package/dist/esm/cli/utils.spec.js +78 -1
- package/dist/esm-node/cli/configPlugin.js +39 -13
- package/dist/esm-node/cli/index.js +30 -24
- package/dist/esm-node/cli/ssrPlugin.js +37 -27
- package/dist/esm-node/cli/utils.js +58 -25
- package/dist/esm-node/cli/utils.spec.js +61 -1
- package/dist/types/cli/configPlugin.d.ts +11 -1
- package/dist/types/cli/ssrPlugin.d.ts +0 -1
- package/dist/types/cli/utils.d.ts +4 -2
- package/package.json +13 -13
|
@@ -29,6 +29,7 @@ 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,
|
|
32
33
|
moduleFederationConfigPlugin: () => moduleFederationConfigPlugin,
|
|
33
34
|
setEnv: () => setEnv
|
|
34
35
|
});
|
|
@@ -41,6 +42,17 @@ function setEnv(enableSSR) {
|
|
|
41
42
|
process.env["MF_SSR_PRJ"] = "true";
|
|
42
43
|
}
|
|
43
44
|
}
|
|
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
|
+
}
|
|
44
56
|
const moduleFederationConfigPlugin = (userConfig) => ({
|
|
45
57
|
name: "@modern-js/plugin-module-federation-config",
|
|
46
58
|
pre: [
|
|
@@ -56,19 +68,6 @@ const moduleFederationConfigPlugin = (userConfig) => ({
|
|
|
56
68
|
const ssrConfig = userConfig.ssrConfig || JSON.parse(JSON.stringify(mfConfig));
|
|
57
69
|
userConfig.ssrConfig = ssrConfig;
|
|
58
70
|
userConfig.csrConfig = csrConfig;
|
|
59
|
-
api.modifyBundlerChain((chain, { isProd, isServer }) => {
|
|
60
|
-
(0, import_utils.addMyTypes2Ignored)(chain, isServer ? ssrConfig : csrConfig);
|
|
61
|
-
const targetMFConfig = isServer ? ssrConfig : csrConfig;
|
|
62
|
-
(0, import_utils.patchMFConfig)(targetMFConfig, isServer, userConfig.remoteIpStrategy || "ipv4");
|
|
63
|
-
(0, import_utils.patchBundlerConfig)({
|
|
64
|
-
// @ts-expect-error chain type is not correct
|
|
65
|
-
chain,
|
|
66
|
-
isServer,
|
|
67
|
-
modernjsConfig,
|
|
68
|
-
mfConfig
|
|
69
|
-
});
|
|
70
|
-
userConfig.distOutputDir = chain.output.get("path") || import_path.default.resolve(process.cwd(), "dist");
|
|
71
|
-
});
|
|
72
71
|
api.config(() => {
|
|
73
72
|
var _userConfig_userConfig, _modernjsConfig_server, _modernjsConfig_source, _modernjsConfig_source1, _modernjsConfig_dev;
|
|
74
73
|
const bundlerType = api.getAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
|
|
@@ -84,6 +83,33 @@ const moduleFederationConfigPlugin = (userConfig) => ({
|
|
|
84
83
|
var _modernjsConfig_source_enableAsyncEntry;
|
|
85
84
|
return {
|
|
86
85
|
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
|
+
},
|
|
87
113
|
devServer: {
|
|
88
114
|
headers: {
|
|
89
115
|
"Access-Control-Allow-Origin": "*",
|
|
@@ -112,6 +138,7 @@ const moduleFederationConfigPlugin = (userConfig) => ({
|
|
|
112
138
|
var configPlugin_default = moduleFederationConfigPlugin;
|
|
113
139
|
// Annotate the CommonJS export names for ESM import in node:
|
|
114
140
|
0 && (module.exports = {
|
|
141
|
+
modifyBundlerConfig,
|
|
115
142
|
moduleFederationConfigPlugin,
|
|
116
143
|
setEnv
|
|
117
144
|
});
|
package/dist/cjs/cli/index.js
CHANGED
|
@@ -43,31 +43,37 @@ 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
|
-
|
|
46
|
+
api.config(() => {
|
|
47
|
+
return {
|
|
48
|
+
tools: {
|
|
49
|
+
rspack(config, { isServer }) {
|
|
50
|
+
const browserPluginOptions = internalModernPluginOptions.csrConfig;
|
|
51
|
+
if (!isServer) {
|
|
52
|
+
var _config_plugins;
|
|
53
|
+
internalModernPluginOptions.browserPlugin = new import_rspack.ModuleFederationPlugin(browserPluginOptions);
|
|
54
|
+
(_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(internalModernPluginOptions.browserPlugin);
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
webpack(config, { isServer }) {
|
|
58
|
+
var _modernjsConfig_source;
|
|
59
|
+
const browserPluginOptions = internalModernPluginOptions.csrConfig;
|
|
60
|
+
if (!isServer) {
|
|
61
|
+
var _config_plugins;
|
|
62
|
+
internalModernPluginOptions.browserPlugin = new import_enhanced.ModuleFederationPlugin(browserPluginOptions);
|
|
63
|
+
(_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(internalModernPluginOptions.browserPlugin);
|
|
64
|
+
}
|
|
65
|
+
const enableAsyncEntry = (_modernjsConfig_source = modernjsConfig.source) === null || _modernjsConfig_source === void 0 ? void 0 : _modernjsConfig_source.enableAsyncEntry;
|
|
66
|
+
if (!enableAsyncEntry && browserPluginOptions.async !== false) {
|
|
67
|
+
var _config_plugins1;
|
|
68
|
+
const asyncBoundaryPluginOptions = typeof browserPluginOptions.async === "object" ? browserPluginOptions.async : {
|
|
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
|
+
}
|
|
69
75
|
}
|
|
70
|
-
}
|
|
76
|
+
};
|
|
71
77
|
});
|
|
72
78
|
},
|
|
73
79
|
usePlugins: [
|
|
@@ -28,7 +28,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
var ssrPlugin_exports = {};
|
|
30
30
|
__export(ssrPlugin_exports, {
|
|
31
|
-
CHAIN_MF_PLUGIN_ID: () => CHAIN_MF_PLUGIN_ID,
|
|
32
31
|
default: () => ssrPlugin_default,
|
|
33
32
|
moduleFederationSSRPlugin: () => moduleFederationSSRPlugin,
|
|
34
33
|
setEnv: () => setEnv
|
|
@@ -46,7 +45,6 @@ function setEnv() {
|
|
|
46
45
|
process.env["MF_DISABLE_EMIT_STATS"] = "true";
|
|
47
46
|
process.env["MF_SSR_PRJ"] = "true";
|
|
48
47
|
}
|
|
49
|
-
const CHAIN_MF_PLUGIN_ID = "plugin-module-federation-server";
|
|
50
48
|
const moduleFederationSSRPlugin = (pluginOptions) => ({
|
|
51
49
|
name: "@modern-js/plugin-module-federation-ssr",
|
|
52
50
|
pre: [
|
|
@@ -78,34 +76,33 @@ const moduleFederationSSRPlugin = (pluginOptions) => ({
|
|
|
78
76
|
plugins
|
|
79
77
|
};
|
|
80
78
|
});
|
|
81
|
-
api.modifyBundlerChain((chain, { isServer }) => {
|
|
82
|
-
const bundlerType = api.getAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
|
|
83
|
-
const MFPlugin = bundlerType === "webpack" ? import_webpack.ModuleFederationPlugin : import_rspack.ModuleFederationPlugin;
|
|
84
|
-
if (isServer) {
|
|
85
|
-
if (!chain.plugins.has(CHAIN_MF_PLUGIN_ID)) {
|
|
86
|
-
chain.plugin(CHAIN_MF_PLUGIN_ID).use(MFPlugin, [
|
|
87
|
-
pluginOptions.ssrConfig
|
|
88
|
-
]).init((Plugin, args) => {
|
|
89
|
-
pluginOptions.nodePlugin = new Plugin(args[0]);
|
|
90
|
-
return pluginOptions.nodePlugin;
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
if (isServer) {
|
|
95
|
-
chain.target("async-node");
|
|
96
|
-
if (import_constant.isDev) {
|
|
97
|
-
chain.plugin("UniverseEntryChunkTrackerPlugin").use(import_universe_entry_chunk_tracker_plugin.default);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
if (import_constant.isDev && !isServer) {
|
|
101
|
-
chain.externals({
|
|
102
|
-
"@module-federation/node/utils": "NOT_USED_IN_BROWSER"
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
79
|
api.config(() => {
|
|
107
80
|
return {
|
|
108
81
|
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
|
+
},
|
|
109
106
|
devServer: {
|
|
110
107
|
before: [
|
|
111
108
|
(req, res, next) => {
|
|
@@ -131,6 +128,19 @@ const moduleFederationSSRPlugin = (pluginOptions) => ({
|
|
|
131
128
|
}
|
|
132
129
|
}
|
|
133
130
|
]
|
|
131
|
+
},
|
|
132
|
+
bundlerChain(chain, { isServer }) {
|
|
133
|
+
if (isServer) {
|
|
134
|
+
chain.target("async-node");
|
|
135
|
+
if (import_constant.isDev) {
|
|
136
|
+
chain.plugin("UniverseEntryChunkTrackerPlugin").use(import_universe_entry_chunk_tracker_plugin.default);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (import_constant.isDev && !isServer) {
|
|
140
|
+
chain.externals({
|
|
141
|
+
"@module-federation/node/utils": "NOT_USED_IN_BROWSER"
|
|
142
|
+
});
|
|
143
|
+
}
|
|
134
144
|
}
|
|
135
145
|
}
|
|
136
146
|
};
|
|
@@ -148,7 +158,6 @@ const moduleFederationSSRPlugin = (pluginOptions) => ({
|
|
|
148
158
|
var ssrPlugin_default = moduleFederationSSRPlugin;
|
|
149
159
|
// Annotate the CommonJS export names for ESM import in node:
|
|
150
160
|
0 && (module.exports = {
|
|
151
|
-
CHAIN_MF_PLUGIN_ID,
|
|
152
161
|
moduleFederationSSRPlugin,
|
|
153
162
|
setEnv
|
|
154
163
|
});
|
package/dist/cjs/cli/utils.js
CHANGED
|
@@ -32,6 +32,7 @@ __export(utils_exports, {
|
|
|
32
32
|
getIPV4: () => getIPV4,
|
|
33
33
|
getMFConfig: () => getMFConfig,
|
|
34
34
|
patchBundlerConfig: () => patchBundlerConfig,
|
|
35
|
+
patchIgnoreWarning: () => patchIgnoreWarning,
|
|
35
36
|
patchMFConfig: () => patchMFConfig
|
|
36
37
|
});
|
|
37
38
|
module.exports = __toCommonJS(utils_exports);
|
|
@@ -172,20 +173,19 @@ const patchMFConfig = (mfConfig, isServer, remoteIpStrategy) => {
|
|
|
172
173
|
mfConfig.dev = false;
|
|
173
174
|
return mfConfig;
|
|
174
175
|
};
|
|
175
|
-
function patchIgnoreWarning(
|
|
176
|
-
|
|
176
|
+
function patchIgnoreWarning(bundlerConfig) {
|
|
177
|
+
bundlerConfig.ignoreWarnings = bundlerConfig.ignoreWarnings || [];
|
|
177
178
|
const ignoredMsgs = [
|
|
178
179
|
"external script",
|
|
179
180
|
"process.env.WS_NO_BUFFER_UTIL",
|
|
180
181
|
`Can't resolve 'utf-8-validate`
|
|
181
182
|
];
|
|
182
|
-
ignoreWarnings.push((warning) => {
|
|
183
|
+
bundlerConfig.ignoreWarnings.push((warning) => {
|
|
183
184
|
if (ignoredMsgs.some((msg) => warning.message.includes(msg))) {
|
|
184
185
|
return true;
|
|
185
186
|
}
|
|
186
187
|
return false;
|
|
187
188
|
});
|
|
188
|
-
chain.ignoreWarnings(ignoreWarnings);
|
|
189
189
|
}
|
|
190
190
|
function addMyTypes2Ignored(chain, mfConfig) {
|
|
191
191
|
const watchOptions = chain.get("watchOptions");
|
|
@@ -224,44 +224,55 @@ function addMyTypes2Ignored(chain, mfConfig) {
|
|
|
224
224
|
});
|
|
225
225
|
}
|
|
226
226
|
function patchBundlerConfig(options) {
|
|
227
|
-
var _modernjsConfig_server, _modernjsConfig_deploy;
|
|
228
|
-
const {
|
|
227
|
+
var _modernjsConfig_server, _bundlerConfig_optimization, _bundlerConfig_optimization1, _bundlerConfig_output, _modernjsConfig_deploy;
|
|
228
|
+
const { bundlerConfig, modernjsConfig, isServer, mfConfig, bundlerType } = 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
|
-
|
|
235
|
-
|
|
236
|
-
|
|
230
|
+
(_bundlerConfig_optimization = bundlerConfig.optimization) === null || _bundlerConfig_optimization === void 0 ? true : delete _bundlerConfig_optimization.runtimeChunk;
|
|
231
|
+
patchIgnoreWarning(bundlerConfig);
|
|
232
|
+
if (bundlerConfig.output) {
|
|
233
|
+
var _bundlerConfig_output1, _bundlerConfig_output2;
|
|
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
|
+
}
|
|
237
240
|
}
|
|
238
|
-
const splitChunkConfig = chain.optimization.splitChunks.entries();
|
|
239
241
|
if (!isServer) {
|
|
240
|
-
(0, import_utils.autoDeleteSplitChunkCacheGroups)(mfConfig,
|
|
242
|
+
(0, import_utils.autoDeleteSplitChunkCacheGroups)(mfConfig, bundlerConfig);
|
|
241
243
|
}
|
|
242
|
-
if (!isServer && enableSSR &&
|
|
243
|
-
|
|
244
|
+
if (!isServer && enableSSR && typeof ((_bundlerConfig_optimization1 = bundlerConfig.optimization) === null || _bundlerConfig_optimization1 === void 0 ? void 0 : _bundlerConfig_optimization1.splitChunks) === "object" && bundlerConfig.optimization.splitChunks.cacheGroups) {
|
|
245
|
+
bundlerConfig.optimization.splitChunks.chunks = "async";
|
|
244
246
|
import_logger.default.warn(`splitChunks.chunks = async is not allowed with stream SSR mode, it will auto changed to "async"`);
|
|
245
247
|
}
|
|
246
|
-
if (isDev &&
|
|
248
|
+
if (isDev && ((_bundlerConfig_output = bundlerConfig.output) === null || _bundlerConfig_output === void 0 ? void 0 : _bundlerConfig_output.publicPath) === "auto") {
|
|
247
249
|
var _modernjsConfig_dev, _modernjsConfig_server1;
|
|
248
250
|
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;
|
|
249
251
|
const publicPath = `http://localhost:${port}/`;
|
|
250
|
-
|
|
252
|
+
bundlerConfig.output.publicPath = publicPath;
|
|
251
253
|
}
|
|
252
254
|
if (isServer && enableSSR) {
|
|
253
|
-
const
|
|
254
|
-
const
|
|
255
|
-
|
|
255
|
+
const { output } = bundlerConfig;
|
|
256
|
+
const uniqueName = mfConfig.name || (output === null || output === void 0 ? void 0 : output.uniqueName);
|
|
257
|
+
const chunkFileName = output === null || output === void 0 ? void 0 : output.chunkFilename;
|
|
258
|
+
if (output && typeof chunkFileName === "string" && uniqueName && !chunkFileName.includes(uniqueName)) {
|
|
256
259
|
const suffix = `${(0, import_sdk.encodeName)(uniqueName)}-[chunkhash].js`;
|
|
257
|
-
|
|
260
|
+
output.chunkFilename = chunkFileName.replace(".js", suffix);
|
|
258
261
|
}
|
|
259
262
|
}
|
|
260
263
|
if (isDev && enableSSR && !isServer) {
|
|
261
|
-
|
|
264
|
+
bundlerConfig.resolve.fallback = {
|
|
265
|
+
...bundlerConfig.resolve.fallback,
|
|
266
|
+
crypto: false,
|
|
267
|
+
stream: false,
|
|
268
|
+
vm: false
|
|
269
|
+
};
|
|
262
270
|
}
|
|
263
271
|
if (((_modernjsConfig_deploy = modernjsConfig.deploy) === null || _modernjsConfig_deploy === void 0 ? void 0 : _modernjsConfig_deploy.microFrontend) && Object.keys(mfConfig.exposes || {}).length) {
|
|
264
|
-
|
|
272
|
+
if (!bundlerConfig.optimization) {
|
|
273
|
+
bundlerConfig.optimization = {};
|
|
274
|
+
}
|
|
275
|
+
bundlerConfig.optimization.usedExports = false;
|
|
265
276
|
}
|
|
266
277
|
}
|
|
267
278
|
const localIpv4 = "127.0.0.1";
|
|
@@ -289,11 +300,34 @@ const getIPV4 = () => {
|
|
|
289
300
|
};
|
|
290
301
|
return ipv4Interface.address;
|
|
291
302
|
};
|
|
303
|
+
const SPLIT_CHUNK_MAP = {
|
|
304
|
+
REACT: "react",
|
|
305
|
+
ROUTER: "router",
|
|
306
|
+
LODASH: "lib-lodash",
|
|
307
|
+
ANTD: "lib-antd",
|
|
308
|
+
ARCO: "lib-arco",
|
|
309
|
+
SEMI: "lib-semi",
|
|
310
|
+
AXIOS: "lib-axios"
|
|
311
|
+
};
|
|
312
|
+
const SHARED_SPLIT_CHUNK_MAP = {
|
|
313
|
+
react: SPLIT_CHUNK_MAP.REACT,
|
|
314
|
+
"react-dom": SPLIT_CHUNK_MAP.REACT,
|
|
315
|
+
"react-router": SPLIT_CHUNK_MAP.ROUTER,
|
|
316
|
+
"react-router-dom": SPLIT_CHUNK_MAP.ROUTER,
|
|
317
|
+
"@remix-run/router": SPLIT_CHUNK_MAP.ROUTER,
|
|
318
|
+
lodash: SPLIT_CHUNK_MAP.LODASH,
|
|
319
|
+
"lodash-es": SPLIT_CHUNK_MAP.LODASH,
|
|
320
|
+
antd: SPLIT_CHUNK_MAP.ANTD,
|
|
321
|
+
"@arco-design/web-react": SPLIT_CHUNK_MAP.ARCO,
|
|
322
|
+
"@douyinfe/semi-ui": SPLIT_CHUNK_MAP.SEMI,
|
|
323
|
+
axios: SPLIT_CHUNK_MAP.AXIOS
|
|
324
|
+
};
|
|
292
325
|
// Annotate the CommonJS export names for ESM import in node:
|
|
293
326
|
0 && (module.exports = {
|
|
294
327
|
addMyTypes2Ignored,
|
|
295
328
|
getIPV4,
|
|
296
329
|
getMFConfig,
|
|
297
330
|
patchBundlerConfig,
|
|
331
|
+
patchIgnoreWarning,
|
|
298
332
|
patchMFConfig
|
|
299
333
|
});
|
|
@@ -109,3 +109,63 @@ 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,6 +8,17 @@ 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
|
+
}
|
|
11
22
|
var moduleFederationConfigPlugin = function(userConfig) {
|
|
12
23
|
return {
|
|
13
24
|
name: "@modern-js/plugin-module-federation-config",
|
|
@@ -34,20 +45,6 @@ var moduleFederationConfigPlugin = function(userConfig) {
|
|
|
34
45
|
ssrConfig = userConfig.ssrConfig || JSON.parse(JSON.stringify(mfConfig));
|
|
35
46
|
userConfig.ssrConfig = ssrConfig;
|
|
36
47
|
userConfig.csrConfig = csrConfig;
|
|
37
|
-
api.modifyBundlerChain(function(chain, param) {
|
|
38
|
-
var isProd = param.isProd, isServer = param.isServer;
|
|
39
|
-
addMyTypes2Ignored(chain, isServer ? ssrConfig : csrConfig);
|
|
40
|
-
var targetMFConfig = isServer ? ssrConfig : csrConfig;
|
|
41
|
-
patchMFConfig(targetMFConfig, isServer, userConfig.remoteIpStrategy || "ipv4");
|
|
42
|
-
patchBundlerConfig({
|
|
43
|
-
// @ts-expect-error chain type is not correct
|
|
44
|
-
chain,
|
|
45
|
-
isServer,
|
|
46
|
-
modernjsConfig,
|
|
47
|
-
mfConfig
|
|
48
|
-
});
|
|
49
|
-
userConfig.distOutputDir = chain.output.get("path") || path.resolve(process.cwd(), "dist");
|
|
50
|
-
});
|
|
51
48
|
api.config(function() {
|
|
52
49
|
var _userConfig_userConfig, _modernjsConfig_server, _modernjsConfig_source, _modernjsConfig_source1, _modernjsConfig_dev;
|
|
53
50
|
var bundlerType = api.getAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
|
|
@@ -63,6 +60,36 @@ var moduleFederationConfigPlugin = function(userConfig) {
|
|
|
63
60
|
var _modernjsConfig_source_enableAsyncEntry;
|
|
64
61
|
return {
|
|
65
62
|
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
|
+
},
|
|
66
93
|
devServer: {
|
|
67
94
|
headers: {
|
|
68
95
|
"Access-Control-Allow-Origin": "*",
|
|
@@ -101,6 +128,7 @@ var moduleFederationConfigPlugin = function(userConfig) {
|
|
|
101
128
|
var configPlugin_default = moduleFederationConfigPlugin;
|
|
102
129
|
export {
|
|
103
130
|
configPlugin_default as default,
|
|
131
|
+
modifyBundlerConfig,
|
|
104
132
|
moduleFederationConfigPlugin,
|
|
105
133
|
setEnv
|
|
106
134
|
};
|
package/dist/esm/cli/index.js
CHANGED
|
@@ -24,36 +24,43 @@ 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
|
-
|
|
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;
|
|
27
|
+
api.config(function() {
|
|
28
|
+
return {
|
|
29
|
+
tools: {
|
|
30
|
+
rspack: function rspack(config, param) {
|
|
31
|
+
var isServer = param.isServer;
|
|
32
|
+
var browserPluginOptions = internalModernPluginOptions.csrConfig;
|
|
33
|
+
if (!isServer) {
|
|
34
|
+
var _config_plugins;
|
|
35
|
+
internalModernPluginOptions.browserPlugin = new RspackModuleFederationPlugin(browserPluginOptions);
|
|
36
|
+
(_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(internalModernPluginOptions.browserPlugin);
|
|
50
37
|
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
38
|
+
},
|
|
39
|
+
webpack: function webpack(config, param) {
|
|
40
|
+
var isServer = param.isServer;
|
|
41
|
+
var _modernjsConfig_source;
|
|
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
|
+
}
|
|
55
62
|
}
|
|
56
|
-
}
|
|
63
|
+
};
|
|
57
64
|
});
|
|
58
65
|
return [
|
|
59
66
|
2
|