@umijs/plugins 4.0.14 → 4.0.17
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/qiankun/slave.js +102 -26
- package/package.json +3 -3
package/dist/qiankun/slave.js
CHANGED
|
@@ -1,26 +1,9 @@
|
|
|
1
1
|
var __create = Object.create;
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
|
-
var __defProps = Object.defineProperties;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
5
|
var __getProtoOf = Object.getPrototypeOf;
|
|
9
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
11
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
-
var __spreadValues = (a, b) => {
|
|
13
|
-
for (var prop in b || (b = {}))
|
|
14
|
-
if (__hasOwnProp.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
if (__getOwnPropSymbols)
|
|
17
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
18
|
-
if (__propIsEnum.call(b, prop))
|
|
19
|
-
__defNormalProp(a, prop, b[prop]);
|
|
20
|
-
}
|
|
21
|
-
return a;
|
|
22
|
-
};
|
|
23
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
7
|
var __export = (target, all) => {
|
|
25
8
|
for (var name in all)
|
|
26
9
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -42,6 +25,8 @@ __export(slave_exports, {
|
|
|
42
25
|
default: () => slave_default
|
|
43
26
|
});
|
|
44
27
|
module.exports = __toCommonJS(slave_exports);
|
|
28
|
+
var import_http_proxy_middleware = require("@umijs/bundler-webpack/compiled/http-proxy-middleware");
|
|
29
|
+
var import_utils = require("@umijs/utils");
|
|
45
30
|
var import_assert = __toESM(require("assert"));
|
|
46
31
|
var import_fs = require("fs");
|
|
47
32
|
var import_path = require("path");
|
|
@@ -49,6 +34,42 @@ var import_umi = require("umi");
|
|
|
49
34
|
var import_plugin_utils = require("umi/plugin-utils");
|
|
50
35
|
var import_withTmpPath = require("../utils/withTmpPath");
|
|
51
36
|
var import_constants = require("./constants");
|
|
37
|
+
function getCurrentLocalDevServerEntry(api, req) {
|
|
38
|
+
const port = api.appData.port;
|
|
39
|
+
const hostname = req.hostname;
|
|
40
|
+
const protocol = req.protocol;
|
|
41
|
+
return `${protocol}://${hostname}${port ? ":" : ""}${port}/local-dev-server`;
|
|
42
|
+
}
|
|
43
|
+
function handleOriginalHtml(api, microAppEntry, originalHtml) {
|
|
44
|
+
const appName = api.pkg.name;
|
|
45
|
+
(0, import_assert.default)(appName, "[@umijs/plugin-qiankun]: You should have name in package.json");
|
|
46
|
+
const $ = import_utils.cheerio.load(originalHtml);
|
|
47
|
+
$("head").prepend(`<script type="extra-qiankun-config">${JSON.stringify({
|
|
48
|
+
master: {
|
|
49
|
+
apps: [
|
|
50
|
+
{
|
|
51
|
+
name: appName,
|
|
52
|
+
entry: microAppEntry,
|
|
53
|
+
extraSource: microAppEntry
|
|
54
|
+
}
|
|
55
|
+
],
|
|
56
|
+
routes: [
|
|
57
|
+
{
|
|
58
|
+
microApp: appName,
|
|
59
|
+
name: appName,
|
|
60
|
+
path: "/" + appName,
|
|
61
|
+
extraSource: microAppEntry
|
|
62
|
+
}
|
|
63
|
+
],
|
|
64
|
+
prefetch: false
|
|
65
|
+
}
|
|
66
|
+
})}<\/script>`);
|
|
67
|
+
return api.applyPlugins({
|
|
68
|
+
key: "modifyMasterHTML",
|
|
69
|
+
type: api.ApplyPluginsType.modify,
|
|
70
|
+
initialValue: $.html()
|
|
71
|
+
});
|
|
72
|
+
}
|
|
52
73
|
function isSlaveEnable(opts) {
|
|
53
74
|
var _a, _b;
|
|
54
75
|
const slaveCfg = (_b = (_a = opts.userConfig) == null ? void 0 : _a.qiankun) == null ? void 0 : _b.slave;
|
|
@@ -102,15 +123,19 @@ export interface IRuntimeConfig {
|
|
|
102
123
|
});
|
|
103
124
|
api.modifyDefaultConfig((memo) => {
|
|
104
125
|
var _a, _b, _c;
|
|
105
|
-
const initialSlaveOptions =
|
|
106
|
-
devSourceMap: true
|
|
107
|
-
|
|
108
|
-
|
|
126
|
+
const initialSlaveOptions = {
|
|
127
|
+
devSourceMap: true,
|
|
128
|
+
...JSON.parse(process.env.INITIAL_QIANKUN_SLAVE_OPTIONS || "{}"),
|
|
129
|
+
...(memo.qiankun || {}).slave
|
|
130
|
+
};
|
|
131
|
+
const modifiedDefaultConfig = {
|
|
132
|
+
...memo,
|
|
109
133
|
runtimePublicPath: true,
|
|
110
|
-
qiankun:
|
|
134
|
+
qiankun: {
|
|
135
|
+
...memo.qiankun,
|
|
111
136
|
slave: initialSlaveOptions
|
|
112
|
-
}
|
|
113
|
-
}
|
|
137
|
+
}
|
|
138
|
+
};
|
|
114
139
|
const shouldNotModifyDefaultBase = ((_b = (_a = api.userConfig.qiankun) == null ? void 0 : _a.slave) == null ? void 0 : _b.shouldNotModifyDefaultBase) ?? initialSlaveOptions.shouldNotModifyDefaultBase;
|
|
115
140
|
const historyType = ((_c = api.userConfig.history) == null ? void 0 : _c.type) || "browser";
|
|
116
141
|
if (!shouldNotModifyDefaultBase && historyType !== "hash") {
|
|
@@ -121,9 +146,10 @@ export interface IRuntimeConfig {
|
|
|
121
146
|
api.modifyConfig((config) => {
|
|
122
147
|
var _a, _b;
|
|
123
148
|
if (config.mfsu !== false) {
|
|
124
|
-
config.mfsu =
|
|
149
|
+
config.mfsu = {
|
|
150
|
+
...config.mfsu,
|
|
125
151
|
mfName: ((_a = config.mfsu) == null ? void 0 : _a.mfName) || `mf_${(_b = api.pkg.name) == null ? void 0 : _b.replace(/^@/, "").replace(/\W/g, "_")}`
|
|
126
|
-
}
|
|
152
|
+
};
|
|
127
153
|
}
|
|
128
154
|
return config;
|
|
129
155
|
});
|
|
@@ -194,6 +220,56 @@ export { connectMaster } from './connectMaster';
|
|
|
194
220
|
},
|
|
195
221
|
before: "model"
|
|
196
222
|
});
|
|
223
|
+
api.addMiddlewares(async () => {
|
|
224
|
+
return async (req, res, next) => {
|
|
225
|
+
var _a, _b;
|
|
226
|
+
const qiankunConfig = api.config.qiankun || {};
|
|
227
|
+
const masterEntry = (_a = qiankunConfig.slave) == null ? void 0 : _a.masterEntry;
|
|
228
|
+
const isMasterApp = (_b = qiankunConfig.master) == null ? void 0 : _b.enable;
|
|
229
|
+
const { proxyToMasterEnabled } = await api.applyPlugins({
|
|
230
|
+
key: "shouldProxyToMaster",
|
|
231
|
+
type: api.ApplyPluginsType.modify,
|
|
232
|
+
initialValue: { proxyToMasterEnabled: true, req }
|
|
233
|
+
}) ?? {};
|
|
234
|
+
if (masterEntry && proxyToMasterEnabled) {
|
|
235
|
+
if (isMasterApp) {
|
|
236
|
+
api.logger.warn("You should not set masterEntry in master app ");
|
|
237
|
+
return next();
|
|
238
|
+
}
|
|
239
|
+
return (0, import_http_proxy_middleware.createProxyMiddleware)((pathname) => pathname !== "/local-dev-server", {
|
|
240
|
+
target: masterEntry,
|
|
241
|
+
secure: false,
|
|
242
|
+
ignorePath: false,
|
|
243
|
+
followRedirects: false,
|
|
244
|
+
changeOrigin: true,
|
|
245
|
+
selfHandleResponse: true,
|
|
246
|
+
onProxyRes: (0, import_http_proxy_middleware.responseInterceptor)(async (responseBuffer, proxyRes, req2, res2) => {
|
|
247
|
+
if (proxyRes.statusCode === 302) {
|
|
248
|
+
const hostname = req2.hostname;
|
|
249
|
+
const port = process.env.PORT;
|
|
250
|
+
const goto = `${hostname}:${port}`;
|
|
251
|
+
const redirectUrl = proxyRes.headers.location.replace(encodeURIComponent(new URL(masterEntry).hostname), encodeURIComponent(goto)) || masterEntry;
|
|
252
|
+
const redirectMessage = `[@umijs/plugin-qiankun]: redirect to ${redirectUrl}`;
|
|
253
|
+
api.logger.info(redirectMessage);
|
|
254
|
+
res2.statusCode = 302;
|
|
255
|
+
res2.setHeader("location", redirectUrl);
|
|
256
|
+
return redirectMessage;
|
|
257
|
+
}
|
|
258
|
+
const microAppEntry = getCurrentLocalDevServerEntry(api, req2);
|
|
259
|
+
const originalHtml = responseBuffer.toString("utf8");
|
|
260
|
+
const html = handleOriginalHtml(api, microAppEntry, originalHtml);
|
|
261
|
+
return html;
|
|
262
|
+
}),
|
|
263
|
+
onError(err, _, res2) {
|
|
264
|
+
api.logger.error(err);
|
|
265
|
+
res2.set("content-type", "text/plain; charset=UTF-8");
|
|
266
|
+
res2.end(`[@umijs/plugin-qiankun] \u4EE3\u7406\u5230 ${masterEntry} \u65F6\u51FA\u9519\u4E86\uFF0C\u8BF7\u5C1D\u8BD5 ${masterEntry} \u662F\u5426\u662F\u53EF\u4EE5\u6B63\u5E38\u8BBF\u95EE\u7684\uFF0C\u7136\u540E\u91CD\u65B0\u542F\u52A8\u9879\u76EE\u8BD5\u8BD5\u3002(\u6CE8\u610F\u5982\u679C\u51FA\u73B0\u8DE8\u57DF\u95EE\u9898\uFF0C\u8BF7\u4FEE\u6539\u672C\u5730 host \uFF0C\u901A\u8FC7\u4E00\u4E2A\u548C\u4E3B\u5E94\u7528\u76F8\u540C\u7684\u4E00\u7EA7\u57DF\u540D\u7684\u57DF\u540D\u6765\u8BBF\u95EE 127.0.0.1)`);
|
|
267
|
+
}
|
|
268
|
+
})(req, res, next);
|
|
269
|
+
}
|
|
270
|
+
return next();
|
|
271
|
+
};
|
|
272
|
+
});
|
|
197
273
|
};
|
|
198
274
|
// Annotate the CommonJS export names for ESM import in node:
|
|
199
275
|
0 && (module.exports = {});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umijs/plugins",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.17",
|
|
4
4
|
"description": "@umijs/plugins",
|
|
5
5
|
"homepage": "https://github.com/umijs/umi/tree/master/packages/plugins#readme",
|
|
6
6
|
"bugs": "https://github.com/umijs/umi/issues",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"@ant-design/antd-theme-variable": "^1.0.0",
|
|
28
28
|
"@ant-design/icons": "^4.7.0",
|
|
29
29
|
"@ant-design/pro-layout": "^7.0.1-beta.28",
|
|
30
|
-
"@umijs/bundler-utils": "4.0.
|
|
30
|
+
"@umijs/bundler-utils": "4.0.17",
|
|
31
31
|
"antd-dayjs-webpack-plugin": "^1.0.6",
|
|
32
32
|
"axios": "^0.27.2",
|
|
33
33
|
"babel-plugin-import": "^1.13.5",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"warning": "^4.0.3"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"umi": "4.0.
|
|
49
|
+
"umi": "4.0.17"
|
|
50
50
|
},
|
|
51
51
|
"publishConfig": {
|
|
52
52
|
"access": "public"
|