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