@module-federation/modern-js 0.3.1 → 0.3.2
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 +12 -12
- package/dist/cjs/cli/mfRuntimePlugins/resolve-entry-ipv4.js +4 -0
- package/dist/cjs/cli/ssrPlugin.js +27 -13
- package/dist/cjs/cli/utils.js +35 -0
- package/dist/cjs/cli/utils.spec.js +19 -4
- package/dist/esm/cli/configPlugin.js +12 -12
- package/dist/esm/cli/mfRuntimePlugins/resolve-entry-ipv4.js +4 -0
- package/dist/esm/cli/ssrPlugin.js +24 -11
- package/dist/esm/cli/utils.js +36 -0
- package/dist/esm/cli/utils.spec.js +21 -6
- package/dist/esm-node/cli/configPlugin.js +12 -12
- package/dist/esm-node/cli/mfRuntimePlugins/resolve-entry-ipv4.js +4 -0
- package/dist/esm-node/cli/ssrPlugin.js +24 -10
- package/dist/esm-node/cli/utils.js +34 -0
- package/dist/esm-node/cli/utils.spec.js +19 -4
- package/dist/types/cli/utils.d.ts +1 -0
- package/package.json +10 -10
|
@@ -43,7 +43,7 @@ function setEnv(enableSSR) {
|
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
function modifyBundlerConfig(options) {
|
|
46
|
-
const { mfConfig, config, isServer, modernjsConfig,
|
|
46
|
+
const { mfConfig, config, isServer, modernjsConfig, remoteIpStrategy = "ipv4" } = options;
|
|
47
47
|
(0, import_utils.patchMFConfig)(mfConfig, isServer, remoteIpStrategy);
|
|
48
48
|
(0, import_utils.patchBundlerConfig)({
|
|
49
49
|
bundlerConfig: config,
|
|
@@ -51,15 +51,6 @@ function modifyBundlerConfig(options) {
|
|
|
51
51
|
modernjsConfig,
|
|
52
52
|
mfConfig
|
|
53
53
|
});
|
|
54
|
-
if (bundlerType === "webpack") {
|
|
55
|
-
config.ignoreWarnings = config.ignoreWarnings || [];
|
|
56
|
-
config.ignoreWarnings.push((warning) => {
|
|
57
|
-
if (warning.message.includes("external script")) {
|
|
58
|
-
return true;
|
|
59
|
-
}
|
|
60
|
-
return false;
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
54
|
}
|
|
64
55
|
const moduleFederationConfigPlugin = (userConfig) => ({
|
|
65
56
|
name: "@modern-js/plugin-module-federation-config",
|
|
@@ -75,9 +66,17 @@ const moduleFederationConfigPlugin = (userConfig) => ({
|
|
|
75
66
|
userConfig.csrConfig = csrConfig;
|
|
76
67
|
return {
|
|
77
68
|
config: async () => {
|
|
78
|
-
var _modernjsConfig_dev;
|
|
69
|
+
var _modernjsConfig_server, _modernjsConfig_dev;
|
|
79
70
|
const bundlerType = useAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
|
|
80
71
|
const ipv4 = (0, import_utils.getIPV4)();
|
|
72
|
+
const enableSSR = Boolean(modernjsConfig === null || modernjsConfig === void 0 ? void 0 : (_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
|
|
73
|
+
if (userConfig.remoteIpStrategy === void 0) {
|
|
74
|
+
if (!enableSSR) {
|
|
75
|
+
userConfig.remoteIpStrategy = "inherit";
|
|
76
|
+
} else {
|
|
77
|
+
userConfig.remoteIpStrategy = "ipv4";
|
|
78
|
+
}
|
|
79
|
+
}
|
|
81
80
|
return {
|
|
82
81
|
tools: {
|
|
83
82
|
rspack(config, { isServer }) {
|
|
@@ -117,7 +116,8 @@ const moduleFederationConfigPlugin = (userConfig) => ({
|
|
|
117
116
|
"@modern-js/runtime/mf": require.resolve("@module-federation/modern-js/runtime")
|
|
118
117
|
},
|
|
119
118
|
define: {
|
|
120
|
-
FEDERATION_IPV4: JSON.stringify(ipv4)
|
|
119
|
+
FEDERATION_IPV4: JSON.stringify(ipv4),
|
|
120
|
+
REMOTE_IP_STRATEGY: JSON.stringify(userConfig.remoteIpStrategy)
|
|
121
121
|
}
|
|
122
122
|
},
|
|
123
123
|
dev: {
|
|
@@ -23,7 +23,11 @@ __export(resolve_entry_ipv4_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(resolve_entry_ipv4_exports);
|
|
24
24
|
var import_constant = require("../../constant");
|
|
25
25
|
const ipv4 = typeof FEDERATION_IPV4 !== "undefined" ? FEDERATION_IPV4 : "127.0.0.1";
|
|
26
|
+
const remoteIpStrategy = typeof REMOTE_IP_STRATEGY !== "undefined" ? REMOTE_IP_STRATEGY : "inherit";
|
|
26
27
|
function replaceObjectLocalhost(key, obj) {
|
|
28
|
+
if (remoteIpStrategy !== "ipv4") {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
27
31
|
if (!(key in obj)) {
|
|
28
32
|
return;
|
|
29
33
|
}
|
|
@@ -36,10 +36,10 @@ module.exports = __toCommonJS(ssrPlugin_exports);
|
|
|
36
36
|
var import_path = __toESM(require("path"));
|
|
37
37
|
var import_utils = require("@modern-js/utils");
|
|
38
38
|
var import_enhanced = require("@module-federation/enhanced");
|
|
39
|
+
var import_rspack = require("@module-federation/enhanced/rspack");
|
|
39
40
|
var import_node = require("@module-federation/node");
|
|
40
41
|
var import_manifest = require("./manifest");
|
|
41
|
-
var import_constant = require("
|
|
42
|
-
var import_constant2 = require("./constant");
|
|
42
|
+
var import_constant = require("./constant");
|
|
43
43
|
function setEnv() {
|
|
44
44
|
process.env["MF_DISABLE_EMIT_STATS"] = "true";
|
|
45
45
|
process.env["MF_SSR_PRJ"] = "true";
|
|
@@ -50,7 +50,7 @@ const moduleFederationSSRPlugin = (userConfig) => ({
|
|
|
50
50
|
"@modern-js/plugin-module-federation-config",
|
|
51
51
|
"@modern-js/plugin-module-federation"
|
|
52
52
|
],
|
|
53
|
-
setup: async ({ useConfigContext }) => {
|
|
53
|
+
setup: async ({ useConfigContext, useAppContext }) => {
|
|
54
54
|
var _modernjsConfig_server;
|
|
55
55
|
const modernjsConfig = useConfigContext();
|
|
56
56
|
const enableSSR = Boolean(modernjsConfig === null || modernjsConfig === void 0 ? void 0 : (_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
|
|
@@ -60,7 +60,7 @@ const moduleFederationSSRPlugin = (userConfig) => ({
|
|
|
60
60
|
setEnv();
|
|
61
61
|
return {
|
|
62
62
|
_internalRuntimePlugins: ({ entrypoint, plugins }) => {
|
|
63
|
-
if (!
|
|
63
|
+
if (!import_constant.isDev) {
|
|
64
64
|
return {
|
|
65
65
|
entrypoint,
|
|
66
66
|
plugins
|
|
@@ -77,25 +77,36 @@ const moduleFederationSSRPlugin = (userConfig) => ({
|
|
|
77
77
|
};
|
|
78
78
|
},
|
|
79
79
|
config: async () => {
|
|
80
|
+
var _modernjsConfig_source, _modernjsConfig_source1;
|
|
81
|
+
const bundlerType = useAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
|
|
82
|
+
var _modernjsConfig_source_enableAsyncEntry;
|
|
80
83
|
return {
|
|
84
|
+
source: {
|
|
85
|
+
enableAsyncEntry: bundlerType === "rspack" ? (_modernjsConfig_source_enableAsyncEntry = (_modernjsConfig_source = modernjsConfig.source) === null || _modernjsConfig_source === void 0 ? void 0 : _modernjsConfig_source.enableAsyncEntry) !== null && _modernjsConfig_source_enableAsyncEntry !== void 0 ? _modernjsConfig_source_enableAsyncEntry : true : (_modernjsConfig_source1 = modernjsConfig.source) === null || _modernjsConfig_source1 === void 0 ? void 0 : _modernjsConfig_source1.enableAsyncEntry
|
|
86
|
+
},
|
|
81
87
|
tools: {
|
|
82
88
|
rspack(config, { isServer }) {
|
|
83
89
|
if (isServer) {
|
|
84
|
-
|
|
90
|
+
if (!userConfig.nodePlugin) {
|
|
91
|
+
var _config_plugins;
|
|
92
|
+
userConfig.nodePlugin = new import_rspack.ModuleFederationPlugin(userConfig.ssrConfig);
|
|
93
|
+
(_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(userConfig.nodePlugin);
|
|
94
|
+
}
|
|
95
|
+
} else {
|
|
96
|
+
var _config_output;
|
|
97
|
+
userConfig.distOutputDir = userConfig.distOutputDir || ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.path) || import_path.default.resolve(process.cwd(), "dist");
|
|
85
98
|
}
|
|
86
99
|
},
|
|
87
100
|
webpack(config, { isServer }) {
|
|
88
101
|
if (isServer) {
|
|
89
|
-
var _config_plugins;
|
|
90
102
|
if (!userConfig.nodePlugin) {
|
|
91
|
-
var
|
|
103
|
+
var _config_plugins;
|
|
92
104
|
userConfig.nodePlugin = new import_enhanced.ModuleFederationPlugin(userConfig.ssrConfig);
|
|
93
|
-
(
|
|
105
|
+
(_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(userConfig.nodePlugin);
|
|
94
106
|
}
|
|
95
|
-
(
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
(_config_plugins2 = config.plugins) === null || _config_plugins2 === void 0 ? void 0 : _config_plugins2.push(new import_node.EntryChunkTrackerPlugin());
|
|
107
|
+
if (import_constant.isDev) {
|
|
108
|
+
var _config_plugins1;
|
|
109
|
+
(_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(new import_node.EntryChunkTrackerPlugin());
|
|
99
110
|
}
|
|
100
111
|
} else {
|
|
101
112
|
var _config_output;
|
|
@@ -131,7 +142,10 @@ const moduleFederationSSRPlugin = (userConfig) => ({
|
|
|
131
142
|
]
|
|
132
143
|
},
|
|
133
144
|
bundlerChain(chain, { isServer }) {
|
|
134
|
-
if (
|
|
145
|
+
if (isServer) {
|
|
146
|
+
chain.target("async-node");
|
|
147
|
+
}
|
|
148
|
+
if (import_constant.isDev && !isServer) {
|
|
135
149
|
chain.externals({
|
|
136
150
|
"@module-federation/node/utils": "NOT_USED_IN_BROWSER"
|
|
137
151
|
});
|
package/dist/cjs/cli/utils.js
CHANGED
|
@@ -31,6 +31,7 @@ __export(utils_exports, {
|
|
|
31
31
|
getIPV4: () => getIPV4,
|
|
32
32
|
getMFConfig: () => getMFConfig,
|
|
33
33
|
patchBundlerConfig: () => patchBundlerConfig,
|
|
34
|
+
patchIgnoreWarning: () => patchIgnoreWarning,
|
|
34
35
|
patchMFConfig: () => patchMFConfig
|
|
35
36
|
});
|
|
36
37
|
module.exports = __toCommonJS(utils_exports);
|
|
@@ -138,6 +139,7 @@ const patchMFConfig = (mfConfig, isServer, remoteIpStrategy) => {
|
|
|
138
139
|
injectRuntimePlugins(import_path.default.resolve(__dirname, "./mfRuntimePlugins/resolve-entry-ipv4.js"), runtimePlugins);
|
|
139
140
|
}
|
|
140
141
|
if (isServer) {
|
|
142
|
+
injectRuntimePlugins(require.resolve("@module-federation/node/runtimePlugin"), runtimePlugins);
|
|
141
143
|
if (isDev) {
|
|
142
144
|
injectRuntimePlugins(require.resolve("@module-federation/node/record-dynamic-remote-entry-hash-plugin"), runtimePlugins);
|
|
143
145
|
}
|
|
@@ -168,11 +170,43 @@ const patchMFConfig = (mfConfig, isServer, remoteIpStrategy) => {
|
|
|
168
170
|
mfConfig.dev = false;
|
|
169
171
|
return mfConfig;
|
|
170
172
|
};
|
|
173
|
+
function patchIgnoreWarning(bundlerConfig) {
|
|
174
|
+
bundlerConfig.ignoreWarnings = bundlerConfig.ignoreWarnings || [];
|
|
175
|
+
const ignoredMsgs = [
|
|
176
|
+
"external script",
|
|
177
|
+
"process.env.WS_NO_BUFFER_UTIL",
|
|
178
|
+
`Can't resolve 'utf-8-validate`
|
|
179
|
+
];
|
|
180
|
+
bundlerConfig.ignoreWarnings.push((warning) => {
|
|
181
|
+
if (ignoredMsgs.some((msg) => warning.message.includes(msg))) {
|
|
182
|
+
return true;
|
|
183
|
+
}
|
|
184
|
+
return false;
|
|
185
|
+
});
|
|
186
|
+
}
|
|
171
187
|
function patchBundlerConfig(options) {
|
|
172
188
|
var _modernjsConfig_server, _bundlerConfig_optimization, _bundlerConfig_optimization1, _bundlerConfig_output, _modernjsConfig_deploy;
|
|
173
189
|
const { bundlerConfig, modernjsConfig, isServer, mfConfig } = options;
|
|
174
190
|
const enableSSR = Boolean((_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
|
|
175
191
|
(_bundlerConfig_optimization = bundlerConfig.optimization) === null || _bundlerConfig_optimization === void 0 ? true : delete _bundlerConfig_optimization.runtimeChunk;
|
|
192
|
+
patchIgnoreWarning(bundlerConfig);
|
|
193
|
+
bundlerConfig.watchOptions = bundlerConfig.watchOptions || {};
|
|
194
|
+
if (!Array.isArray(bundlerConfig.watchOptions.ignored)) {
|
|
195
|
+
if (bundlerConfig.watchOptions.ignored) {
|
|
196
|
+
bundlerConfig.watchOptions.ignored = [
|
|
197
|
+
bundlerConfig.watchOptions.ignored
|
|
198
|
+
];
|
|
199
|
+
} else {
|
|
200
|
+
bundlerConfig.watchOptions.ignored = [];
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
if (mfConfig.dts !== false) {
|
|
204
|
+
if (typeof mfConfig.dts === "object" && typeof mfConfig.dts.consumeTypes === "object" && mfConfig.dts.consumeTypes.remoteTypesFolder) {
|
|
205
|
+
bundlerConfig.watchOptions.ignored.push(mfConfig.dts.consumeTypes.remoteTypesFolder);
|
|
206
|
+
} else {
|
|
207
|
+
bundlerConfig.watchOptions.ignored.push("@mf-types");
|
|
208
|
+
}
|
|
209
|
+
}
|
|
176
210
|
if (bundlerConfig.output) {
|
|
177
211
|
var _bundlerConfig_output1, _bundlerConfig_output2;
|
|
178
212
|
if (!((_bundlerConfig_output1 = bundlerConfig.output) === null || _bundlerConfig_output1 === void 0 ? void 0 : _bundlerConfig_output1.chunkLoadingGlobal)) {
|
|
@@ -290,5 +324,6 @@ function autoDeleteSplitChunkCacheGroups(mfConfig, bundlerConfig) {
|
|
|
290
324
|
getIPV4,
|
|
291
325
|
getMFConfig,
|
|
292
326
|
patchBundlerConfig,
|
|
327
|
+
patchIgnoreWarning,
|
|
293
328
|
patchMFConfig
|
|
294
329
|
});
|
|
@@ -61,6 +61,7 @@ const mfConfig = {
|
|
|
61
61
|
remoteType: "script",
|
|
62
62
|
runtimePlugins: [
|
|
63
63
|
import_path.default.resolve(__dirname, "./mfRuntimePlugins/shared-strategy.js"),
|
|
64
|
+
require.resolve("@module-federation/node/runtimePlugin"),
|
|
64
65
|
import_path.default.resolve(__dirname, "./mfRuntimePlugins/inject-node-fetch.js")
|
|
65
66
|
],
|
|
66
67
|
shared: {
|
|
@@ -128,13 +129,20 @@ const mfConfig = {
|
|
|
128
129
|
},
|
|
129
130
|
mfConfig
|
|
130
131
|
});
|
|
131
|
-
|
|
132
|
+
const expectedConfig = {
|
|
132
133
|
output: {
|
|
133
134
|
chunkLoadingGlobal: "chunk_host",
|
|
134
135
|
publicPath: "auto",
|
|
135
136
|
uniqueName: "host"
|
|
137
|
+
},
|
|
138
|
+
watchOptions: {
|
|
139
|
+
ignored: [
|
|
140
|
+
"@mf-types"
|
|
141
|
+
]
|
|
136
142
|
}
|
|
137
|
-
}
|
|
143
|
+
};
|
|
144
|
+
bundlerConfig === null || bundlerConfig === void 0 ? true : delete bundlerConfig.ignoreWarnings;
|
|
145
|
+
(0, import_vitest.expect)(bundlerConfig).toStrictEqual(expectedConfig);
|
|
138
146
|
});
|
|
139
147
|
(0, import_vitest.it)("patchBundlerConfig: client", async () => {
|
|
140
148
|
const bundlerConfig = {
|
|
@@ -154,12 +162,19 @@ const mfConfig = {
|
|
|
154
162
|
},
|
|
155
163
|
mfConfig
|
|
156
164
|
});
|
|
157
|
-
|
|
165
|
+
const expectedConfig = {
|
|
158
166
|
output: {
|
|
159
167
|
chunkLoadingGlobal: "chunk_host",
|
|
160
168
|
publicPath: "auto",
|
|
161
169
|
uniqueName: "host"
|
|
170
|
+
},
|
|
171
|
+
watchOptions: {
|
|
172
|
+
ignored: [
|
|
173
|
+
"@mf-types"
|
|
174
|
+
]
|
|
162
175
|
}
|
|
163
|
-
}
|
|
176
|
+
};
|
|
177
|
+
bundlerConfig === null || bundlerConfig === void 0 ? true : delete bundlerConfig.ignoreWarnings;
|
|
178
|
+
(0, import_vitest.expect)(bundlerConfig).toStrictEqual(expectedConfig);
|
|
164
179
|
});
|
|
165
180
|
});
|
|
@@ -9,7 +9,7 @@ function setEnv(enableSSR) {
|
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
function modifyBundlerConfig(options) {
|
|
12
|
-
var mfConfig = options.mfConfig, config = options.config, isServer = options.isServer, modernjsConfig = options.modernjsConfig,
|
|
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;
|
|
13
13
|
patchMFConfig(mfConfig, isServer, remoteIpStrategy);
|
|
14
14
|
patchBundlerConfig({
|
|
15
15
|
bundlerConfig: config,
|
|
@@ -17,15 +17,6 @@ function modifyBundlerConfig(options) {
|
|
|
17
17
|
modernjsConfig,
|
|
18
18
|
mfConfig
|
|
19
19
|
});
|
|
20
|
-
if (bundlerType === "webpack") {
|
|
21
|
-
config.ignoreWarnings = config.ignoreWarnings || [];
|
|
22
|
-
config.ignoreWarnings.push(function(warning) {
|
|
23
|
-
if (warning.message.includes("external script")) {
|
|
24
|
-
return true;
|
|
25
|
-
}
|
|
26
|
-
return false;
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
20
|
}
|
|
30
21
|
var moduleFederationConfigPlugin = function(userConfig) {
|
|
31
22
|
return {
|
|
@@ -55,10 +46,18 @@ var moduleFederationConfigPlugin = function(userConfig) {
|
|
|
55
46
|
2,
|
|
56
47
|
{
|
|
57
48
|
config: /* @__PURE__ */ _async_to_generator(function() {
|
|
58
|
-
var _modernjsConfig_dev, bundlerType, ipv4;
|
|
49
|
+
var _modernjsConfig_server, _modernjsConfig_dev, bundlerType, ipv4, enableSSR;
|
|
59
50
|
return _ts_generator(this, function(_state2) {
|
|
60
51
|
bundlerType = useAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
|
|
61
52
|
ipv4 = getIPV4();
|
|
53
|
+
enableSSR = Boolean(modernjsConfig === null || modernjsConfig === void 0 ? void 0 : (_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
|
|
54
|
+
if (userConfig.remoteIpStrategy === void 0) {
|
|
55
|
+
if (!enableSSR) {
|
|
56
|
+
userConfig.remoteIpStrategy = "inherit";
|
|
57
|
+
} else {
|
|
58
|
+
userConfig.remoteIpStrategy = "ipv4";
|
|
59
|
+
}
|
|
60
|
+
}
|
|
62
61
|
return [
|
|
63
62
|
2,
|
|
64
63
|
{
|
|
@@ -102,7 +101,8 @@ var moduleFederationConfigPlugin = function(userConfig) {
|
|
|
102
101
|
"@modern-js/runtime/mf": require.resolve("@module-federation/modern-js/runtime")
|
|
103
102
|
},
|
|
104
103
|
define: {
|
|
105
|
-
FEDERATION_IPV4: JSON.stringify(ipv4)
|
|
104
|
+
FEDERATION_IPV4: JSON.stringify(ipv4),
|
|
105
|
+
REMOTE_IP_STRATEGY: JSON.stringify(userConfig.remoteIpStrategy)
|
|
106
106
|
}
|
|
107
107
|
},
|
|
108
108
|
dev: {
|
|
@@ -2,7 +2,11 @@ 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 { LOCALHOST } from "../../constant";
|
|
4
4
|
var ipv4 = typeof FEDERATION_IPV4 !== "undefined" ? FEDERATION_IPV4 : "127.0.0.1";
|
|
5
|
+
var remoteIpStrategy = typeof REMOTE_IP_STRATEGY !== "undefined" ? REMOTE_IP_STRATEGY : "inherit";
|
|
5
6
|
function replaceObjectLocalhost(key, obj) {
|
|
7
|
+
if (remoteIpStrategy !== "ipv4") {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
6
10
|
if (!(key in obj)) {
|
|
7
11
|
return;
|
|
8
12
|
}
|
|
@@ -3,9 +3,9 @@ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
|
3
3
|
import path from "path";
|
|
4
4
|
import { fs } from "@modern-js/utils";
|
|
5
5
|
import { ModuleFederationPlugin } from "@module-federation/enhanced";
|
|
6
|
-
import {
|
|
6
|
+
import { ModuleFederationPlugin as RspackModuleFederationPlugin } from "@module-federation/enhanced/rspack";
|
|
7
|
+
import { EntryChunkTrackerPlugin } from "@module-federation/node";
|
|
7
8
|
import { updateStatsAndManifest } from "./manifest";
|
|
8
|
-
import { PLUGIN_IDENTIFIER } from "../constant";
|
|
9
9
|
import { isDev } from "./constant";
|
|
10
10
|
function setEnv() {
|
|
11
11
|
process.env["MF_DISABLE_EMIT_STATS"] = "true";
|
|
@@ -20,9 +20,9 @@ var moduleFederationSSRPlugin = function(userConfig) {
|
|
|
20
20
|
],
|
|
21
21
|
setup: function() {
|
|
22
22
|
var _ref = _async_to_generator(function(param) {
|
|
23
|
-
var useConfigContext, _modernjsConfig_server, modernjsConfig, enableSSR;
|
|
23
|
+
var useConfigContext, useAppContext, _modernjsConfig_server, modernjsConfig, enableSSR;
|
|
24
24
|
return _ts_generator(this, function(_state) {
|
|
25
|
-
useConfigContext = param.useConfigContext;
|
|
25
|
+
useConfigContext = param.useConfigContext, useAppContext = param.useAppContext;
|
|
26
26
|
modernjsConfig = useConfigContext();
|
|
27
27
|
enableSSR = Boolean(modernjsConfig === null || modernjsConfig === void 0 ? void 0 : (_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
|
|
28
28
|
if (!enableSSR) {
|
|
@@ -54,30 +54,40 @@ var moduleFederationSSRPlugin = function(userConfig) {
|
|
|
54
54
|
};
|
|
55
55
|
},
|
|
56
56
|
config: /* @__PURE__ */ _async_to_generator(function() {
|
|
57
|
+
var _modernjsConfig_source, _modernjsConfig_source1, bundlerType, _modernjsConfig_source_enableAsyncEntry;
|
|
57
58
|
return _ts_generator(this, function(_state2) {
|
|
59
|
+
bundlerType = useAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
|
|
58
60
|
return [
|
|
59
61
|
2,
|
|
60
62
|
{
|
|
63
|
+
source: {
|
|
64
|
+
enableAsyncEntry: bundlerType === "rspack" ? (_modernjsConfig_source_enableAsyncEntry = (_modernjsConfig_source = modernjsConfig.source) === null || _modernjsConfig_source === void 0 ? void 0 : _modernjsConfig_source.enableAsyncEntry) !== null && _modernjsConfig_source_enableAsyncEntry !== void 0 ? _modernjsConfig_source_enableAsyncEntry : true : (_modernjsConfig_source1 = modernjsConfig.source) === null || _modernjsConfig_source1 === void 0 ? void 0 : _modernjsConfig_source1.enableAsyncEntry
|
|
65
|
+
},
|
|
61
66
|
tools: {
|
|
62
67
|
rspack: function rspack(config, param2) {
|
|
63
68
|
var isServer = param2.isServer;
|
|
64
69
|
if (isServer) {
|
|
65
|
-
|
|
70
|
+
if (!userConfig.nodePlugin) {
|
|
71
|
+
var _config_plugins;
|
|
72
|
+
userConfig.nodePlugin = new RspackModuleFederationPlugin(userConfig.ssrConfig);
|
|
73
|
+
(_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(userConfig.nodePlugin);
|
|
74
|
+
}
|
|
75
|
+
} else {
|
|
76
|
+
var _config_output;
|
|
77
|
+
userConfig.distOutputDir = userConfig.distOutputDir || ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.path) || path.resolve(process.cwd(), "dist");
|
|
66
78
|
}
|
|
67
79
|
},
|
|
68
80
|
webpack: function webpack(config, param2) {
|
|
69
81
|
var isServer = param2.isServer;
|
|
70
82
|
if (isServer) {
|
|
71
|
-
var _config_plugins;
|
|
72
83
|
if (!userConfig.nodePlugin) {
|
|
73
|
-
var
|
|
84
|
+
var _config_plugins;
|
|
74
85
|
userConfig.nodePlugin = new ModuleFederationPlugin(userConfig.ssrConfig);
|
|
75
|
-
(
|
|
86
|
+
(_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(userConfig.nodePlugin);
|
|
76
87
|
}
|
|
77
|
-
(_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(new StreamingTargetPlugin(userConfig.nodePlugin));
|
|
78
88
|
if (isDev) {
|
|
79
|
-
var
|
|
80
|
-
(
|
|
89
|
+
var _config_plugins1;
|
|
90
|
+
(_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(new EntryChunkTrackerPlugin());
|
|
81
91
|
}
|
|
82
92
|
} else {
|
|
83
93
|
var _config_output;
|
|
@@ -114,6 +124,9 @@ var moduleFederationSSRPlugin = function(userConfig) {
|
|
|
114
124
|
},
|
|
115
125
|
bundlerChain: function bundlerChain(chain, param2) {
|
|
116
126
|
var isServer = param2.isServer;
|
|
127
|
+
if (isServer) {
|
|
128
|
+
chain.target("async-node");
|
|
129
|
+
}
|
|
117
130
|
if (isDev && !isServer) {
|
|
118
131
|
chain.externals({
|
|
119
132
|
"@module-federation/node/utils": "NOT_USED_IN_BROWSER"
|
package/dist/esm/cli/utils.js
CHANGED
|
@@ -132,6 +132,7 @@ var patchMFConfig = function(mfConfig, isServer, remoteIpStrategy) {
|
|
|
132
132
|
injectRuntimePlugins(path.resolve(__dirname, "./mfRuntimePlugins/resolve-entry-ipv4.js"), runtimePlugins);
|
|
133
133
|
}
|
|
134
134
|
if (isServer) {
|
|
135
|
+
injectRuntimePlugins(require.resolve("@module-federation/node/runtimePlugin"), runtimePlugins);
|
|
135
136
|
if (isDev) {
|
|
136
137
|
injectRuntimePlugins(require.resolve("@module-federation/node/record-dynamic-remote-entry-hash-plugin"), runtimePlugins);
|
|
137
138
|
}
|
|
@@ -162,11 +163,45 @@ var patchMFConfig = function(mfConfig, isServer, remoteIpStrategy) {
|
|
|
162
163
|
mfConfig.dev = false;
|
|
163
164
|
return mfConfig;
|
|
164
165
|
};
|
|
166
|
+
function patchIgnoreWarning(bundlerConfig) {
|
|
167
|
+
bundlerConfig.ignoreWarnings = bundlerConfig.ignoreWarnings || [];
|
|
168
|
+
var ignoredMsgs = [
|
|
169
|
+
"external script",
|
|
170
|
+
"process.env.WS_NO_BUFFER_UTIL",
|
|
171
|
+
"Can't resolve 'utf-8-validate"
|
|
172
|
+
];
|
|
173
|
+
bundlerConfig.ignoreWarnings.push(function(warning) {
|
|
174
|
+
if (ignoredMsgs.some(function(msg) {
|
|
175
|
+
return warning.message.includes(msg);
|
|
176
|
+
})) {
|
|
177
|
+
return true;
|
|
178
|
+
}
|
|
179
|
+
return false;
|
|
180
|
+
});
|
|
181
|
+
}
|
|
165
182
|
function patchBundlerConfig(options) {
|
|
166
183
|
var _modernjsConfig_server, _bundlerConfig_optimization, _bundlerConfig_optimization1, _bundlerConfig_output, _modernjsConfig_deploy;
|
|
167
184
|
var bundlerConfig = options.bundlerConfig, modernjsConfig = options.modernjsConfig, isServer = options.isServer, mfConfig = options.mfConfig;
|
|
168
185
|
var enableSSR = Boolean((_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
|
|
169
186
|
(_bundlerConfig_optimization = bundlerConfig.optimization) === null || _bundlerConfig_optimization === void 0 ? true : delete _bundlerConfig_optimization.runtimeChunk;
|
|
187
|
+
patchIgnoreWarning(bundlerConfig);
|
|
188
|
+
bundlerConfig.watchOptions = bundlerConfig.watchOptions || {};
|
|
189
|
+
if (!Array.isArray(bundlerConfig.watchOptions.ignored)) {
|
|
190
|
+
if (bundlerConfig.watchOptions.ignored) {
|
|
191
|
+
bundlerConfig.watchOptions.ignored = [
|
|
192
|
+
bundlerConfig.watchOptions.ignored
|
|
193
|
+
];
|
|
194
|
+
} else {
|
|
195
|
+
bundlerConfig.watchOptions.ignored = [];
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
if (mfConfig.dts !== false) {
|
|
199
|
+
if (typeof mfConfig.dts === "object" && typeof mfConfig.dts.consumeTypes === "object" && mfConfig.dts.consumeTypes.remoteTypesFolder) {
|
|
200
|
+
bundlerConfig.watchOptions.ignored.push(mfConfig.dts.consumeTypes.remoteTypesFolder);
|
|
201
|
+
} else {
|
|
202
|
+
bundlerConfig.watchOptions.ignored.push("@mf-types");
|
|
203
|
+
}
|
|
204
|
+
}
|
|
170
205
|
if (bundlerConfig.output) {
|
|
171
206
|
var _bundlerConfig_output1, _bundlerConfig_output2;
|
|
172
207
|
if (!((_bundlerConfig_output1 = bundlerConfig.output) === null || _bundlerConfig_output1 === void 0 ? void 0 : _bundlerConfig_output1.chunkLoadingGlobal)) {
|
|
@@ -299,5 +334,6 @@ export {
|
|
|
299
334
|
getIPV4,
|
|
300
335
|
getMFConfig,
|
|
301
336
|
patchBundlerConfig,
|
|
337
|
+
patchIgnoreWarning,
|
|
302
338
|
patchMFConfig
|
|
303
339
|
};
|
|
@@ -43,6 +43,7 @@ describe("patchMFConfig", /* @__PURE__ */ _async_to_generator(function() {
|
|
|
43
43
|
remoteType: "script",
|
|
44
44
|
runtimePlugins: [
|
|
45
45
|
path.resolve(__dirname, "./mfRuntimePlugins/shared-strategy.js"),
|
|
46
|
+
require.resolve("@module-federation/node/runtimePlugin"),
|
|
46
47
|
path.resolve(__dirname, "./mfRuntimePlugins/inject-node-fetch.js")
|
|
47
48
|
],
|
|
48
49
|
shared: {
|
|
@@ -108,7 +109,7 @@ describe("patchMFConfig", /* @__PURE__ */ _async_to_generator(function() {
|
|
|
108
109
|
describe("patchBundlerConfig", /* @__PURE__ */ _async_to_generator(function() {
|
|
109
110
|
return _ts_generator(this, function(_state) {
|
|
110
111
|
it("patchBundlerConfig: server", /* @__PURE__ */ _async_to_generator(function() {
|
|
111
|
-
var bundlerConfig;
|
|
112
|
+
var bundlerConfig, expectedConfig;
|
|
112
113
|
return _ts_generator(this, function(_state2) {
|
|
113
114
|
bundlerConfig = {
|
|
114
115
|
output: {
|
|
@@ -127,20 +128,27 @@ describe("patchBundlerConfig", /* @__PURE__ */ _async_to_generator(function() {
|
|
|
127
128
|
},
|
|
128
129
|
mfConfig
|
|
129
130
|
});
|
|
130
|
-
|
|
131
|
+
expectedConfig = {
|
|
131
132
|
output: {
|
|
132
133
|
chunkLoadingGlobal: "chunk_host",
|
|
133
134
|
publicPath: "auto",
|
|
134
135
|
uniqueName: "host"
|
|
136
|
+
},
|
|
137
|
+
watchOptions: {
|
|
138
|
+
ignored: [
|
|
139
|
+
"@mf-types"
|
|
140
|
+
]
|
|
135
141
|
}
|
|
136
|
-
}
|
|
142
|
+
};
|
|
143
|
+
bundlerConfig === null || bundlerConfig === void 0 ? true : delete bundlerConfig.ignoreWarnings;
|
|
144
|
+
expect(bundlerConfig).toStrictEqual(expectedConfig);
|
|
137
145
|
return [
|
|
138
146
|
2
|
|
139
147
|
];
|
|
140
148
|
});
|
|
141
149
|
}));
|
|
142
150
|
it("patchBundlerConfig: client", /* @__PURE__ */ _async_to_generator(function() {
|
|
143
|
-
var bundlerConfig;
|
|
151
|
+
var bundlerConfig, expectedConfig;
|
|
144
152
|
return _ts_generator(this, function(_state2) {
|
|
145
153
|
bundlerConfig = {
|
|
146
154
|
output: {
|
|
@@ -159,13 +167,20 @@ describe("patchBundlerConfig", /* @__PURE__ */ _async_to_generator(function() {
|
|
|
159
167
|
},
|
|
160
168
|
mfConfig
|
|
161
169
|
});
|
|
162
|
-
|
|
170
|
+
expectedConfig = {
|
|
163
171
|
output: {
|
|
164
172
|
chunkLoadingGlobal: "chunk_host",
|
|
165
173
|
publicPath: "auto",
|
|
166
174
|
uniqueName: "host"
|
|
175
|
+
},
|
|
176
|
+
watchOptions: {
|
|
177
|
+
ignored: [
|
|
178
|
+
"@mf-types"
|
|
179
|
+
]
|
|
167
180
|
}
|
|
168
|
-
}
|
|
181
|
+
};
|
|
182
|
+
bundlerConfig === null || bundlerConfig === void 0 ? true : delete bundlerConfig.ignoreWarnings;
|
|
183
|
+
expect(bundlerConfig).toStrictEqual(expectedConfig);
|
|
169
184
|
return [
|
|
170
185
|
2
|
|
171
186
|
];
|
|
@@ -7,7 +7,7 @@ function setEnv(enableSSR) {
|
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
9
|
function modifyBundlerConfig(options) {
|
|
10
|
-
const { mfConfig, config, isServer, modernjsConfig,
|
|
10
|
+
const { mfConfig, config, isServer, modernjsConfig, remoteIpStrategy = "ipv4" } = options;
|
|
11
11
|
patchMFConfig(mfConfig, isServer, remoteIpStrategy);
|
|
12
12
|
patchBundlerConfig({
|
|
13
13
|
bundlerConfig: config,
|
|
@@ -15,15 +15,6 @@ function modifyBundlerConfig(options) {
|
|
|
15
15
|
modernjsConfig,
|
|
16
16
|
mfConfig
|
|
17
17
|
});
|
|
18
|
-
if (bundlerType === "webpack") {
|
|
19
|
-
config.ignoreWarnings = config.ignoreWarnings || [];
|
|
20
|
-
config.ignoreWarnings.push((warning) => {
|
|
21
|
-
if (warning.message.includes("external script")) {
|
|
22
|
-
return true;
|
|
23
|
-
}
|
|
24
|
-
return false;
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
18
|
}
|
|
28
19
|
const moduleFederationConfigPlugin = (userConfig) => ({
|
|
29
20
|
name: "@modern-js/plugin-module-federation-config",
|
|
@@ -39,9 +30,17 @@ const moduleFederationConfigPlugin = (userConfig) => ({
|
|
|
39
30
|
userConfig.csrConfig = csrConfig;
|
|
40
31
|
return {
|
|
41
32
|
config: async () => {
|
|
42
|
-
var _modernjsConfig_dev;
|
|
33
|
+
var _modernjsConfig_server, _modernjsConfig_dev;
|
|
43
34
|
const bundlerType = useAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
|
|
44
35
|
const ipv4 = getIPV4();
|
|
36
|
+
const enableSSR = Boolean(modernjsConfig === null || modernjsConfig === void 0 ? void 0 : (_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
|
|
37
|
+
if (userConfig.remoteIpStrategy === void 0) {
|
|
38
|
+
if (!enableSSR) {
|
|
39
|
+
userConfig.remoteIpStrategy = "inherit";
|
|
40
|
+
} else {
|
|
41
|
+
userConfig.remoteIpStrategy = "ipv4";
|
|
42
|
+
}
|
|
43
|
+
}
|
|
45
44
|
return {
|
|
46
45
|
tools: {
|
|
47
46
|
rspack(config, { isServer }) {
|
|
@@ -81,7 +80,8 @@ const moduleFederationConfigPlugin = (userConfig) => ({
|
|
|
81
80
|
"@modern-js/runtime/mf": require.resolve("@module-federation/modern-js/runtime")
|
|
82
81
|
},
|
|
83
82
|
define: {
|
|
84
|
-
FEDERATION_IPV4: JSON.stringify(ipv4)
|
|
83
|
+
FEDERATION_IPV4: JSON.stringify(ipv4),
|
|
84
|
+
REMOTE_IP_STRATEGY: JSON.stringify(userConfig.remoteIpStrategy)
|
|
85
85
|
}
|
|
86
86
|
},
|
|
87
87
|
dev: {
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { LOCALHOST } from "../../constant";
|
|
2
2
|
const ipv4 = typeof FEDERATION_IPV4 !== "undefined" ? FEDERATION_IPV4 : "127.0.0.1";
|
|
3
|
+
const remoteIpStrategy = typeof REMOTE_IP_STRATEGY !== "undefined" ? REMOTE_IP_STRATEGY : "inherit";
|
|
3
4
|
function replaceObjectLocalhost(key, obj) {
|
|
5
|
+
if (remoteIpStrategy !== "ipv4") {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
4
8
|
if (!(key in obj)) {
|
|
5
9
|
return;
|
|
6
10
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import { fs } from "@modern-js/utils";
|
|
3
3
|
import { ModuleFederationPlugin } from "@module-federation/enhanced";
|
|
4
|
-
import {
|
|
4
|
+
import { ModuleFederationPlugin as RspackModuleFederationPlugin } from "@module-federation/enhanced/rspack";
|
|
5
|
+
import { EntryChunkTrackerPlugin } from "@module-federation/node";
|
|
5
6
|
import { updateStatsAndManifest } from "./manifest";
|
|
6
|
-
import { PLUGIN_IDENTIFIER } from "../constant";
|
|
7
7
|
import { isDev } from "./constant";
|
|
8
8
|
function setEnv() {
|
|
9
9
|
process.env["MF_DISABLE_EMIT_STATS"] = "true";
|
|
@@ -15,7 +15,7 @@ const moduleFederationSSRPlugin = (userConfig) => ({
|
|
|
15
15
|
"@modern-js/plugin-module-federation-config",
|
|
16
16
|
"@modern-js/plugin-module-federation"
|
|
17
17
|
],
|
|
18
|
-
setup: async ({ useConfigContext }) => {
|
|
18
|
+
setup: async ({ useConfigContext, useAppContext }) => {
|
|
19
19
|
var _modernjsConfig_server;
|
|
20
20
|
const modernjsConfig = useConfigContext();
|
|
21
21
|
const enableSSR = Boolean(modernjsConfig === null || modernjsConfig === void 0 ? void 0 : (_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
|
|
@@ -42,25 +42,36 @@ const moduleFederationSSRPlugin = (userConfig) => ({
|
|
|
42
42
|
};
|
|
43
43
|
},
|
|
44
44
|
config: async () => {
|
|
45
|
+
var _modernjsConfig_source, _modernjsConfig_source1;
|
|
46
|
+
const bundlerType = useAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
|
|
47
|
+
var _modernjsConfig_source_enableAsyncEntry;
|
|
45
48
|
return {
|
|
49
|
+
source: {
|
|
50
|
+
enableAsyncEntry: bundlerType === "rspack" ? (_modernjsConfig_source_enableAsyncEntry = (_modernjsConfig_source = modernjsConfig.source) === null || _modernjsConfig_source === void 0 ? void 0 : _modernjsConfig_source.enableAsyncEntry) !== null && _modernjsConfig_source_enableAsyncEntry !== void 0 ? _modernjsConfig_source_enableAsyncEntry : true : (_modernjsConfig_source1 = modernjsConfig.source) === null || _modernjsConfig_source1 === void 0 ? void 0 : _modernjsConfig_source1.enableAsyncEntry
|
|
51
|
+
},
|
|
46
52
|
tools: {
|
|
47
53
|
rspack(config, { isServer }) {
|
|
48
54
|
if (isServer) {
|
|
49
|
-
|
|
55
|
+
if (!userConfig.nodePlugin) {
|
|
56
|
+
var _config_plugins;
|
|
57
|
+
userConfig.nodePlugin = new RspackModuleFederationPlugin(userConfig.ssrConfig);
|
|
58
|
+
(_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(userConfig.nodePlugin);
|
|
59
|
+
}
|
|
60
|
+
} else {
|
|
61
|
+
var _config_output;
|
|
62
|
+
userConfig.distOutputDir = userConfig.distOutputDir || ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.path) || path.resolve(process.cwd(), "dist");
|
|
50
63
|
}
|
|
51
64
|
},
|
|
52
65
|
webpack(config, { isServer }) {
|
|
53
66
|
if (isServer) {
|
|
54
|
-
var _config_plugins;
|
|
55
67
|
if (!userConfig.nodePlugin) {
|
|
56
|
-
var
|
|
68
|
+
var _config_plugins;
|
|
57
69
|
userConfig.nodePlugin = new ModuleFederationPlugin(userConfig.ssrConfig);
|
|
58
|
-
(
|
|
70
|
+
(_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(userConfig.nodePlugin);
|
|
59
71
|
}
|
|
60
|
-
(_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(new StreamingTargetPlugin(userConfig.nodePlugin));
|
|
61
72
|
if (isDev) {
|
|
62
|
-
var
|
|
63
|
-
(
|
|
73
|
+
var _config_plugins1;
|
|
74
|
+
(_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(new EntryChunkTrackerPlugin());
|
|
64
75
|
}
|
|
65
76
|
} else {
|
|
66
77
|
var _config_output;
|
|
@@ -96,6 +107,9 @@ const moduleFederationSSRPlugin = (userConfig) => ({
|
|
|
96
107
|
]
|
|
97
108
|
},
|
|
98
109
|
bundlerChain(chain, { isServer }) {
|
|
110
|
+
if (isServer) {
|
|
111
|
+
chain.target("async-node");
|
|
112
|
+
}
|
|
99
113
|
if (isDev && !isServer) {
|
|
100
114
|
chain.externals({
|
|
101
115
|
"@module-federation/node/utils": "NOT_USED_IN_BROWSER"
|
|
@@ -102,6 +102,7 @@ const patchMFConfig = (mfConfig, isServer, remoteIpStrategy) => {
|
|
|
102
102
|
injectRuntimePlugins(path.resolve(__dirname, "./mfRuntimePlugins/resolve-entry-ipv4.js"), runtimePlugins);
|
|
103
103
|
}
|
|
104
104
|
if (isServer) {
|
|
105
|
+
injectRuntimePlugins(require.resolve("@module-federation/node/runtimePlugin"), runtimePlugins);
|
|
105
106
|
if (isDev) {
|
|
106
107
|
injectRuntimePlugins(require.resolve("@module-federation/node/record-dynamic-remote-entry-hash-plugin"), runtimePlugins);
|
|
107
108
|
}
|
|
@@ -132,11 +133,43 @@ const patchMFConfig = (mfConfig, isServer, remoteIpStrategy) => {
|
|
|
132
133
|
mfConfig.dev = false;
|
|
133
134
|
return mfConfig;
|
|
134
135
|
};
|
|
136
|
+
function patchIgnoreWarning(bundlerConfig) {
|
|
137
|
+
bundlerConfig.ignoreWarnings = bundlerConfig.ignoreWarnings || [];
|
|
138
|
+
const ignoredMsgs = [
|
|
139
|
+
"external script",
|
|
140
|
+
"process.env.WS_NO_BUFFER_UTIL",
|
|
141
|
+
`Can't resolve 'utf-8-validate`
|
|
142
|
+
];
|
|
143
|
+
bundlerConfig.ignoreWarnings.push((warning) => {
|
|
144
|
+
if (ignoredMsgs.some((msg) => warning.message.includes(msg))) {
|
|
145
|
+
return true;
|
|
146
|
+
}
|
|
147
|
+
return false;
|
|
148
|
+
});
|
|
149
|
+
}
|
|
135
150
|
function patchBundlerConfig(options) {
|
|
136
151
|
var _modernjsConfig_server, _bundlerConfig_optimization, _bundlerConfig_optimization1, _bundlerConfig_output, _modernjsConfig_deploy;
|
|
137
152
|
const { bundlerConfig, modernjsConfig, isServer, mfConfig } = options;
|
|
138
153
|
const enableSSR = Boolean((_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
|
|
139
154
|
(_bundlerConfig_optimization = bundlerConfig.optimization) === null || _bundlerConfig_optimization === void 0 ? true : delete _bundlerConfig_optimization.runtimeChunk;
|
|
155
|
+
patchIgnoreWarning(bundlerConfig);
|
|
156
|
+
bundlerConfig.watchOptions = bundlerConfig.watchOptions || {};
|
|
157
|
+
if (!Array.isArray(bundlerConfig.watchOptions.ignored)) {
|
|
158
|
+
if (bundlerConfig.watchOptions.ignored) {
|
|
159
|
+
bundlerConfig.watchOptions.ignored = [
|
|
160
|
+
bundlerConfig.watchOptions.ignored
|
|
161
|
+
];
|
|
162
|
+
} else {
|
|
163
|
+
bundlerConfig.watchOptions.ignored = [];
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
if (mfConfig.dts !== false) {
|
|
167
|
+
if (typeof mfConfig.dts === "object" && typeof mfConfig.dts.consumeTypes === "object" && mfConfig.dts.consumeTypes.remoteTypesFolder) {
|
|
168
|
+
bundlerConfig.watchOptions.ignored.push(mfConfig.dts.consumeTypes.remoteTypesFolder);
|
|
169
|
+
} else {
|
|
170
|
+
bundlerConfig.watchOptions.ignored.push("@mf-types");
|
|
171
|
+
}
|
|
172
|
+
}
|
|
140
173
|
if (bundlerConfig.output) {
|
|
141
174
|
var _bundlerConfig_output1, _bundlerConfig_output2;
|
|
142
175
|
if (!((_bundlerConfig_output1 = bundlerConfig.output) === null || _bundlerConfig_output1 === void 0 ? void 0 : _bundlerConfig_output1.chunkLoadingGlobal)) {
|
|
@@ -253,5 +286,6 @@ export {
|
|
|
253
286
|
getIPV4,
|
|
254
287
|
getMFConfig,
|
|
255
288
|
patchBundlerConfig,
|
|
289
|
+
patchIgnoreWarning,
|
|
256
290
|
patchMFConfig
|
|
257
291
|
};
|
|
@@ -38,6 +38,7 @@ describe("patchMFConfig", async () => {
|
|
|
38
38
|
remoteType: "script",
|
|
39
39
|
runtimePlugins: [
|
|
40
40
|
path.resolve(__dirname, "./mfRuntimePlugins/shared-strategy.js"),
|
|
41
|
+
require.resolve("@module-federation/node/runtimePlugin"),
|
|
41
42
|
path.resolve(__dirname, "./mfRuntimePlugins/inject-node-fetch.js")
|
|
42
43
|
],
|
|
43
44
|
shared: {
|
|
@@ -105,13 +106,20 @@ describe("patchBundlerConfig", async () => {
|
|
|
105
106
|
},
|
|
106
107
|
mfConfig
|
|
107
108
|
});
|
|
108
|
-
|
|
109
|
+
const expectedConfig = {
|
|
109
110
|
output: {
|
|
110
111
|
chunkLoadingGlobal: "chunk_host",
|
|
111
112
|
publicPath: "auto",
|
|
112
113
|
uniqueName: "host"
|
|
114
|
+
},
|
|
115
|
+
watchOptions: {
|
|
116
|
+
ignored: [
|
|
117
|
+
"@mf-types"
|
|
118
|
+
]
|
|
113
119
|
}
|
|
114
|
-
}
|
|
120
|
+
};
|
|
121
|
+
bundlerConfig === null || bundlerConfig === void 0 ? true : delete bundlerConfig.ignoreWarnings;
|
|
122
|
+
expect(bundlerConfig).toStrictEqual(expectedConfig);
|
|
115
123
|
});
|
|
116
124
|
it("patchBundlerConfig: client", async () => {
|
|
117
125
|
const bundlerConfig = {
|
|
@@ -131,12 +139,19 @@ describe("patchBundlerConfig", async () => {
|
|
|
131
139
|
},
|
|
132
140
|
mfConfig
|
|
133
141
|
});
|
|
134
|
-
|
|
142
|
+
const expectedConfig = {
|
|
135
143
|
output: {
|
|
136
144
|
chunkLoadingGlobal: "chunk_host",
|
|
137
145
|
publicPath: "auto",
|
|
138
146
|
uniqueName: "host"
|
|
147
|
+
},
|
|
148
|
+
watchOptions: {
|
|
149
|
+
ignored: [
|
|
150
|
+
"@mf-types"
|
|
151
|
+
]
|
|
139
152
|
}
|
|
140
|
-
}
|
|
153
|
+
};
|
|
154
|
+
bundlerConfig === null || bundlerConfig === void 0 ? true : delete bundlerConfig.ignoreWarnings;
|
|
155
|
+
expect(bundlerConfig).toStrictEqual(expectedConfig);
|
|
141
156
|
});
|
|
142
157
|
});
|
|
@@ -5,6 +5,7 @@ import { BundlerConfig } from '../interfaces/bundler';
|
|
|
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;
|
|
8
9
|
export declare function patchBundlerConfig<T extends Bundler>(options: {
|
|
9
10
|
bundlerConfig: BundlerConfig<T>;
|
|
10
11
|
isServer: boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/modern-js",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"files": [
|
|
5
5
|
"dist/",
|
|
6
6
|
"types.d.ts",
|
|
@@ -61,18 +61,18 @@
|
|
|
61
61
|
"node-fetch": "~3.3.0",
|
|
62
62
|
"react-error-boundary": "4.0.13",
|
|
63
63
|
"hoist-non-react-statics": "3.3.2",
|
|
64
|
-
"@module-federation/sdk": "0.3.
|
|
65
|
-
"@module-federation/enhanced": "0.3.
|
|
66
|
-
"@module-federation/node": "2.5.
|
|
64
|
+
"@module-federation/sdk": "0.3.2",
|
|
65
|
+
"@module-federation/enhanced": "0.3.2",
|
|
66
|
+
"@module-federation/node": "2.5.2"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
69
|
"@types/hoist-non-react-statics": "3.3.2",
|
|
70
|
-
"@modern-js/app-tools": "2.56.
|
|
71
|
-
"@modern-js/core": "2.56.
|
|
72
|
-
"@modern-js/runtime": "2.56.
|
|
73
|
-
"@modern-js/module-tools": "2.56.
|
|
74
|
-
"@modern-js/tsconfig": "2.56.
|
|
75
|
-
"@module-federation/manifest": "0.3.
|
|
70
|
+
"@modern-js/app-tools": "2.56.2",
|
|
71
|
+
"@modern-js/core": "2.56.2",
|
|
72
|
+
"@modern-js/runtime": "2.56.2",
|
|
73
|
+
"@modern-js/module-tools": "2.56.2",
|
|
74
|
+
"@modern-js/tsconfig": "2.56.2",
|
|
75
|
+
"@module-federation/manifest": "0.3.2"
|
|
76
76
|
},
|
|
77
77
|
"peerDependencies": {
|
|
78
78
|
"react": ">=17",
|