@module-federation/modern-js 0.0.0-next-20240712032032 → 0.0.0-next-20240715061004
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 +137 -0
- package/dist/cjs/cli/constant.js +28 -0
- package/dist/cjs/cli/index.js +50 -189
- package/dist/cjs/cli/ssrPlugin.js +160 -0
- package/dist/cjs/cli/utils.js +35 -48
- package/dist/cjs/cli/utils.spec.js +20 -14
- package/dist/cjs/ssr-runtime/plugin.js +3 -3
- package/dist/esm/cli/configPlugin.js +132 -0
- package/dist/esm/cli/constant.js +4 -0
- package/dist/esm/cli/index.js +61 -199
- package/dist/esm/cli/ssrPlugin.js +152 -0
- package/dist/esm/cli/utils.js +57 -82
- package/dist/esm/cli/utils.spec.js +23 -17
- package/dist/esm/ssr-runtime/plugin.js +2 -2
- package/dist/esm-node/cli/configPlugin.js +101 -0
- package/dist/esm-node/cli/constant.js +4 -0
- package/dist/esm-node/cli/index.js +50 -179
- package/dist/esm-node/cli/ssrPlugin.js +125 -0
- package/dist/esm-node/cli/utils.js +33 -45
- package/dist/esm-node/cli/utils.spec.js +21 -15
- package/dist/esm-node/ssr-runtime/plugin.js +2 -2
- package/dist/types/cli/configPlugin.d.ts +14 -0
- package/dist/types/cli/constant.d.ts +1 -0
- package/dist/types/cli/ssrPlugin.d.ts +5 -0
- package/dist/types/cli/utils.d.ts +2 -37
- package/dist/types/ssr-runtime/plugin.d.ts +1 -1
- package/dist/types/types/index.d.ts +8 -2
- package/package.json +20 -7
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
+
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import { fs } from "@modern-js/utils";
|
|
5
|
+
import { ModuleFederationPlugin } from "@module-federation/enhanced";
|
|
6
|
+
import { StreamingTargetPlugin, EntryChunkTrackerPlugin } from "@module-federation/node";
|
|
7
|
+
import { updateStatsAndManifest } from "./manifest";
|
|
8
|
+
import { MODERN_JS_SERVER_DIR, PLUGIN_IDENTIFIER } from "../constant";
|
|
9
|
+
import { isDev } from "./constant";
|
|
10
|
+
function setEnv() {
|
|
11
|
+
process.env["MF_DISABLE_EMIT_STATS"] = "true";
|
|
12
|
+
process.env["MF_SSR_PRJ"] = "true";
|
|
13
|
+
}
|
|
14
|
+
var moduleFederationSSRPlugin = function(userConfig) {
|
|
15
|
+
return {
|
|
16
|
+
name: "@modern-js/plugin-module-federation-ssr",
|
|
17
|
+
pre: [
|
|
18
|
+
"@modern-js/plugin-module-federation-config",
|
|
19
|
+
"@modern-js/plugin-module-federation"
|
|
20
|
+
],
|
|
21
|
+
setup: function() {
|
|
22
|
+
var _ref = _async_to_generator(function(param) {
|
|
23
|
+
var useConfigContext, _modernjsConfig_server, modernjsConfig, enableSSR;
|
|
24
|
+
return _ts_generator(this, function(_state) {
|
|
25
|
+
useConfigContext = param.useConfigContext;
|
|
26
|
+
console.log("ssr plugin");
|
|
27
|
+
modernjsConfig = useConfigContext();
|
|
28
|
+
enableSSR = Boolean(modernjsConfig === null || modernjsConfig === void 0 ? void 0 : (_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
|
|
29
|
+
if (!enableSSR) {
|
|
30
|
+
return [
|
|
31
|
+
2,
|
|
32
|
+
{}
|
|
33
|
+
];
|
|
34
|
+
}
|
|
35
|
+
setEnv();
|
|
36
|
+
return [
|
|
37
|
+
2,
|
|
38
|
+
{
|
|
39
|
+
_internalRuntimePlugins: function(param2) {
|
|
40
|
+
var entrypoint = param2.entrypoint, plugins = param2.plugins;
|
|
41
|
+
if (!isDev) {
|
|
42
|
+
return {
|
|
43
|
+
entrypoint,
|
|
44
|
+
plugins
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
plugins.push({
|
|
48
|
+
name: "mfSSR",
|
|
49
|
+
path: "@module-federation/modern-js/ssr-runtime",
|
|
50
|
+
config: {}
|
|
51
|
+
});
|
|
52
|
+
return {
|
|
53
|
+
entrypoint,
|
|
54
|
+
plugins
|
|
55
|
+
};
|
|
56
|
+
},
|
|
57
|
+
config: /* @__PURE__ */ _async_to_generator(function() {
|
|
58
|
+
return _ts_generator(this, function(_state2) {
|
|
59
|
+
return [
|
|
60
|
+
2,
|
|
61
|
+
{
|
|
62
|
+
tools: {
|
|
63
|
+
rspack: function rspack(config, param2) {
|
|
64
|
+
var isServer = param2.isServer;
|
|
65
|
+
if (isServer) {
|
|
66
|
+
throw new Error("".concat(PLUGIN_IDENTIFIER, " Not support rspack ssr mode yet !"));
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
webpack: function webpack(config, param2) {
|
|
70
|
+
var isServer = param2.isServer;
|
|
71
|
+
if (isServer) {
|
|
72
|
+
var _config_plugins, _config_plugins1;
|
|
73
|
+
if (!userConfig.nodePlugin) {
|
|
74
|
+
userConfig.nodePlugin = new ModuleFederationPlugin(userConfig.ssrConfig);
|
|
75
|
+
}
|
|
76
|
+
(_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(userConfig.nodePlugin);
|
|
77
|
+
(_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(new StreamingTargetPlugin(userConfig.nodePlugin));
|
|
78
|
+
if (isDev) {
|
|
79
|
+
var _config_plugins2;
|
|
80
|
+
(_config_plugins2 = config.plugins) === null || _config_plugins2 === void 0 ? void 0 : _config_plugins2.push(new EntryChunkTrackerPlugin());
|
|
81
|
+
}
|
|
82
|
+
} else {
|
|
83
|
+
var _config_output;
|
|
84
|
+
userConfig.distOutputDir = userConfig.distOutputDir || ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.path) || path.resolve(process.cwd(), "dist");
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
devServer: {
|
|
88
|
+
before: [
|
|
89
|
+
function(req, res, next) {
|
|
90
|
+
if (!enableSSR) {
|
|
91
|
+
next();
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
try {
|
|
95
|
+
var _req_url, _req_url1, _req_url2;
|
|
96
|
+
var SERVER_PREFIX = "/".concat(MODERN_JS_SERVER_DIR);
|
|
97
|
+
if (((_req_url = req.url) === null || _req_url === void 0 ? void 0 : _req_url.startsWith(SERVER_PREFIX)) || ((_req_url1 = req.url) === null || _req_url1 === void 0 ? void 0 : _req_url1.includes(".json")) && !((_req_url2 = req.url) === null || _req_url2 === void 0 ? void 0 : _req_url2.includes("hot-update"))) {
|
|
98
|
+
var filepath = path.join(process.cwd(), "dist".concat(req.url));
|
|
99
|
+
fs.statSync(filepath);
|
|
100
|
+
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
101
|
+
res.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, PATCH, OPTIONS");
|
|
102
|
+
res.setHeader("Access-Control-Allow-Headers", "X-Requested-With, content-type, Authorization");
|
|
103
|
+
fs.createReadStream(filepath).pipe(res);
|
|
104
|
+
} else {
|
|
105
|
+
next();
|
|
106
|
+
}
|
|
107
|
+
} catch (err) {
|
|
108
|
+
if (process.env.FEDERATION_DEBUG) {
|
|
109
|
+
console.error(err);
|
|
110
|
+
}
|
|
111
|
+
next();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
]
|
|
115
|
+
},
|
|
116
|
+
bundlerChain: function bundlerChain(chain, param2) {
|
|
117
|
+
var isServer = param2.isServer;
|
|
118
|
+
if (isDev && !isServer) {
|
|
119
|
+
chain.externals({
|
|
120
|
+
"@module-federation/node/utils": "NOT_USED_IN_BROWSER"
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
];
|
|
127
|
+
});
|
|
128
|
+
}),
|
|
129
|
+
afterBuild: function() {
|
|
130
|
+
var nodePlugin = userConfig.nodePlugin, browserPlugin = userConfig.browserPlugin, distOutputDir = userConfig.distOutputDir;
|
|
131
|
+
updateStatsAndManifest(nodePlugin, browserPlugin, distOutputDir);
|
|
132
|
+
},
|
|
133
|
+
afterDev: function() {
|
|
134
|
+
var nodePlugin = userConfig.nodePlugin, browserPlugin = userConfig.browserPlugin, distOutputDir = userConfig.distOutputDir;
|
|
135
|
+
updateStatsAndManifest(nodePlugin, browserPlugin, distOutputDir);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
];
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
return function(_) {
|
|
142
|
+
return _ref.apply(this, arguments);
|
|
143
|
+
};
|
|
144
|
+
}()
|
|
145
|
+
};
|
|
146
|
+
};
|
|
147
|
+
var ssrPlugin_default = moduleFederationSSRPlugin;
|
|
148
|
+
export {
|
|
149
|
+
ssrPlugin_default as default,
|
|
150
|
+
moduleFederationSSRPlugin,
|
|
151
|
+
setEnv
|
|
152
|
+
};
|
package/dist/esm/cli/utils.js
CHANGED
|
@@ -36,18 +36,6 @@ var getMFConfig = function() {
|
|
|
36
36
|
];
|
|
37
37
|
case 2:
|
|
38
38
|
mfConfig = _state.sent().default;
|
|
39
|
-
return [
|
|
40
|
-
4,
|
|
41
|
-
replaceRemoteUrl(mfConfig)
|
|
42
|
-
];
|
|
43
|
-
case 3:
|
|
44
|
-
_state.sent();
|
|
45
|
-
if (mfConfig.remoteType === void 0) {
|
|
46
|
-
mfConfig.remoteType = "script";
|
|
47
|
-
}
|
|
48
|
-
if (!mfConfig.name) {
|
|
49
|
-
throw new Error("".concat(PLUGIN_IDENTIFIER, " mfConfig.name can not be empty!"));
|
|
50
|
-
}
|
|
51
39
|
return [
|
|
52
40
|
2,
|
|
53
41
|
mfConfig
|
|
@@ -64,49 +52,36 @@ var injectRuntimePlugins = function(runtimePlugin, runtimePlugins) {
|
|
|
64
52
|
runtimePlugins.push(runtimePlugin);
|
|
65
53
|
}
|
|
66
54
|
};
|
|
67
|
-
var replaceRemoteUrl = function() {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
55
|
+
var replaceRemoteUrl = function(mfConfig) {
|
|
56
|
+
if (!mfConfig.remotes) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
var ipv4 = getIPV4();
|
|
60
|
+
var handleRemoteObject = function(remoteObject) {
|
|
61
|
+
Object.keys(remoteObject).forEach(function(remoteKey) {
|
|
62
|
+
var remote = remoteObject[remoteKey];
|
|
63
|
+
if (Array.isArray(remote)) {
|
|
64
|
+
return;
|
|
75
65
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
if (typeof remote === "string" && remote.includes(LOCALHOST)) {
|
|
84
|
-
remoteObject[remoteKey] = remote.replace(LOCALHOST, ipv4);
|
|
85
|
-
}
|
|
86
|
-
if (typeof remote === "object" && !Array.isArray(remote.external) && remote.external.includes(LOCALHOST)) {
|
|
87
|
-
remote.external = remote.external.replace(LOCALHOST, ipv4);
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
};
|
|
91
|
-
if (Array.isArray(mfConfig.remotes)) {
|
|
92
|
-
mfConfig.remotes.forEach(function(remoteObject) {
|
|
93
|
-
if (typeof remoteObject === "string") {
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
handleRemoteObject(remoteObject);
|
|
97
|
-
});
|
|
98
|
-
} else if (typeof mfConfig.remotes !== "string") {
|
|
99
|
-
handleRemoteObject(mfConfig.remotes);
|
|
66
|
+
if (typeof remote === "string" && remote.includes(LOCALHOST)) {
|
|
67
|
+
remoteObject[remoteKey] = remote.replace(LOCALHOST, ipv4);
|
|
68
|
+
}
|
|
69
|
+
if (typeof remote === "object" && !Array.isArray(remote.external) && remote.external.includes(LOCALHOST)) {
|
|
70
|
+
remote.external = remote.external.replace(LOCALHOST, ipv4);
|
|
100
71
|
}
|
|
101
|
-
return [
|
|
102
|
-
2
|
|
103
|
-
];
|
|
104
72
|
});
|
|
105
|
-
});
|
|
106
|
-
return function replaceRemoteUrl2(mfConfig) {
|
|
107
|
-
return _ref.apply(this, arguments);
|
|
108
73
|
};
|
|
109
|
-
|
|
74
|
+
if (Array.isArray(mfConfig.remotes)) {
|
|
75
|
+
mfConfig.remotes.forEach(function(remoteObject) {
|
|
76
|
+
if (typeof remoteObject === "string") {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
handleRemoteObject(remoteObject);
|
|
80
|
+
});
|
|
81
|
+
} else if (typeof mfConfig.remotes !== "string") {
|
|
82
|
+
handleRemoteObject(mfConfig.remotes);
|
|
83
|
+
}
|
|
84
|
+
};
|
|
110
85
|
var patchDTSConfig = function(mfConfig, isServer) {
|
|
111
86
|
if (isServer) {
|
|
112
87
|
return;
|
|
@@ -140,6 +115,13 @@ var patchDTSConfig = function(mfConfig, isServer) {
|
|
|
140
115
|
}
|
|
141
116
|
};
|
|
142
117
|
var patchMFConfig = function(mfConfig, isServer) {
|
|
118
|
+
replaceRemoteUrl(mfConfig);
|
|
119
|
+
if (mfConfig.remoteType === void 0) {
|
|
120
|
+
mfConfig.remoteType = "script";
|
|
121
|
+
}
|
|
122
|
+
if (!mfConfig.name) {
|
|
123
|
+
throw new Error("".concat(PLUGIN_IDENTIFIER, " mfConfig.name can not be empty!"));
|
|
124
|
+
}
|
|
143
125
|
var runtimePlugins = _to_consumable_array(mfConfig.runtimePlugins || []);
|
|
144
126
|
patchDTSConfig(mfConfig, isServer);
|
|
145
127
|
injectRuntimePlugins(path.resolve(__dirname, "./mfRuntimePlugins/shared-strategy.js"), runtimePlugins);
|
|
@@ -151,39 +133,33 @@ var patchMFConfig = function(mfConfig, isServer) {
|
|
|
151
133
|
injectRuntimePlugins(require.resolve("@module-federation/node/record-dynamic-remote-entry-hash-plugin"), runtimePlugins);
|
|
152
134
|
}
|
|
153
135
|
injectRuntimePlugins(path.resolve(__dirname, "./mfRuntimePlugins/inject-node-fetch.js"), runtimePlugins);
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
return _object_spread_props(_object_spread({}, mfConfig), {
|
|
157
|
-
runtimePlugins
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
return _object_spread_props(_object_spread({}, mfConfig), {
|
|
161
|
-
runtimePlugins,
|
|
162
|
-
dts: false,
|
|
163
|
-
dev: false
|
|
164
|
-
});
|
|
165
|
-
};
|
|
166
|
-
function getTargetEnvConfig(mfConfig, isServer) {
|
|
167
|
-
var _patchedMFConfig_library;
|
|
168
|
-
var patchedMFConfig = patchMFConfig(mfConfig, isServer);
|
|
169
|
-
if (isServer) {
|
|
170
|
-
return _object_spread({
|
|
171
|
-
library: {
|
|
136
|
+
if (!mfConfig.library) {
|
|
137
|
+
mfConfig.library = {
|
|
172
138
|
type: "commonjs-module",
|
|
173
139
|
name: mfConfig.name
|
|
140
|
+
};
|
|
141
|
+
} else {
|
|
142
|
+
if (!mfConfig.library.type) {
|
|
143
|
+
mfConfig.library.type = "commonjs-module";
|
|
144
|
+
}
|
|
145
|
+
if (!mfConfig.library.name) {
|
|
146
|
+
mfConfig.library.name = mfConfig.name;
|
|
174
147
|
}
|
|
175
|
-
}
|
|
148
|
+
}
|
|
176
149
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
}
|
|
150
|
+
mfConfig.runtimePlugins = runtimePlugins;
|
|
151
|
+
if (!isServer) {
|
|
152
|
+
var _mfConfig_library;
|
|
153
|
+
if (((_mfConfig_library = mfConfig.library) === null || _mfConfig_library === void 0 ? void 0 : _mfConfig_library.type) === "commonjs-module") {
|
|
154
|
+
mfConfig.library.type = "global";
|
|
155
|
+
}
|
|
156
|
+
return mfConfig;
|
|
183
157
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
158
|
+
mfConfig.dts = false;
|
|
159
|
+
mfConfig.dev = false;
|
|
160
|
+
return mfConfig;
|
|
161
|
+
};
|
|
162
|
+
function patchBundlerConfig(options) {
|
|
187
163
|
var _modernjsConfig_server, _bundlerConfig_optimization, _bundlerConfig_optimization1, _bundlerConfig_output, _modernjsConfig_deploy;
|
|
188
164
|
var bundlerConfig = options.bundlerConfig, modernjsConfig = options.modernjsConfig, isServer = options.isServer, mfConfig = options.mfConfig;
|
|
189
165
|
var enableSSR = Boolean((_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
|
|
@@ -319,7 +295,6 @@ function autoDeleteSplitChunkCacheGroups(mfConfig, bundlerConfig) {
|
|
|
319
295
|
export {
|
|
320
296
|
getIPV4,
|
|
321
297
|
getMFConfig,
|
|
322
|
-
|
|
323
|
-
patchMFConfig
|
|
324
|
-
patchWebpackConfig
|
|
298
|
+
patchBundlerConfig,
|
|
299
|
+
patchMFConfig
|
|
325
300
|
};
|
|
@@ -2,7 +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 { it, expect, describe } from "vitest";
|
|
4
4
|
import path from "path";
|
|
5
|
-
import {
|
|
5
|
+
import { patchMFConfig, patchBundlerConfig, getIPV4 } from "./utils";
|
|
6
6
|
var mfConfig = {
|
|
7
7
|
name: "host",
|
|
8
8
|
filename: "remoteEntry.js",
|
|
@@ -20,13 +20,15 @@ var mfConfig = {
|
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
};
|
|
23
|
-
describe("
|
|
23
|
+
describe("patchMFConfig", /* @__PURE__ */ _async_to_generator(function() {
|
|
24
24
|
return _ts_generator(this, function(_state) {
|
|
25
|
-
it("
|
|
26
|
-
var
|
|
25
|
+
it("patchMFConfig: server", /* @__PURE__ */ _async_to_generator(function() {
|
|
26
|
+
var patchedConfig, ipv4;
|
|
27
27
|
return _ts_generator(this, function(_state2) {
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
patchedConfig = JSON.parse(JSON.stringify(mfConfig));
|
|
29
|
+
patchMFConfig(patchedConfig, true);
|
|
30
|
+
ipv4 = getIPV4();
|
|
31
|
+
expect(patchedConfig).toStrictEqual({
|
|
30
32
|
dev: false,
|
|
31
33
|
dts: false,
|
|
32
34
|
filename: "remoteEntry.js",
|
|
@@ -36,8 +38,9 @@ describe("getTargetEnvConfig", /* @__PURE__ */ _async_to_generator(function() {
|
|
|
36
38
|
},
|
|
37
39
|
name: "host",
|
|
38
40
|
remotes: {
|
|
39
|
-
remote: "http://
|
|
41
|
+
remote: "http://".concat(ipv4, ":3000/remoteEntry.js")
|
|
40
42
|
},
|
|
43
|
+
remoteType: "script",
|
|
41
44
|
runtimePlugins: [
|
|
42
45
|
path.resolve(__dirname, "./mfRuntimePlugins/shared-strategy.js"),
|
|
43
46
|
path.resolve(__dirname, "./mfRuntimePlugins/inject-node-fetch.js")
|
|
@@ -58,16 +61,19 @@ describe("getTargetEnvConfig", /* @__PURE__ */ _async_to_generator(function() {
|
|
|
58
61
|
];
|
|
59
62
|
});
|
|
60
63
|
}));
|
|
61
|
-
it("
|
|
62
|
-
var
|
|
64
|
+
it("patchMFConfig: client", /* @__PURE__ */ _async_to_generator(function() {
|
|
65
|
+
var patchedConfig, ipv4;
|
|
63
66
|
return _ts_generator(this, function(_state2) {
|
|
64
|
-
|
|
65
|
-
|
|
67
|
+
patchedConfig = JSON.parse(JSON.stringify(mfConfig));
|
|
68
|
+
patchMFConfig(patchedConfig, false);
|
|
69
|
+
ipv4 = getIPV4();
|
|
70
|
+
expect(patchedConfig).toStrictEqual({
|
|
66
71
|
filename: "remoteEntry.js",
|
|
67
72
|
name: "host",
|
|
68
73
|
remotes: {
|
|
69
|
-
remote: "http://
|
|
74
|
+
remote: "http://".concat(ipv4, ":3000/remoteEntry.js")
|
|
70
75
|
},
|
|
76
|
+
remoteType: "script",
|
|
71
77
|
runtimePlugins: [
|
|
72
78
|
path.resolve(__dirname, "./mfRuntimePlugins/shared-strategy.js")
|
|
73
79
|
],
|
|
@@ -99,9 +105,9 @@ describe("getTargetEnvConfig", /* @__PURE__ */ _async_to_generator(function() {
|
|
|
99
105
|
];
|
|
100
106
|
});
|
|
101
107
|
}));
|
|
102
|
-
describe("
|
|
108
|
+
describe("patchBundlerConfig", /* @__PURE__ */ _async_to_generator(function() {
|
|
103
109
|
return _ts_generator(this, function(_state) {
|
|
104
|
-
it("
|
|
110
|
+
it("patchBundlerConfig: server", /* @__PURE__ */ _async_to_generator(function() {
|
|
105
111
|
var bundlerConfig;
|
|
106
112
|
return _ts_generator(this, function(_state2) {
|
|
107
113
|
bundlerConfig = {
|
|
@@ -109,7 +115,7 @@ describe("patchWebpackConfig", /* @__PURE__ */ _async_to_generator(function() {
|
|
|
109
115
|
publicPath: "auto"
|
|
110
116
|
}
|
|
111
117
|
};
|
|
112
|
-
|
|
118
|
+
patchBundlerConfig({
|
|
113
119
|
bundlerConfig,
|
|
114
120
|
isServer: true,
|
|
115
121
|
modernjsConfig: {
|
|
@@ -133,7 +139,7 @@ describe("patchWebpackConfig", /* @__PURE__ */ _async_to_generator(function() {
|
|
|
133
139
|
];
|
|
134
140
|
});
|
|
135
141
|
}));
|
|
136
|
-
it("
|
|
142
|
+
it("patchBundlerConfig: client", /* @__PURE__ */ _async_to_generator(function() {
|
|
137
143
|
var bundlerConfig;
|
|
138
144
|
return _ts_generator(this, function(_state2) {
|
|
139
145
|
bundlerConfig = {
|
|
@@ -141,7 +147,7 @@ describe("patchWebpackConfig", /* @__PURE__ */ _async_to_generator(function() {
|
|
|
141
147
|
publicPath: "auto"
|
|
142
148
|
}
|
|
143
149
|
};
|
|
144
|
-
|
|
150
|
+
patchBundlerConfig({
|
|
145
151
|
bundlerConfig,
|
|
146
152
|
isServer: false,
|
|
147
153
|
modernjsConfig: {
|
|
@@ -4,7 +4,7 @@ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
|
4
4
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
5
5
|
import hoistNonReactStatics from "hoist-non-react-statics";
|
|
6
6
|
import { SSRLiveReload } from "./SSRLiveReload";
|
|
7
|
-
var
|
|
7
|
+
var mfSSRPlugin = function() {
|
|
8
8
|
return {
|
|
9
9
|
name: "@module-federation/modern-js",
|
|
10
10
|
setup: function() {
|
|
@@ -82,5 +82,5 @@ var mfPluginSSR = function() {
|
|
|
82
82
|
};
|
|
83
83
|
};
|
|
84
84
|
export {
|
|
85
|
-
|
|
85
|
+
mfSSRPlugin
|
|
86
86
|
};
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { patchBundlerConfig, getIPV4, getMFConfig, patchMFConfig } from "./utils";
|
|
3
|
+
function setEnv(enableSSR) {
|
|
4
|
+
if (enableSSR) {
|
|
5
|
+
process.env["MF_DISABLE_EMIT_STATS"] = "true";
|
|
6
|
+
process.env["MF_SSR_PRJ"] = "true";
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
function modifyBundlerConfig(options) {
|
|
10
|
+
const { mfConfig, config, isServer, modernjsConfig, bundlerType } = options;
|
|
11
|
+
patchMFConfig(mfConfig, isServer);
|
|
12
|
+
patchBundlerConfig({
|
|
13
|
+
bundlerConfig: config,
|
|
14
|
+
isServer,
|
|
15
|
+
modernjsConfig,
|
|
16
|
+
mfConfig
|
|
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
|
+
}
|
|
28
|
+
const moduleFederationConfigPlugin = (userConfig) => ({
|
|
29
|
+
name: "@modern-js/plugin-module-federation-config",
|
|
30
|
+
post: [
|
|
31
|
+
"@modern-js/plugin-module-federation"
|
|
32
|
+
],
|
|
33
|
+
setup: async ({ useConfigContext, useAppContext }) => {
|
|
34
|
+
console.log("config plugin");
|
|
35
|
+
const modernjsConfig = useConfigContext();
|
|
36
|
+
const mfConfig = await getMFConfig(userConfig.originPluginOptions);
|
|
37
|
+
const csrConfig = JSON.parse(JSON.stringify(mfConfig));
|
|
38
|
+
const ssrConfig = JSON.parse(JSON.stringify(mfConfig));
|
|
39
|
+
userConfig.ssrConfig = ssrConfig;
|
|
40
|
+
userConfig.csrConfig = csrConfig;
|
|
41
|
+
return {
|
|
42
|
+
config: async () => {
|
|
43
|
+
var _modernjsConfig_dev;
|
|
44
|
+
const bundlerType = useAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
|
|
45
|
+
const ipv4 = getIPV4();
|
|
46
|
+
return {
|
|
47
|
+
tools: {
|
|
48
|
+
rspack(config, { isServer }) {
|
|
49
|
+
var _config_output;
|
|
50
|
+
modifyBundlerConfig({
|
|
51
|
+
bundlerType,
|
|
52
|
+
mfConfig: isServer ? ssrConfig : csrConfig,
|
|
53
|
+
config,
|
|
54
|
+
isServer,
|
|
55
|
+
// MFBundlerPlugin,
|
|
56
|
+
modernjsConfig
|
|
57
|
+
});
|
|
58
|
+
userConfig.distOutputDir = ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.path) || path.resolve(process.cwd(), "dist");
|
|
59
|
+
},
|
|
60
|
+
webpack(config, { isServer }) {
|
|
61
|
+
var _config_output;
|
|
62
|
+
modifyBundlerConfig({
|
|
63
|
+
bundlerType,
|
|
64
|
+
mfConfig: isServer ? ssrConfig : csrConfig,
|
|
65
|
+
config,
|
|
66
|
+
isServer,
|
|
67
|
+
modernjsConfig
|
|
68
|
+
});
|
|
69
|
+
userConfig.distOutputDir = ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.path) || path.resolve(process.cwd(), "dist");
|
|
70
|
+
},
|
|
71
|
+
devServer: {
|
|
72
|
+
headers: {
|
|
73
|
+
"Access-Control-Allow-Origin": "*",
|
|
74
|
+
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, PATCH, OPTIONS",
|
|
75
|
+
"Access-Control-Allow-Headers": "X-Requested-With, content-type, Authorization"
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
source: {
|
|
80
|
+
alias: {
|
|
81
|
+
"@modern-js/runtime/mf": require.resolve("@module-federation/modern-js/runtime")
|
|
82
|
+
},
|
|
83
|
+
define: {
|
|
84
|
+
FEDERATION_IPV4: JSON.stringify(ipv4)
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
dev: {
|
|
88
|
+
assetPrefix: (modernjsConfig === null || modernjsConfig === void 0 ? void 0 : (_modernjsConfig_dev = modernjsConfig.dev) === null || _modernjsConfig_dev === void 0 ? void 0 : _modernjsConfig_dev.assetPrefix) ? modernjsConfig.dev.assetPrefix : true
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
var configPlugin_default = moduleFederationConfigPlugin;
|
|
96
|
+
export {
|
|
97
|
+
configPlugin_default as default,
|
|
98
|
+
modifyBundlerConfig,
|
|
99
|
+
moduleFederationConfigPlugin,
|
|
100
|
+
setEnv
|
|
101
|
+
};
|