@module-federation/modern-js 0.0.0-next-20250221063001 → 0.0.0-next-20250221081237
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 +18 -42
- package/dist/cjs/cli/index.js +24 -30
- package/dist/cjs/cli/ssrPlugin.js +30 -38
- package/dist/cjs/cli/utils.js +27 -62
- package/dist/cjs/cli/utils.spec.js +0 -60
- package/dist/esm/cli/configPlugin.js +18 -45
- package/dist/esm/cli/index.js +28 -35
- package/dist/esm/cli/ssrPlugin.js +30 -42
- package/dist/esm/cli/utils.js +27 -60
- package/dist/esm/cli/utils.spec.js +1 -78
- package/dist/esm-node/cli/configPlugin.js +18 -41
- package/dist/esm-node/cli/index.js +24 -30
- package/dist/esm-node/cli/ssrPlugin.js +29 -38
- package/dist/esm-node/cli/utils.js +27 -61
- 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 +5 -6
- package/dist/types/types/index.d.ts +1 -1
- package/package.json +13 -13
|
@@ -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: [
|
|
@@ -62,17 +50,33 @@ const moduleFederationConfigPlugin = (userConfig) => ({
|
|
|
62
50
|
"@modern-js/plugin-module-federation"
|
|
63
51
|
],
|
|
64
52
|
setup: async (api) => {
|
|
53
|
+
var _userConfig_userConfig, _modernjsConfig_server;
|
|
65
54
|
const modernjsConfig = api.getConfig();
|
|
66
55
|
const mfConfig = await (0, import_utils.getMFConfig)(userConfig.originPluginOptions);
|
|
67
56
|
const csrConfig = userConfig.csrConfig || JSON.parse(JSON.stringify(mfConfig));
|
|
68
57
|
const ssrConfig = userConfig.ssrConfig || JSON.parse(JSON.stringify(mfConfig));
|
|
69
58
|
userConfig.ssrConfig = ssrConfig;
|
|
70
59
|
userConfig.csrConfig = csrConfig;
|
|
60
|
+
var _userConfig_userConfig_ssr;
|
|
61
|
+
const enableSSR = (_userConfig_userConfig_ssr = (_userConfig_userConfig = userConfig.userConfig) === null || _userConfig_userConfig === void 0 ? void 0 : _userConfig_userConfig.ssr) !== null && _userConfig_userConfig_ssr !== void 0 ? _userConfig_userConfig_ssr : Boolean(modernjsConfig === null || modernjsConfig === void 0 ? void 0 : (_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
|
|
62
|
+
api.modifyBundlerChain((chain, { isProd, isServer }) => {
|
|
63
|
+
(0, import_utils.addMyTypes2Ignored)(chain, isServer ? ssrConfig : csrConfig);
|
|
64
|
+
const targetMFConfig = isServer ? ssrConfig : csrConfig;
|
|
65
|
+
(0, import_utils.patchMFConfig)(targetMFConfig, isServer, userConfig.remoteIpStrategy || "ipv4");
|
|
66
|
+
(0, import_utils.patchBundlerConfig)({
|
|
67
|
+
// @ts-expect-error chain type is not correct
|
|
68
|
+
chain,
|
|
69
|
+
isServer,
|
|
70
|
+
modernjsConfig,
|
|
71
|
+
mfConfig,
|
|
72
|
+
enableSSR
|
|
73
|
+
});
|
|
74
|
+
userConfig.distOutputDir = chain.output.get("path") || import_path.default.resolve(process.cwd(), "dist");
|
|
75
|
+
});
|
|
71
76
|
api.config(() => {
|
|
72
|
-
var
|
|
77
|
+
var _modernjsConfig_source, _modernjsConfig_source1, _modernjsConfig_dev;
|
|
73
78
|
const bundlerType = api.getAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
|
|
74
79
|
const ipv4 = (0, import_utils.getIPV4)();
|
|
75
|
-
const enableSSR = ((_userConfig_userConfig = userConfig.userConfig) === null || _userConfig_userConfig === void 0 ? void 0 : _userConfig_userConfig.ssr) === false ? false : Boolean(modernjsConfig === null || modernjsConfig === void 0 ? void 0 : (_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
|
|
76
80
|
if (userConfig.remoteIpStrategy === void 0) {
|
|
77
81
|
if (!enableSSR) {
|
|
78
82
|
userConfig.remoteIpStrategy = "inherit";
|
|
@@ -83,33 +87,6 @@ const moduleFederationConfigPlugin = (userConfig) => ({
|
|
|
83
87
|
var _modernjsConfig_source_enableAsyncEntry;
|
|
84
88
|
return {
|
|
85
89
|
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
90
|
devServer: {
|
|
114
91
|
headers: {
|
|
115
92
|
"Access-Control-Allow-Origin": "*",
|
|
@@ -138,7 +115,6 @@ const moduleFederationConfigPlugin = (userConfig) => ({
|
|
|
138
115
|
var configPlugin_default = moduleFederationConfigPlugin;
|
|
139
116
|
// Annotate the CommonJS export names for ESM import in node:
|
|
140
117
|
0 && (module.exports = {
|
|
141
|
-
modifyBundlerConfig,
|
|
142
118
|
moduleFederationConfigPlugin,
|
|
143
119
|
setEnv
|
|
144
120
|
});
|
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, { 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: [
|
|
@@ -28,6 +28,7 @@ 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,
|
|
31
32
|
default: () => ssrPlugin_default,
|
|
32
33
|
moduleFederationSSRPlugin: () => moduleFederationSSRPlugin,
|
|
33
34
|
setEnv: () => setEnv
|
|
@@ -45,6 +46,7 @@ function setEnv() {
|
|
|
45
46
|
process.env["MF_DISABLE_EMIT_STATS"] = "true";
|
|
46
47
|
process.env["MF_SSR_PRJ"] = "true";
|
|
47
48
|
}
|
|
49
|
+
const CHAIN_MF_PLUGIN_ID = "plugin-module-federation-server";
|
|
48
50
|
const moduleFederationSSRPlugin = (pluginOptions) => ({
|
|
49
51
|
name: "@modern-js/plugin-module-federation-ssr",
|
|
50
52
|
pre: [
|
|
@@ -54,7 +56,8 @@ const moduleFederationSSRPlugin = (pluginOptions) => ({
|
|
|
54
56
|
setup: async (api) => {
|
|
55
57
|
var _pluginOptions_userConfig, _modernjsConfig_server;
|
|
56
58
|
const modernjsConfig = api.getConfig();
|
|
57
|
-
|
|
59
|
+
var _pluginOptions_userConfig_ssr;
|
|
60
|
+
const enableSSR = (_pluginOptions_userConfig_ssr = (_pluginOptions_userConfig = pluginOptions.userConfig) === null || _pluginOptions_userConfig === void 0 ? void 0 : _pluginOptions_userConfig.ssr) !== null && _pluginOptions_userConfig_ssr !== void 0 ? _pluginOptions_userConfig_ssr : Boolean(modernjsConfig === null || modernjsConfig === void 0 ? void 0 : (_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
|
|
58
61
|
if (!enableSSR) {
|
|
59
62
|
return;
|
|
60
63
|
}
|
|
@@ -76,33 +79,34 @@ const moduleFederationSSRPlugin = (pluginOptions) => ({
|
|
|
76
79
|
plugins
|
|
77
80
|
};
|
|
78
81
|
});
|
|
82
|
+
api.modifyBundlerChain((chain, { isServer }) => {
|
|
83
|
+
const bundlerType = api.getAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
|
|
84
|
+
const MFPlugin = bundlerType === "webpack" ? import_webpack.ModuleFederationPlugin : import_rspack.ModuleFederationPlugin;
|
|
85
|
+
if (isServer) {
|
|
86
|
+
if (!chain.plugins.has(CHAIN_MF_PLUGIN_ID)) {
|
|
87
|
+
chain.plugin(CHAIN_MF_PLUGIN_ID).use(MFPlugin, [
|
|
88
|
+
pluginOptions.ssrConfig
|
|
89
|
+
]).init((Plugin, args) => {
|
|
90
|
+
pluginOptions.nodePlugin = new Plugin(args[0]);
|
|
91
|
+
return pluginOptions.nodePlugin;
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (isServer) {
|
|
96
|
+
chain.target("async-node");
|
|
97
|
+
if (import_constant.isDev) {
|
|
98
|
+
chain.plugin("UniverseEntryChunkTrackerPlugin").use(import_universe_entry_chunk_tracker_plugin.default);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (import_constant.isDev && !isServer) {
|
|
102
|
+
chain.externals({
|
|
103
|
+
"@module-federation/node/utils": "NOT_USED_IN_BROWSER"
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
});
|
|
79
107
|
api.config(() => {
|
|
80
108
|
return {
|
|
81
109
|
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
110
|
devServer: {
|
|
107
111
|
before: [
|
|
108
112
|
(req, res, next) => {
|
|
@@ -128,19 +132,6 @@ const moduleFederationSSRPlugin = (pluginOptions) => ({
|
|
|
128
132
|
}
|
|
129
133
|
}
|
|
130
134
|
]
|
|
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
|
-
}
|
|
144
135
|
}
|
|
145
136
|
}
|
|
146
137
|
};
|
|
@@ -158,6 +149,7 @@ const moduleFederationSSRPlugin = (pluginOptions) => ({
|
|
|
158
149
|
var ssrPlugin_default = moduleFederationSSRPlugin;
|
|
159
150
|
// Annotate the CommonJS export names for ESM import in node:
|
|
160
151
|
0 && (module.exports = {
|
|
152
|
+
CHAIN_MF_PLUGIN_ID,
|
|
161
153
|
moduleFederationSSRPlugin,
|
|
162
154
|
setEnv
|
|
163
155
|
});
|
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,43 @@ function addMyTypes2Ignored(chain, mfConfig) {
|
|
|
224
224
|
});
|
|
225
225
|
}
|
|
226
226
|
function patchBundlerConfig(options) {
|
|
227
|
-
var
|
|
228
|
-
const {
|
|
229
|
-
|
|
230
|
-
(
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
}
|
|
237
|
-
if (!((_bundlerConfig_output2 = bundlerConfig.output) === null || _bundlerConfig_output2 === void 0 ? void 0 : _bundlerConfig_output2.uniqueName)) {
|
|
238
|
-
bundlerConfig.output.uniqueName = mfConfig.name;
|
|
239
|
-
}
|
|
227
|
+
var _modernjsConfig_deploy;
|
|
228
|
+
const { chain, modernjsConfig, isServer, mfConfig, enableSSR } = options;
|
|
229
|
+
chain.optimization.delete("runtimeChunk");
|
|
230
|
+
patchIgnoreWarning(chain);
|
|
231
|
+
if (!chain.output.get("chunkLoadingGlobal")) {
|
|
232
|
+
chain.output.chunkLoadingGlobal(`chunk_${mfConfig.name}`);
|
|
233
|
+
}
|
|
234
|
+
if (!chain.output.get("uniqueName")) {
|
|
235
|
+
chain.output.uniqueName(mfConfig.name);
|
|
240
236
|
}
|
|
237
|
+
const splitChunkConfig = chain.optimization.splitChunks.entries();
|
|
241
238
|
if (!isServer) {
|
|
242
|
-
(0, import_utils.autoDeleteSplitChunkCacheGroups)(mfConfig,
|
|
239
|
+
(0, import_utils.autoDeleteSplitChunkCacheGroups)(mfConfig, splitChunkConfig);
|
|
243
240
|
}
|
|
244
|
-
if (!isServer && enableSSR &&
|
|
245
|
-
|
|
241
|
+
if (!isServer && enableSSR && splitChunkConfig && typeof splitChunkConfig === "object" && splitChunkConfig.cacheGroups) {
|
|
242
|
+
splitChunkConfig.chunks = "async";
|
|
246
243
|
import_logger.default.warn(`splitChunks.chunks = async is not allowed with stream SSR mode, it will auto changed to "async"`);
|
|
247
244
|
}
|
|
248
|
-
if (isDev &&
|
|
249
|
-
var _modernjsConfig_dev,
|
|
250
|
-
const port = ((_modernjsConfig_dev = modernjsConfig.dev) === null || _modernjsConfig_dev === void 0 ? void 0 : _modernjsConfig_dev.port) || ((
|
|
245
|
+
if (isDev && chain.output.get("publicPath") === "auto") {
|
|
246
|
+
var _modernjsConfig_dev, _modernjsConfig_server;
|
|
247
|
+
const port = ((_modernjsConfig_dev = modernjsConfig.dev) === null || _modernjsConfig_dev === void 0 ? void 0 : _modernjsConfig_dev.port) || ((_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.port) || 8080;
|
|
251
248
|
const publicPath = `http://localhost:${port}/`;
|
|
252
|
-
|
|
249
|
+
chain.output.publicPath(publicPath);
|
|
253
250
|
}
|
|
254
251
|
if (isServer && enableSSR) {
|
|
255
|
-
const
|
|
256
|
-
const
|
|
257
|
-
|
|
258
|
-
if (output && typeof chunkFileName === "string" && uniqueName && !chunkFileName.includes(uniqueName)) {
|
|
252
|
+
const uniqueName = mfConfig.name || chain.output.get("uniqueName");
|
|
253
|
+
const chunkFileName = chain.output.get("chunkFilename");
|
|
254
|
+
if (typeof chunkFileName === "string" && uniqueName && !chunkFileName.includes(uniqueName)) {
|
|
259
255
|
const suffix = `${(0, import_sdk.encodeName)(uniqueName)}-[chunkhash].js`;
|
|
260
|
-
output.chunkFilename
|
|
256
|
+
chain.output.chunkFilename(chunkFileName.replace(".js", suffix));
|
|
261
257
|
}
|
|
262
258
|
}
|
|
263
259
|
if (isDev && enableSSR && !isServer) {
|
|
264
|
-
|
|
265
|
-
...bundlerConfig.resolve.fallback,
|
|
266
|
-
crypto: false,
|
|
267
|
-
stream: false,
|
|
268
|
-
vm: false
|
|
269
|
-
};
|
|
260
|
+
chain.resolve.fallback.set("crypto", false).set("stream", false).set("vm", false);
|
|
270
261
|
}
|
|
271
262
|
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;
|
|
263
|
+
chain.optimization.usedExports(false);
|
|
276
264
|
}
|
|
277
265
|
}
|
|
278
266
|
const localIpv4 = "127.0.0.1";
|
|
@@ -300,34 +288,11 @@ const getIPV4 = () => {
|
|
|
300
288
|
};
|
|
301
289
|
return ipv4Interface.address;
|
|
302
290
|
};
|
|
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
|
-
};
|
|
325
291
|
// Annotate the CommonJS export names for ESM import in node:
|
|
326
292
|
0 && (module.exports = {
|
|
327
293
|
addMyTypes2Ignored,
|
|
328
294
|
getIPV4,
|
|
329
295
|
getMFConfig,
|
|
330
296
|
patchBundlerConfig,
|
|
331
|
-
patchIgnoreWarning,
|
|
332
297
|
patchMFConfig
|
|
333
298
|
});
|
|
@@ -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",
|
|
@@ -30,7 +19,7 @@ var moduleFederationConfigPlugin = function(userConfig) {
|
|
|
30
19
|
],
|
|
31
20
|
setup: function() {
|
|
32
21
|
var _ref = _async_to_generator(function(api) {
|
|
33
|
-
var modernjsConfig, mfConfig, csrConfig, ssrConfig;
|
|
22
|
+
var _userConfig_userConfig, _modernjsConfig_server, modernjsConfig, mfConfig, csrConfig, ssrConfig, _userConfig_userConfig_ssr, enableSSR;
|
|
34
23
|
return _ts_generator(this, function(_state) {
|
|
35
24
|
switch (_state.label) {
|
|
36
25
|
case 0:
|
|
@@ -45,11 +34,26 @@ 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
|
+
enableSSR = (_userConfig_userConfig_ssr = (_userConfig_userConfig = userConfig.userConfig) === null || _userConfig_userConfig === void 0 ? void 0 : _userConfig_userConfig.ssr) !== null && _userConfig_userConfig_ssr !== void 0 ? _userConfig_userConfig_ssr : Boolean(modernjsConfig === null || modernjsConfig === void 0 ? void 0 : (_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
|
|
38
|
+
api.modifyBundlerChain(function(chain, param) {
|
|
39
|
+
var isProd = param.isProd, isServer = param.isServer;
|
|
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
|
+
enableSSR
|
|
50
|
+
});
|
|
51
|
+
userConfig.distOutputDir = chain.output.get("path") || path.resolve(process.cwd(), "dist");
|
|
52
|
+
});
|
|
48
53
|
api.config(function() {
|
|
49
|
-
var
|
|
54
|
+
var _modernjsConfig_source, _modernjsConfig_source1, _modernjsConfig_dev;
|
|
50
55
|
var bundlerType = api.getAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
|
|
51
56
|
var ipv4 = getIPV4();
|
|
52
|
-
var enableSSR = ((_userConfig_userConfig = userConfig.userConfig) === null || _userConfig_userConfig === void 0 ? void 0 : _userConfig_userConfig.ssr) === false ? false : Boolean(modernjsConfig === null || modernjsConfig === void 0 ? void 0 : (_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
|
|
53
57
|
if (userConfig.remoteIpStrategy === void 0) {
|
|
54
58
|
if (!enableSSR) {
|
|
55
59
|
userConfig.remoteIpStrategy = "inherit";
|
|
@@ -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
|
};
|