@umijs/plugins 4.0.0-canary.20220718.2 → 4.0.0-canary.20220729.1
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/access.d.ts +0 -1
- package/dist/access.js +69 -53
- package/dist/analytics.d.ts +0 -1
- package/dist/analytics.js +62 -41
- package/dist/antd.d.ts +0 -1
- package/dist/antd.js +139 -123
- package/dist/dva.d.ts +0 -1
- package/dist/dva.js +133 -142
- package/dist/icons.d.ts +0 -1
- package/dist/icons.js +28 -4
- package/dist/initial-state.d.ts +0 -1
- package/dist/initial-state.js +71 -54
- package/dist/layout.d.ts +0 -1
- package/dist/layout.js +205 -214
- package/dist/locale.d.ts +0 -1
- package/dist/locale.js +214 -192
- package/dist/mf.d.ts +2 -0
- package/dist/mf.js +197 -0
- package/dist/model.d.ts +0 -1
- package/dist/model.js +79 -78
- package/dist/moment2dayjs.d.ts +0 -1
- package/dist/moment2dayjs.js +102 -81
- package/dist/qiankun/constants.d.ts +0 -1
- package/dist/qiankun/constants.js +41 -8
- package/dist/qiankun/master.d.ts +0 -1
- package/dist/qiankun/master.js +147 -121
- package/dist/qiankun/slave.d.ts +0 -1
- package/dist/qiankun/slave.js +160 -150
- package/dist/qiankun.d.ts +0 -1
- package/dist/qiankun.js +46 -19
- package/dist/request.d.ts +0 -1
- package/dist/request.js +79 -55
- package/dist/tailwindcss.d.ts +0 -1
- package/dist/tailwindcss.js +70 -49
- package/dist/unocss.d.ts +0 -1
- package/dist/unocss.js +57 -37
- package/dist/utils/astUtils.d.ts +0 -1
- package/dist/utils/astUtils.js +38 -34
- package/dist/utils/localeUtils.d.ts +0 -1
- package/dist/utils/localeUtils.js +125 -120
- package/dist/utils/modelUtils.d.ts +0 -1
- package/dist/utils/modelUtils.js +216 -237
- package/dist/utils/resolveProjectDep.d.ts +0 -1
- package/dist/utils/resolveProjectDep.js +36 -13
- package/dist/utils/withTmpPath.d.ts +0 -1
- package/dist/utils/withTmpPath.js +31 -9
- package/libs/locale/localeExports.tpl +7 -3
- package/libs/qiankun/master/MicroApp.tsx +8 -2
- package/libs/qiankun/slave/lifecycles.ts +15 -7
- package/package.json +6 -6
- package/dist/access.d.ts.map +0 -1
- package/dist/analytics.d.ts.map +0 -1
- package/dist/antd.d.ts.map +0 -1
- package/dist/dva.d.ts.map +0 -1
- package/dist/icons.d.ts.map +0 -1
- package/dist/initial-state.d.ts.map +0 -1
- package/dist/layout.d.ts.map +0 -1
- package/dist/locale.d.ts.map +0 -1
- package/dist/model.d.ts.map +0 -1
- package/dist/moment2dayjs.d.ts.map +0 -1
- package/dist/qiankun/constants.d.ts.map +0 -1
- package/dist/qiankun/master.d.ts.map +0 -1
- package/dist/qiankun/slave.d.ts.map +0 -1
- package/dist/qiankun.d.ts.map +0 -1
- package/dist/request.d.ts.map +0 -1
- package/dist/tailwindcss.d.ts.map +0 -1
- package/dist/unocss.d.ts.map +0 -1
- package/dist/utils/astUtils.d.ts.map +0 -1
- package/dist/utils/localeUtils.d.ts.map +0 -1
- package/dist/utils/modelUtils.d.ts.map +0 -1
- package/dist/utils/resolveProjectDep.d.ts.map +0 -1
- package/dist/utils/withTmpPath.d.ts.map +0 -1
package/dist/qiankun/master.js
CHANGED
|
@@ -1,137 +1,163 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
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]);
|
|
14
20
|
}
|
|
15
|
-
|
|
21
|
+
return a;
|
|
22
|
+
};
|
|
23
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
|
+
var __export = (target, all) => {
|
|
25
|
+
for (var name in all)
|
|
26
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
27
|
+
};
|
|
28
|
+
var __copyProps = (to, from, except, desc) => {
|
|
29
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
30
|
+
for (let key of __getOwnPropNames(from))
|
|
31
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
32
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
33
|
+
}
|
|
34
|
+
return to;
|
|
35
|
+
};
|
|
36
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
37
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
38
|
+
|
|
39
|
+
// src/qiankun/master.ts
|
|
40
|
+
var master_exports = {};
|
|
41
|
+
__export(master_exports, {
|
|
42
|
+
default: () => master_default,
|
|
43
|
+
isMasterEnable: () => isMasterEnable
|
|
44
|
+
});
|
|
45
|
+
module.exports = __toCommonJS(master_exports);
|
|
46
|
+
var import_fs = require("fs");
|
|
47
|
+
var import_path = require("path");
|
|
48
|
+
var import_plugin_utils = require("umi/plugin-utils");
|
|
49
|
+
var import_withTmpPath = require("../utils/withTmpPath");
|
|
50
|
+
var import_constants = require("./constants");
|
|
51
|
+
function isMasterEnable(opts) {
|
|
52
|
+
var _a;
|
|
53
|
+
const masterCfg = (_a = opts.userConfig.qiankun) == null ? void 0 : _a.master;
|
|
54
|
+
if (masterCfg) {
|
|
55
|
+
return masterCfg.enable !== false;
|
|
56
|
+
}
|
|
57
|
+
return !!process.env.INITIAL_QIANKUN_MASTER_OPTIONS;
|
|
16
58
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const appName = route.microApp;
|
|
43
|
-
const base = api.config.base || '/';
|
|
44
|
-
const masterHistoryType = ((_a = api.config.history) === null || _a === void 0 ? void 0 : _a.type) || 'browser';
|
|
45
|
-
const routeProps = route.microAppProps || {};
|
|
46
|
-
const normalizedRouteProps = JSON.stringify(routeProps).replace(/"/g, "'");
|
|
47
|
-
route.file = `(async () => {
|
|
59
|
+
var master_default = (api) => {
|
|
60
|
+
api.describe({
|
|
61
|
+
key: "qiankun-master",
|
|
62
|
+
enableBy: isMasterEnable
|
|
63
|
+
});
|
|
64
|
+
api.addRuntimePlugin(() => {
|
|
65
|
+
return [(0, import_withTmpPath.withTmpPath)({ api, path: "masterRuntimePlugin.tsx" })];
|
|
66
|
+
});
|
|
67
|
+
api.modifyDefaultConfig((config) => __spreadProps(__spreadValues({}, config), {
|
|
68
|
+
mountElementId: import_constants.defaultMasterRootId,
|
|
69
|
+
qiankun: __spreadProps(__spreadValues({}, config.qiankun), {
|
|
70
|
+
master: __spreadValues(__spreadValues({}, JSON.parse(process.env.INITIAL_QIANKUN_MASTER_OPTIONS || "{}")), (config.qiankun || {}).master)
|
|
71
|
+
})
|
|
72
|
+
}));
|
|
73
|
+
api.modifyRoutes((memo) => {
|
|
74
|
+
Object.keys(memo).forEach((id) => {
|
|
75
|
+
var _a;
|
|
76
|
+
const route = memo[id];
|
|
77
|
+
if (route.microApp) {
|
|
78
|
+
const appName = route.microApp;
|
|
79
|
+
const base = api.config.base || "/";
|
|
80
|
+
const masterHistoryType = ((_a = api.config.history) == null ? void 0 : _a.type) || "browser";
|
|
81
|
+
const routeProps = route.microAppProps || {};
|
|
82
|
+
const normalizedRouteProps = JSON.stringify(routeProps).replace(/"/g, "'");
|
|
83
|
+
route.file = `(async () => {
|
|
48
84
|
const { getMicroAppRouteComponent } = await import('@@/plugin-qiankun-master/getMicroAppRouteComponent');
|
|
49
85
|
return getMicroAppRouteComponent({ appName: '${appName}', base: '${base}', routePath: '${route.path}', masterHistoryType: '${masterHistoryType}', routeProps: ${normalizedRouteProps} })
|
|
50
86
|
})()`;
|
|
51
|
-
|
|
52
|
-
});
|
|
53
|
-
return memo;
|
|
54
|
-
});
|
|
55
|
-
// state model for slave app
|
|
56
|
-
api.addRuntimePluginKey(() => [constants_1.MODEL_EXPORT_NAME]);
|
|
57
|
-
api.register({
|
|
58
|
-
key: 'addExtraModels',
|
|
59
|
-
fn() {
|
|
60
|
-
const { path, exports } = api.appData.appJS || {};
|
|
61
|
-
return path && exports.includes(constants_1.MODEL_EXPORT_NAME)
|
|
62
|
-
? [
|
|
63
|
-
`${path}#{"namespace":"${constants_1.qiankunStateForSlaveModelNamespace}","exportName":"${constants_1.MODEL_EXPORT_NAME}"}`,
|
|
64
|
-
]
|
|
65
|
-
: [];
|
|
66
|
-
},
|
|
87
|
+
}
|
|
67
88
|
});
|
|
68
|
-
|
|
69
|
-
|
|
89
|
+
return memo;
|
|
90
|
+
});
|
|
91
|
+
api.addRuntimePluginKey(() => [import_constants.MODEL_EXPORT_NAME]);
|
|
92
|
+
api.register({
|
|
93
|
+
key: "addExtraModels",
|
|
94
|
+
fn() {
|
|
95
|
+
const { path, exports } = api.appData.appJS || {};
|
|
96
|
+
return path && exports.includes(import_constants.MODEL_EXPORT_NAME) ? [
|
|
97
|
+
`${path}#{"namespace":"${import_constants.qiankunStateForSlaveModelNamespace}","exportName":"${import_constants.MODEL_EXPORT_NAME}"}`
|
|
98
|
+
] : [];
|
|
70
99
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
100
|
+
});
|
|
101
|
+
function getFileContent(file) {
|
|
102
|
+
return (0, import_fs.readFileSync)((0, import_path.join)(__dirname, "../../libs/qiankun/master", file), "utf-8");
|
|
103
|
+
}
|
|
104
|
+
api.onGenerateFiles(() => {
|
|
105
|
+
var _a;
|
|
106
|
+
api.writeTmpFile({
|
|
107
|
+
path: "masterOptions.ts",
|
|
108
|
+
content: `
|
|
109
|
+
let options = ${JSON.stringify(__spreadValues({
|
|
110
|
+
masterHistoryType: ((_a = api.config.history) == null ? void 0 : _a.type) || import_constants.defaultHistoryType,
|
|
111
|
+
base: api.config.base || "/"
|
|
112
|
+
}, api.config.qiankun.master))};
|
|
81
113
|
export const getMasterOptions = () => options;
|
|
82
114
|
export const setMasterOptions = (newOpts) => options = ({ ...options, ...newOpts });
|
|
83
|
-
|
|
84
|
-
|
|
115
|
+
`
|
|
116
|
+
});
|
|
117
|
+
api.writeTmpFile({
|
|
118
|
+
path: "MicroAppLoader.tsx",
|
|
119
|
+
content: api.isPluginEnable("antd") ? getFileContent("AntdLoader.tsx") : `export default function Loader() { console.warn(\`[plugins/qiankun]: Seems like you'r not using @umijs/plugin-antd, you need to provide a custom loader or set autoSetLoading false to shut down this warning!\`); return null; }`
|
|
120
|
+
});
|
|
121
|
+
[
|
|
122
|
+
"common.ts",
|
|
123
|
+
"constants.ts",
|
|
124
|
+
"types.ts",
|
|
125
|
+
"masterRuntimePlugin.tsx",
|
|
126
|
+
"getMicroAppRouteComponent.tsx.tpl",
|
|
127
|
+
"ErrorBoundary.tsx",
|
|
128
|
+
"MicroApp.tsx",
|
|
129
|
+
"MicroAppWithMemoHistory.tsx"
|
|
130
|
+
].forEach((file) => {
|
|
131
|
+
if (file.endsWith(".tpl")) {
|
|
85
132
|
api.writeTmpFile({
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
[
|
|
93
|
-
'common.ts',
|
|
94
|
-
'constants.ts',
|
|
95
|
-
'types.ts',
|
|
96
|
-
'masterRuntimePlugin.tsx',
|
|
97
|
-
'getMicroAppRouteComponent.tsx.tpl',
|
|
98
|
-
'ErrorBoundary.tsx',
|
|
99
|
-
'MicroApp.tsx',
|
|
100
|
-
'MicroAppWithMemoHistory.tsx',
|
|
101
|
-
].forEach((file) => {
|
|
102
|
-
if (file.endsWith('.tpl')) {
|
|
103
|
-
api.writeTmpFile({
|
|
104
|
-
path: file.replace(/\.tpl$/, ''),
|
|
105
|
-
tpl: getFileContent(file),
|
|
106
|
-
context: {
|
|
107
|
-
dynamicRoot: false,
|
|
108
|
-
hasModelPlugin: api.isPluginEnable('model'),
|
|
109
|
-
// dynamicRoot:
|
|
110
|
-
// api.config.exportStatic && api.config.exportStatic.dynamicRoot,
|
|
111
|
-
},
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
let content = getFileContent(file);
|
|
116
|
-
if (!api.config.qiankun.externalQiankun) {
|
|
117
|
-
content = content.replace(/from 'qiankun'/g, `from '${(0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve('qiankun/package')))}'`);
|
|
118
|
-
}
|
|
119
|
-
api.writeTmpFile({
|
|
120
|
-
path: file.replace(/\.tpl$/, ''),
|
|
121
|
-
content: content
|
|
122
|
-
.replace('__USE_MODEL__', api.isPluginEnable('model')
|
|
123
|
-
? `import { useModel } from '@@/plugin-model'`
|
|
124
|
-
: `const useModel = null;`)
|
|
125
|
-
.replace(/from 'lodash\//g, `from '${(0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve('lodash/package')))}/`),
|
|
126
|
-
});
|
|
127
|
-
}
|
|
133
|
+
path: file.replace(/\.tpl$/, ""),
|
|
134
|
+
tpl: getFileContent(file),
|
|
135
|
+
context: {
|
|
136
|
+
dynamicRoot: false,
|
|
137
|
+
hasModelPlugin: api.isPluginEnable("model")
|
|
138
|
+
}
|
|
128
139
|
});
|
|
140
|
+
} else {
|
|
141
|
+
let content = getFileContent(file);
|
|
142
|
+
if (!api.config.qiankun.externalQiankun) {
|
|
143
|
+
content = content.replace(/from 'qiankun'/g, `from '${(0, import_plugin_utils.winPath)((0, import_path.dirname)(require.resolve("qiankun/package")))}'`);
|
|
144
|
+
}
|
|
129
145
|
api.writeTmpFile({
|
|
130
|
-
|
|
131
|
-
|
|
146
|
+
path: file.replace(/\.tpl$/, ""),
|
|
147
|
+
content: content.replace("__USE_MODEL__", api.isPluginEnable("model") ? `import { useModel } from '@@/plugin-model'` : `const useModel = null;`).replace(/from 'lodash\//g, `from '${(0, import_plugin_utils.winPath)((0, import_path.dirname)(require.resolve("lodash/package")))}/`)
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
api.writeTmpFile({
|
|
152
|
+
path: "index.ts",
|
|
153
|
+
content: `
|
|
132
154
|
export { MicroApp } from './MicroApp';
|
|
133
155
|
export { MicroAppWithMemoHistory } from './MicroAppWithMemoHistory';
|
|
134
|
-
|
|
135
|
-
});
|
|
156
|
+
`
|
|
136
157
|
});
|
|
158
|
+
});
|
|
137
159
|
};
|
|
160
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
161
|
+
0 && (module.exports = {
|
|
162
|
+
isMasterEnable
|
|
163
|
+
});
|
package/dist/qiankun/slave.d.ts
CHANGED
package/dist/qiankun/slave.js
CHANGED
|
@@ -1,119 +1,140 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
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
|
+
var __export = (target, all) => {
|
|
25
|
+
for (var name in all)
|
|
26
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
27
|
+
};
|
|
28
|
+
var __copyProps = (to, from, except, desc) => {
|
|
29
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
30
|
+
for (let key of __getOwnPropNames(from))
|
|
31
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
32
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
33
|
+
}
|
|
34
|
+
return to;
|
|
4
35
|
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
36
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
37
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
38
|
+
|
|
39
|
+
// src/qiankun/slave.ts
|
|
40
|
+
var slave_exports = {};
|
|
41
|
+
__export(slave_exports, {
|
|
42
|
+
default: () => slave_default
|
|
43
|
+
});
|
|
44
|
+
module.exports = __toCommonJS(slave_exports);
|
|
45
|
+
var import_assert = __toESM(require("assert"));
|
|
46
|
+
var import_fs = require("fs");
|
|
47
|
+
var import_path = require("path");
|
|
48
|
+
var import_plugin_utils = require("umi/plugin-utils");
|
|
49
|
+
var import_withTmpPath = require("../utils/withTmpPath");
|
|
50
|
+
var import_constants = require("./constants");
|
|
13
51
|
function isSlaveEnable(opts) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
52
|
+
var _a, _b;
|
|
53
|
+
const slaveCfg = (_b = (_a = opts.userConfig) == null ? void 0 : _a.qiankun) == null ? void 0 : _b.slave;
|
|
54
|
+
if (slaveCfg) {
|
|
55
|
+
return slaveCfg.enable !== false;
|
|
56
|
+
}
|
|
57
|
+
return !!process.env.INITIAL_QIANKUN_SLAVE_OPTIONS;
|
|
20
58
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
runtimePublicPath: true,
|
|
51
|
-
qiankun: {
|
|
52
|
-
...memo.qiankun,
|
|
53
|
-
slave: initialSlaveOptions,
|
|
54
|
-
},
|
|
55
|
-
};
|
|
56
|
-
const shouldNotModifyDefaultBase = (_c = (_b = (_a = api.userConfig.qiankun) === null || _a === void 0 ? void 0 : _a.slave) === null || _b === void 0 ? void 0 : _b.shouldNotModifyDefaultBase) !== null && _c !== void 0 ? _c : initialSlaveOptions.shouldNotModifyDefaultBase;
|
|
57
|
-
const historyType = ((_d = api.userConfig.history) === null || _d === void 0 ? void 0 : _d.type) || 'browser';
|
|
58
|
-
if (!shouldNotModifyDefaultBase && historyType !== 'hash') {
|
|
59
|
-
// @ts-ignore
|
|
60
|
-
modifiedDefaultConfig.base = `/${api.pkg.name}`;
|
|
61
|
-
}
|
|
62
|
-
return modifiedDefaultConfig;
|
|
63
|
-
});
|
|
64
|
-
api.modifyConfig((config) => {
|
|
65
|
-
var _a, _b;
|
|
66
|
-
// mfsu 场景默认给子应用增加 mfName 配置,从而避免冲突
|
|
67
|
-
if (config.mfsu !== false) {
|
|
68
|
-
config.mfsu = {
|
|
69
|
-
...config.mfsu,
|
|
70
|
-
mfName: ((_a = config.mfsu) === null || _a === void 0 ? void 0 : _a.mfName) ||
|
|
71
|
-
`mf_${(_b = api.pkg.name) === null || _b === void 0 ? void 0 : _b.replace(/^@/, '').replace(/\W/g, '_')}`,
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
return config;
|
|
75
|
-
});
|
|
76
|
-
api.addHTMLHeadScripts(() => {
|
|
77
|
-
var _a, _b;
|
|
78
|
-
const dontModify = (_b = (_a = api.config.qiankun) === null || _a === void 0 ? void 0 : _a.slave) === null || _b === void 0 ? void 0 : _b.shouldNotModifyRuntimePublicPath;
|
|
79
|
-
return dontModify
|
|
80
|
-
? []
|
|
81
|
-
: [
|
|
82
|
-
`window.publicPath = window.__INJECTED_PUBLIC_PATH_BY_QIANKUN__ || "${api.config.publicPath || '/'}";`,
|
|
83
|
-
];
|
|
84
|
-
});
|
|
85
|
-
api.chainWebpack((config) => {
|
|
86
|
-
(0, assert_1.default)(api.pkg.name, 'You should have name in package.json.');
|
|
87
|
-
const { shouldNotAddLibraryChunkName } = (api.config.qiankun || {}).slave;
|
|
88
|
-
config.output
|
|
89
|
-
.libraryTarget('umd')
|
|
90
|
-
.library(shouldNotAddLibraryChunkName ? api.pkg.name : `${api.pkg.name}-[name]`);
|
|
91
|
-
// TODO: SOCKET_SERVER
|
|
92
|
-
// TODO: devSourceMap
|
|
93
|
-
return config;
|
|
94
|
-
});
|
|
95
|
-
// umi bundle 添加 entry 标记
|
|
96
|
-
api.modifyHTML(($) => {
|
|
97
|
-
$('script').each((_, el) => {
|
|
98
|
-
var _a;
|
|
99
|
-
const scriptEl = $(el);
|
|
100
|
-
const umiEntry = /\/?umi(\.\w+)?\.js$/g;
|
|
101
|
-
if (umiEntry.test((_a = scriptEl.attr('src')) !== null && _a !== void 0 ? _a : '')) {
|
|
102
|
-
scriptEl.attr('entry', '');
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
return $;
|
|
59
|
+
var slave_default = (api) => {
|
|
60
|
+
api.describe({
|
|
61
|
+
key: "qiankun-slave",
|
|
62
|
+
enableBy: isSlaveEnable
|
|
63
|
+
});
|
|
64
|
+
api.addRuntimePlugin(() => {
|
|
65
|
+
return [(0, import_withTmpPath.withTmpPath)({ api, path: "slaveRuntimePlugin.ts" })];
|
|
66
|
+
});
|
|
67
|
+
api.register({
|
|
68
|
+
key: "addExtraModels",
|
|
69
|
+
fn() {
|
|
70
|
+
return [
|
|
71
|
+
(0, import_withTmpPath.withTmpPath)({
|
|
72
|
+
api,
|
|
73
|
+
path: `qiankunModel.ts#{"namespace":"${import_constants.qiankunStateFromMasterModelNamespace}"}`
|
|
74
|
+
})
|
|
75
|
+
];
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
api.modifyDefaultConfig((memo) => {
|
|
79
|
+
var _a, _b, _c;
|
|
80
|
+
const initialSlaveOptions = __spreadValues(__spreadValues({
|
|
81
|
+
devSourceMap: true
|
|
82
|
+
}, JSON.parse(process.env.INITIAL_QIANKUN_SLAVE_OPTIONS || "{}")), (memo.qiankun || {}).slave);
|
|
83
|
+
const modifiedDefaultConfig = __spreadProps(__spreadValues({}, memo), {
|
|
84
|
+
runtimePublicPath: true,
|
|
85
|
+
qiankun: __spreadProps(__spreadValues({}, memo.qiankun), {
|
|
86
|
+
slave: initialSlaveOptions
|
|
87
|
+
})
|
|
106
88
|
});
|
|
107
|
-
api.
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
89
|
+
const shouldNotModifyDefaultBase = ((_b = (_a = api.userConfig.qiankun) == null ? void 0 : _a.slave) == null ? void 0 : _b.shouldNotModifyDefaultBase) ?? initialSlaveOptions.shouldNotModifyDefaultBase;
|
|
90
|
+
const historyType = ((_c = api.userConfig.history) == null ? void 0 : _c.type) || "browser";
|
|
91
|
+
if (!shouldNotModifyDefaultBase && historyType !== "hash") {
|
|
92
|
+
modifiedDefaultConfig.base = `/${api.pkg.name}`;
|
|
93
|
+
}
|
|
94
|
+
return modifiedDefaultConfig;
|
|
95
|
+
});
|
|
96
|
+
api.modifyConfig((config) => {
|
|
97
|
+
var _a, _b;
|
|
98
|
+
if (config.mfsu !== false) {
|
|
99
|
+
config.mfsu = __spreadProps(__spreadValues({}, config.mfsu), {
|
|
100
|
+
mfName: ((_a = config.mfsu) == null ? void 0 : _a.mfName) || `mf_${(_b = api.pkg.name) == null ? void 0 : _b.replace(/^@/, "").replace(/\W/g, "_")}`
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
return config;
|
|
104
|
+
});
|
|
105
|
+
api.addHTMLHeadScripts(() => {
|
|
106
|
+
var _a, _b;
|
|
107
|
+
const dontModify = (_b = (_a = api.config.qiankun) == null ? void 0 : _a.slave) == null ? void 0 : _b.shouldNotModifyRuntimePublicPath;
|
|
108
|
+
return dontModify ? [] : [
|
|
109
|
+
`window.publicPath = window.__INJECTED_PUBLIC_PATH_BY_QIANKUN__ || "${api.config.publicPath || "/"}";`
|
|
110
|
+
];
|
|
111
|
+
});
|
|
112
|
+
api.chainWebpack((config) => {
|
|
113
|
+
(0, import_assert.default)(api.pkg.name, "You should have name in package.json.");
|
|
114
|
+
const { shouldNotAddLibraryChunkName } = (api.config.qiankun || {}).slave;
|
|
115
|
+
config.output.libraryTarget("umd").library(shouldNotAddLibraryChunkName ? api.pkg.name : `${api.pkg.name}-[name]`);
|
|
116
|
+
return config;
|
|
117
|
+
});
|
|
118
|
+
api.modifyHTML(($) => {
|
|
119
|
+
$("script").each((_, el) => {
|
|
120
|
+
const scriptEl = $(el);
|
|
121
|
+
const umiEntry = /\/?umi(\.\w+)?\.js$/g;
|
|
122
|
+
if (umiEntry.test(scriptEl.attr("src") ?? "")) {
|
|
123
|
+
scriptEl.attr("entry", "");
|
|
124
|
+
}
|
|
114
125
|
});
|
|
115
|
-
|
|
116
|
-
|
|
126
|
+
return $;
|
|
127
|
+
});
|
|
128
|
+
api.addEntryImports(() => {
|
|
129
|
+
return [
|
|
130
|
+
{
|
|
131
|
+
source: "@@/plugin-qiankun-slave/lifecycles",
|
|
132
|
+
specifier: "{ genMount as qiankun_genMount, genBootstrap as qiankun_genBootstrap, genUnmount as qiankun_genUnmount, genUpdate as qiankun_genUpdate }"
|
|
133
|
+
}
|
|
134
|
+
];
|
|
135
|
+
});
|
|
136
|
+
api.addEntryCode(() => [
|
|
137
|
+
`
|
|
117
138
|
export const bootstrap = qiankun_genBootstrap(render);
|
|
118
139
|
export const mount = qiankun_genMount('${api.config.mountElementId}');
|
|
119
140
|
export const unmount = qiankun_genUnmount('${api.config.mountElementId}');
|
|
@@ -121,44 +142,33 @@ export const update = qiankun_genUpdate();
|
|
|
121
142
|
if (!window.__POWERED_BY_QIANKUN__) {
|
|
122
143
|
bootstrap().then(mount);
|
|
123
144
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
api.writeTmpFile({
|
|
146
|
-
path: file.replace(/\.tpl$/, ''),
|
|
147
|
-
content: getFileContent(file)
|
|
148
|
-
.replace('__USE_MODEL__', api.isPluginEnable('model')
|
|
149
|
-
? `import { useModel } from '@@/plugin-model'`
|
|
150
|
-
: `const useModel = null;`)
|
|
151
|
-
.replace(/from 'qiankun'/g, `from '${(0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve('qiankun/package')))}'`)
|
|
152
|
-
.replace(/from 'lodash\//g, `from '${(0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve('lodash/package')))}/`),
|
|
153
|
-
});
|
|
154
|
-
});
|
|
155
|
-
api.writeTmpFile({
|
|
156
|
-
path: 'index.ts',
|
|
157
|
-
content: `
|
|
145
|
+
`
|
|
146
|
+
]);
|
|
147
|
+
function getFileContent(file) {
|
|
148
|
+
return (0, import_fs.readFileSync)((0, import_path.join)(__dirname, "../../libs/qiankun/slave", file), "utf-8");
|
|
149
|
+
}
|
|
150
|
+
api.onGenerateFiles({
|
|
151
|
+
fn() {
|
|
152
|
+
[
|
|
153
|
+
"qiankunModel.ts",
|
|
154
|
+
"connectMaster.tsx",
|
|
155
|
+
"slaveRuntimePlugin.ts",
|
|
156
|
+
"lifecycles.ts"
|
|
157
|
+
].forEach((file) => {
|
|
158
|
+
api.writeTmpFile({
|
|
159
|
+
path: file.replace(/\.tpl$/, ""),
|
|
160
|
+
content: getFileContent(file).replace("__USE_MODEL__", api.isPluginEnable("model") ? `import { useModel } from '@@/plugin-model'` : `const useModel = null;`).replace(/from 'qiankun'/g, `from '${(0, import_plugin_utils.winPath)((0, import_path.dirname)(require.resolve("qiankun/package")))}'`).replace(/from 'lodash\//g, `from '${(0, import_plugin_utils.winPath)((0, import_path.dirname)(require.resolve("lodash/package")))}/`)
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
api.writeTmpFile({
|
|
164
|
+
path: "index.ts",
|
|
165
|
+
content: `
|
|
158
166
|
export { connectMaster } from './connectMaster';
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
167
|
+
`
|
|
168
|
+
});
|
|
169
|
+
},
|
|
170
|
+
before: "model"
|
|
171
|
+
});
|
|
164
172
|
};
|
|
173
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
174
|
+
0 && (module.exports = {});
|
package/dist/qiankun.d.ts
CHANGED