@umijs/plugins 4.0.7 → 4.0.10
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.js +69 -53
- package/dist/analytics.js +62 -41
- package/dist/antd.js +139 -123
- package/dist/dva.js +155 -141
- package/dist/icons.js +28 -4
- package/dist/initial-state.js +80 -54
- package/dist/layout.js +219 -215
- package/dist/locale.js +214 -192
- package/dist/mf.d.ts +2 -0
- package/dist/mf.js +197 -0
- package/dist/model.js +79 -78
- package/dist/moment2dayjs.js +102 -81
- package/dist/qiankun/constants.js +41 -8
- package/dist/qiankun/master.js +163 -121
- package/dist/qiankun/slave.js +183 -148
- package/dist/qiankun.js +46 -19
- package/dist/request.js +91 -55
- package/dist/tailwindcss.js +74 -49
- package/dist/unocss.js +57 -37
- package/dist/utils/astUtils.js +38 -34
- package/dist/utils/localeUtils.js +125 -120
- package/dist/utils/modelUtils.js +216 -237
- package/dist/utils/resolveProjectDep.js +36 -13
- package/dist/utils/withTmpPath.js +31 -9
- package/libs/locale/localeExports.tpl +7 -3
- package/libs/qiankun/master/MicroApp.tsx +17 -12
- package/libs/qiankun/master/types.ts +1 -1
- package/libs/qiankun/slave/lifecycles.ts +15 -7
- package/package.json +6 -6
package/dist/qiankun/master.js
CHANGED
|
@@ -1,137 +1,179 @@
|
|
|
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_umi = require("umi");
|
|
49
|
+
var import_plugin_utils = require("umi/plugin-utils");
|
|
50
|
+
var import_withTmpPath = require("../utils/withTmpPath");
|
|
51
|
+
var import_constants = require("./constants");
|
|
52
|
+
function isMasterEnable(opts) {
|
|
53
|
+
var _a;
|
|
54
|
+
const masterCfg = (_a = opts.userConfig.qiankun) == null ? void 0 : _a.master;
|
|
55
|
+
if (masterCfg) {
|
|
56
|
+
return masterCfg.enable !== false;
|
|
57
|
+
}
|
|
58
|
+
return !!process.env.INITIAL_QIANKUN_MASTER_OPTIONS;
|
|
16
59
|
}
|
|
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 () => {
|
|
60
|
+
var master_default = (api) => {
|
|
61
|
+
api.describe({
|
|
62
|
+
key: "qiankun-master",
|
|
63
|
+
enableBy: isMasterEnable
|
|
64
|
+
});
|
|
65
|
+
api.addRuntimePlugin(() => {
|
|
66
|
+
return [(0, import_withTmpPath.withTmpPath)({ api, path: "masterRuntimePlugin.tsx" })];
|
|
67
|
+
});
|
|
68
|
+
api.modifyDefaultConfig((config) => __spreadProps(__spreadValues({}, config), {
|
|
69
|
+
mountElementId: import_constants.defaultMasterRootId,
|
|
70
|
+
qiankun: __spreadProps(__spreadValues({}, config.qiankun), {
|
|
71
|
+
master: __spreadValues(__spreadValues({}, JSON.parse(process.env.INITIAL_QIANKUN_MASTER_OPTIONS || "{}")), (config.qiankun || {}).master)
|
|
72
|
+
})
|
|
73
|
+
}));
|
|
74
|
+
api.modifyRoutes((memo) => {
|
|
75
|
+
Object.keys(memo).forEach((id) => {
|
|
76
|
+
var _a;
|
|
77
|
+
const route = memo[id];
|
|
78
|
+
if (route.microApp) {
|
|
79
|
+
const appName = route.microApp;
|
|
80
|
+
const base = api.config.base || "/";
|
|
81
|
+
const masterHistoryType = ((_a = api.config.history) == null ? void 0 : _a.type) || "browser";
|
|
82
|
+
const routeProps = route.microAppProps || {};
|
|
83
|
+
const normalizedRouteProps = JSON.stringify(routeProps).replace(/"/g, "'");
|
|
84
|
+
route.file = `(async () => {
|
|
48
85
|
const { getMicroAppRouteComponent } = await import('@@/plugin-qiankun-master/getMicroAppRouteComponent');
|
|
49
86
|
return getMicroAppRouteComponent({ appName: '${appName}', base: '${base}', routePath: '${route.path}', masterHistoryType: '${masterHistoryType}', routeProps: ${normalizedRouteProps} })
|
|
50
87
|
})()`;
|
|
51
|
-
|
|
52
|
-
});
|
|
53
|
-
return memo;
|
|
88
|
+
}
|
|
54
89
|
});
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
: [];
|
|
66
|
-
},
|
|
67
|
-
});
|
|
68
|
-
function getFileContent(file) {
|
|
69
|
-
return (0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../../libs/qiankun/master', file), 'utf-8');
|
|
90
|
+
return memo;
|
|
91
|
+
});
|
|
92
|
+
api.addRuntimePluginKey(() => [import_constants.MODEL_EXPORT_NAME]);
|
|
93
|
+
api.register({
|
|
94
|
+
key: "addExtraModels",
|
|
95
|
+
fn() {
|
|
96
|
+
const { path, exports } = api.appData.appJS || {};
|
|
97
|
+
return path && exports.includes(import_constants.MODEL_EXPORT_NAME) ? [
|
|
98
|
+
`${path}#{"namespace":"${import_constants.qiankunStateForSlaveModelNamespace}","exportName":"${import_constants.MODEL_EXPORT_NAME}"}`
|
|
99
|
+
] : [];
|
|
70
100
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
101
|
+
});
|
|
102
|
+
function getFileContent(file) {
|
|
103
|
+
return (0, import_fs.readFileSync)((0, import_path.join)(__dirname, "../../libs/qiankun/master", file), "utf-8");
|
|
104
|
+
}
|
|
105
|
+
api.onGenerateFiles(() => {
|
|
106
|
+
var _a;
|
|
107
|
+
api.writeTmpFile({
|
|
108
|
+
path: import_umi.RUNTIME_TYPE_FILE_NAME,
|
|
109
|
+
content: `
|
|
110
|
+
import { MasterOptions } from './types'
|
|
111
|
+
type Without<T, U> = { [P in Exclude<keyof T, keyof U>]?: never };
|
|
112
|
+
type XOR<T, U> = (Without<T, U> & U) | (Without<U, T> & T);
|
|
113
|
+
interface Config {
|
|
114
|
+
master?: MasterOptions;
|
|
115
|
+
}
|
|
116
|
+
export interface IRuntimeConfig {
|
|
117
|
+
qiankun?: XOR<MasterOptions, Config>;
|
|
118
|
+
${import_constants.MODEL_EXPORT_NAME}?: () => Record<string, any>;
|
|
119
|
+
}
|
|
120
|
+
`
|
|
121
|
+
});
|
|
122
|
+
api.writeTmpFile({
|
|
123
|
+
path: "masterOptions.ts",
|
|
124
|
+
content: `
|
|
125
|
+
let options = ${JSON.stringify(__spreadValues({
|
|
126
|
+
masterHistoryType: ((_a = api.config.history) == null ? void 0 : _a.type) || import_constants.defaultHistoryType,
|
|
127
|
+
base: api.config.base || "/"
|
|
128
|
+
}, api.config.qiankun.master))};
|
|
81
129
|
export const getMasterOptions = () => options;
|
|
82
130
|
export const setMasterOptions = (newOpts) => options = ({ ...options, ...newOpts });
|
|
83
|
-
|
|
84
|
-
|
|
131
|
+
`
|
|
132
|
+
});
|
|
133
|
+
api.writeTmpFile({
|
|
134
|
+
path: "MicroAppLoader.tsx",
|
|
135
|
+
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; }`
|
|
136
|
+
});
|
|
137
|
+
[
|
|
138
|
+
"common.ts",
|
|
139
|
+
"constants.ts",
|
|
140
|
+
"types.ts",
|
|
141
|
+
"masterRuntimePlugin.tsx",
|
|
142
|
+
"getMicroAppRouteComponent.tsx.tpl",
|
|
143
|
+
"ErrorBoundary.tsx",
|
|
144
|
+
"MicroApp.tsx",
|
|
145
|
+
"MicroAppWithMemoHistory.tsx"
|
|
146
|
+
].forEach((file) => {
|
|
147
|
+
if (file.endsWith(".tpl")) {
|
|
85
148
|
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
|
-
}
|
|
149
|
+
path: file.replace(/\.tpl$/, ""),
|
|
150
|
+
tpl: getFileContent(file),
|
|
151
|
+
context: {
|
|
152
|
+
dynamicRoot: false,
|
|
153
|
+
hasModelPlugin: api.isPluginEnable("model")
|
|
154
|
+
}
|
|
128
155
|
});
|
|
156
|
+
} else {
|
|
157
|
+
let content = getFileContent(file);
|
|
158
|
+
if (!api.config.qiankun.externalQiankun) {
|
|
159
|
+
content = content.replace(/from 'qiankun'/g, `from '${(0, import_plugin_utils.winPath)((0, import_path.dirname)(require.resolve("qiankun/package")))}'`);
|
|
160
|
+
}
|
|
129
161
|
api.writeTmpFile({
|
|
130
|
-
|
|
131
|
-
|
|
162
|
+
path: file.replace(/\.tpl$/, ""),
|
|
163
|
+
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")))}/`)
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
api.writeTmpFile({
|
|
168
|
+
path: "index.ts",
|
|
169
|
+
content: `
|
|
132
170
|
export { MicroApp } from './MicroApp';
|
|
133
171
|
export { MicroAppWithMemoHistory } from './MicroAppWithMemoHistory';
|
|
134
|
-
|
|
135
|
-
});
|
|
172
|
+
`
|
|
136
173
|
});
|
|
174
|
+
});
|
|
137
175
|
};
|
|
176
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
177
|
+
0 && (module.exports = {
|
|
178
|
+
isMasterEnable
|
|
179
|
+
});
|
package/dist/qiankun/slave.js
CHANGED
|
@@ -1,119 +1,165 @@
|
|
|
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_umi = require("umi");
|
|
49
|
+
var import_plugin_utils = require("umi/plugin-utils");
|
|
50
|
+
var import_withTmpPath = require("../utils/withTmpPath");
|
|
51
|
+
var import_constants = require("./constants");
|
|
13
52
|
function isSlaveEnable(opts) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
53
|
+
var _a, _b;
|
|
54
|
+
const slaveCfg = (_b = (_a = opts.userConfig) == null ? void 0 : _a.qiankun) == null ? void 0 : _b.slave;
|
|
55
|
+
if (slaveCfg) {
|
|
56
|
+
return slaveCfg.enable !== false;
|
|
57
|
+
}
|
|
58
|
+
return !!process.env.INITIAL_QIANKUN_SLAVE_OPTIONS;
|
|
59
|
+
}
|
|
60
|
+
var slave_default = (api) => {
|
|
61
|
+
api.describe({
|
|
62
|
+
key: "qiankun-slave",
|
|
63
|
+
enableBy: isSlaveEnable
|
|
64
|
+
});
|
|
65
|
+
api.addRuntimePlugin(() => {
|
|
66
|
+
return [(0, import_withTmpPath.withTmpPath)({ api, path: "slaveRuntimePlugin.ts" })];
|
|
67
|
+
});
|
|
68
|
+
api.register({
|
|
69
|
+
key: "addExtraModels",
|
|
70
|
+
fn() {
|
|
71
|
+
return [
|
|
72
|
+
(0, import_withTmpPath.withTmpPath)({
|
|
73
|
+
api,
|
|
74
|
+
path: `qiankunModel.ts#{"namespace":"${import_constants.qiankunStateFromMasterModelNamespace}"}`
|
|
75
|
+
})
|
|
76
|
+
];
|
|
18
77
|
}
|
|
19
|
-
|
|
78
|
+
});
|
|
79
|
+
api.onGenerateFiles(() => {
|
|
80
|
+
api.writeTmpFile({
|
|
81
|
+
path: import_umi.RUNTIME_TYPE_FILE_NAME,
|
|
82
|
+
content: `
|
|
83
|
+
interface LifeCycles {
|
|
84
|
+
bootstrap?: (props?: any) => Promise<any>;
|
|
85
|
+
mount?: (props?: any) => Promise<any>;
|
|
86
|
+
unmount?: (props?: any) => Promise<any>;
|
|
87
|
+
update?: (props?: any) => Promise<any>;
|
|
20
88
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
(0, withTmpPath_1.withTmpPath)({
|
|
34
|
-
api,
|
|
35
|
-
path: `qiankunModel.ts#{"namespace":"${constants_1.qiankunStateFromMasterModelNamespace}"}`,
|
|
36
|
-
}),
|
|
37
|
-
];
|
|
38
|
-
},
|
|
39
|
-
});
|
|
40
|
-
api.modifyDefaultConfig((memo) => {
|
|
41
|
-
var _a, _b, _c, _d;
|
|
42
|
-
const initialSlaveOptions = {
|
|
43
|
-
devSourceMap: true,
|
|
44
|
-
...JSON.parse(process.env.INITIAL_QIANKUN_SLAVE_OPTIONS || '{}'),
|
|
45
|
-
...(memo.qiankun || {}).slave,
|
|
46
|
-
};
|
|
47
|
-
const modifiedDefaultConfig = {
|
|
48
|
-
...memo,
|
|
49
|
-
// 默认开启 runtimePublicPath,避免出现 dynamic import 场景子应用资源地址出问题
|
|
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;
|
|
89
|
+
type Without<T, U> = { [P in Exclude<keyof T, keyof U>]?: never };
|
|
90
|
+
type XOR<T, U> = (Without<T, U> & U) | (Without<U, T> & T);
|
|
91
|
+
interface SlaveOption extends LifeCycles {
|
|
92
|
+
enable?: boolean;
|
|
93
|
+
}
|
|
94
|
+
interface Config {
|
|
95
|
+
slave?: SlaveOption;
|
|
96
|
+
}
|
|
97
|
+
export interface IRuntimeConfig {
|
|
98
|
+
qiankun?: XOR<Config, LifeCycles>
|
|
99
|
+
}
|
|
100
|
+
`
|
|
94
101
|
});
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
102
|
+
});
|
|
103
|
+
api.modifyDefaultConfig((memo) => {
|
|
104
|
+
var _a, _b, _c;
|
|
105
|
+
const initialSlaveOptions = __spreadValues(__spreadValues({
|
|
106
|
+
devSourceMap: true
|
|
107
|
+
}, JSON.parse(process.env.INITIAL_QIANKUN_SLAVE_OPTIONS || "{}")), (memo.qiankun || {}).slave);
|
|
108
|
+
const modifiedDefaultConfig = __spreadProps(__spreadValues({}, memo), {
|
|
109
|
+
runtimePublicPath: true,
|
|
110
|
+
qiankun: __spreadProps(__spreadValues({}, memo.qiankun), {
|
|
111
|
+
slave: initialSlaveOptions
|
|
112
|
+
})
|
|
106
113
|
});
|
|
107
|
-
api.
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
+
const shouldNotModifyDefaultBase = ((_b = (_a = api.userConfig.qiankun) == null ? void 0 : _a.slave) == null ? void 0 : _b.shouldNotModifyDefaultBase) ?? initialSlaveOptions.shouldNotModifyDefaultBase;
|
|
115
|
+
const historyType = ((_c = api.userConfig.history) == null ? void 0 : _c.type) || "browser";
|
|
116
|
+
if (!shouldNotModifyDefaultBase && historyType !== "hash") {
|
|
117
|
+
modifiedDefaultConfig.base = `/${api.pkg.name}`;
|
|
118
|
+
}
|
|
119
|
+
return modifiedDefaultConfig;
|
|
120
|
+
});
|
|
121
|
+
api.modifyConfig((config) => {
|
|
122
|
+
var _a, _b;
|
|
123
|
+
if (config.mfsu !== false) {
|
|
124
|
+
config.mfsu = __spreadProps(__spreadValues({}, config.mfsu), {
|
|
125
|
+
mfName: ((_a = config.mfsu) == null ? void 0 : _a.mfName) || `mf_${(_b = api.pkg.name) == null ? void 0 : _b.replace(/^@/, "").replace(/\W/g, "_")}`
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
return config;
|
|
129
|
+
});
|
|
130
|
+
api.addHTMLHeadScripts(() => {
|
|
131
|
+
var _a, _b;
|
|
132
|
+
const dontModify = (_b = (_a = api.config.qiankun) == null ? void 0 : _a.slave) == null ? void 0 : _b.shouldNotModifyRuntimePublicPath;
|
|
133
|
+
return dontModify ? [] : [
|
|
134
|
+
`window.publicPath = window.__INJECTED_PUBLIC_PATH_BY_QIANKUN__ || "${api.config.publicPath || "/"}";`
|
|
135
|
+
];
|
|
136
|
+
});
|
|
137
|
+
api.chainWebpack((config) => {
|
|
138
|
+
(0, import_assert.default)(api.pkg.name, "You should have name in package.json.");
|
|
139
|
+
const { shouldNotAddLibraryChunkName } = (api.config.qiankun || {}).slave;
|
|
140
|
+
config.output.libraryTarget("umd").library(shouldNotAddLibraryChunkName ? api.pkg.name : `${api.pkg.name}-[name]`);
|
|
141
|
+
return config;
|
|
142
|
+
});
|
|
143
|
+
api.modifyHTML(($) => {
|
|
144
|
+
$("script").each((_, el) => {
|
|
145
|
+
const scriptEl = $(el);
|
|
146
|
+
const umiEntry = /\/?umi(\.\w+)?\.js$/g;
|
|
147
|
+
if (umiEntry.test(scriptEl.attr("src") ?? "")) {
|
|
148
|
+
scriptEl.attr("entry", "");
|
|
149
|
+
}
|
|
114
150
|
});
|
|
115
|
-
|
|
116
|
-
|
|
151
|
+
return $;
|
|
152
|
+
});
|
|
153
|
+
api.addEntryImports(() => {
|
|
154
|
+
return [
|
|
155
|
+
{
|
|
156
|
+
source: "@@/plugin-qiankun-slave/lifecycles",
|
|
157
|
+
specifier: "{ genMount as qiankun_genMount, genBootstrap as qiankun_genBootstrap, genUnmount as qiankun_genUnmount, genUpdate as qiankun_genUpdate }"
|
|
158
|
+
}
|
|
159
|
+
];
|
|
160
|
+
});
|
|
161
|
+
api.addEntryCode(() => [
|
|
162
|
+
`
|
|
117
163
|
export const bootstrap = qiankun_genBootstrap(render);
|
|
118
164
|
export const mount = qiankun_genMount('${api.config.mountElementId}');
|
|
119
165
|
export const unmount = qiankun_genUnmount('${api.config.mountElementId}');
|
|
@@ -121,44 +167,33 @@ export const update = qiankun_genUpdate();
|
|
|
121
167
|
if (!window.__POWERED_BY_QIANKUN__) {
|
|
122
168
|
bootstrap().then(mount);
|
|
123
169
|
}
|
|
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: `
|
|
170
|
+
`
|
|
171
|
+
]);
|
|
172
|
+
function getFileContent(file) {
|
|
173
|
+
return (0, import_fs.readFileSync)((0, import_path.join)(__dirname, "../../libs/qiankun/slave", file), "utf-8");
|
|
174
|
+
}
|
|
175
|
+
api.onGenerateFiles({
|
|
176
|
+
fn() {
|
|
177
|
+
[
|
|
178
|
+
"qiankunModel.ts",
|
|
179
|
+
"connectMaster.tsx",
|
|
180
|
+
"slaveRuntimePlugin.ts",
|
|
181
|
+
"lifecycles.ts"
|
|
182
|
+
].forEach((file) => {
|
|
183
|
+
api.writeTmpFile({
|
|
184
|
+
path: file.replace(/\.tpl$/, ""),
|
|
185
|
+
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")))}/`)
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
api.writeTmpFile({
|
|
189
|
+
path: "index.ts",
|
|
190
|
+
content: `
|
|
158
191
|
export { connectMaster } from './connectMaster';
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
192
|
+
`
|
|
193
|
+
});
|
|
194
|
+
},
|
|
195
|
+
before: "model"
|
|
196
|
+
});
|
|
164
197
|
};
|
|
198
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
199
|
+
0 && (module.exports = {});
|