@umijs/plugins 4.0.0-canary.20220507.2 → 4.0.0-canary.20220512.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/antd.js +16 -7
- package/dist/request.js +11 -11
- package/libs/qiankun/slave/lifecycles.ts +8 -0
- package/package.json +3 -3
package/dist/antd.js
CHANGED
|
@@ -30,7 +30,12 @@ exports.default = (api) => {
|
|
|
30
30
|
});
|
|
31
31
|
},
|
|
32
32
|
},
|
|
33
|
-
enableBy
|
|
33
|
+
enableBy({ userConfig }) {
|
|
34
|
+
// 由于本插件有 api.modifyConfig 的调用,以及 Umi 框架的限制
|
|
35
|
+
// 在其他插件中通过 api.modifyDefaultConfig 设置 antd 并不能让 api.modifyConfig 生效
|
|
36
|
+
// 所以这里通过环境变量来判断是否启用
|
|
37
|
+
return process.env.UMI_PLUGIN_ANTD_ENABLE || userConfig.antd;
|
|
38
|
+
},
|
|
34
39
|
});
|
|
35
40
|
function checkPkgPath() {
|
|
36
41
|
if (!pkgPath) {
|
|
@@ -48,23 +53,27 @@ exports.default = (api) => {
|
|
|
48
53
|
});
|
|
49
54
|
api.modifyConfig((memo) => {
|
|
50
55
|
checkPkgPath();
|
|
56
|
+
const antd = memo.antd || {};
|
|
57
|
+
// defaultConfig 的取值在 config 之后,所以改用环境变量传默认值
|
|
58
|
+
if (process.env.UMI_PLUGIN_ANTD_ENABLE) {
|
|
59
|
+
const { defaultConfig } = JSON.parse(process.env.UMI_PLUGIN_ANTD_ENABLE);
|
|
60
|
+
Object.assign(antd, defaultConfig);
|
|
61
|
+
}
|
|
51
62
|
// antd import
|
|
52
63
|
memo.alias.antd = pkgPath;
|
|
53
64
|
// moment > dayjs
|
|
54
|
-
if (
|
|
65
|
+
if (antd.dayjs) {
|
|
55
66
|
memo.alias.moment = (0, path_1.dirname)(require.resolve('dayjs/package.json'));
|
|
56
67
|
}
|
|
57
68
|
// dark mode & compact mode
|
|
58
|
-
if (
|
|
69
|
+
if (antd.dark || antd.compact) {
|
|
59
70
|
const { getThemeVariables } = require('antd/dist/theme');
|
|
60
71
|
memo.theme = {
|
|
61
|
-
...getThemeVariables(
|
|
72
|
+
...getThemeVariables(antd),
|
|
62
73
|
...memo.theme,
|
|
63
74
|
};
|
|
64
75
|
}
|
|
65
|
-
|
|
66
|
-
});
|
|
67
|
-
api.modifyConfig((memo) => {
|
|
76
|
+
// antd theme
|
|
68
77
|
memo.theme = {
|
|
69
78
|
'root-entry-name': 'default',
|
|
70
79
|
...memo.theme,
|
package/dist/request.js
CHANGED
|
@@ -160,12 +160,12 @@ const getRequestInstance = (): AxiosInstance => {
|
|
|
160
160
|
const config = getConfig();
|
|
161
161
|
requestInstance = axios.create(config);
|
|
162
162
|
|
|
163
|
-
config?.requestInterceptors?.forEach((interceptor) => {
|
|
163
|
+
config?.requestInterceptors?.forEach((interceptor) => {
|
|
164
164
|
if(interceptor instanceof Array){
|
|
165
165
|
requestInstance.interceptors.request.use((config) => {
|
|
166
166
|
const { url } = config;
|
|
167
167
|
if(interceptor[0].length === 2){
|
|
168
|
-
const { url: newUrl, options } = interceptor[0](url, config);
|
|
168
|
+
const { url: newUrl, options } = interceptor[0](url, config);
|
|
169
169
|
return { ...options, url: newUrl };
|
|
170
170
|
}
|
|
171
171
|
return interceptor[0](config);
|
|
@@ -182,16 +182,16 @@ const getRequestInstance = (): AxiosInstance => {
|
|
|
182
182
|
}
|
|
183
183
|
});
|
|
184
184
|
|
|
185
|
-
config?.responseInterceptors?.forEach((interceptor) => {
|
|
186
|
-
interceptor instanceof Array ?
|
|
185
|
+
config?.responseInterceptors?.forEach((interceptor) => {
|
|
186
|
+
interceptor instanceof Array ?
|
|
187
187
|
requestInstance.interceptors.response.use(interceptor[0], interceptor[1]):
|
|
188
188
|
requestInstance.interceptors.response.use(interceptor);
|
|
189
189
|
});
|
|
190
190
|
|
|
191
191
|
// 当响应的数据 success 是 false 的时候,抛出 error 以供 errorHandler 处理。
|
|
192
|
-
requestInstance.interceptors.response.use((response)=>{
|
|
192
|
+
requestInstance.interceptors.response.use((response) => {
|
|
193
193
|
const { data } = response;
|
|
194
|
-
if(config?.errorConfig?.errorThrower){
|
|
194
|
+
if(data?.success === false && config?.errorConfig?.errorThrower){
|
|
195
195
|
config.errorConfig.errorThrower(data);
|
|
196
196
|
}
|
|
197
197
|
return response;
|
|
@@ -199,16 +199,16 @@ const getRequestInstance = (): AxiosInstance => {
|
|
|
199
199
|
return requestInstance;
|
|
200
200
|
};
|
|
201
201
|
|
|
202
|
-
const request: IRequest = (url: string, opts: any = { method: 'GET' }) => {
|
|
202
|
+
const request: IRequest = (url: string, opts: any = { method: 'GET' }) => {
|
|
203
203
|
const requestInstance = getRequestInstance();
|
|
204
204
|
const config = getConfig();
|
|
205
205
|
const { getResponse = false, requestInterceptors, responseInterceptors } = opts;
|
|
206
|
-
const requestInterceptorsToEject = requestInterceptors?.map((interceptor) => {
|
|
206
|
+
const requestInterceptorsToEject = requestInterceptors?.map((interceptor) => {
|
|
207
207
|
if(interceptor instanceof Array){
|
|
208
208
|
return requestInstance.interceptors.request.use((config) => {
|
|
209
209
|
const { url } = config;
|
|
210
210
|
if(interceptor[0].length === 2){
|
|
211
|
-
const { url: newUrl, options } = interceptor[0](url, config);
|
|
211
|
+
const { url: newUrl, options } = interceptor[0](url, config);
|
|
212
212
|
return { ...options, url: newUrl };
|
|
213
213
|
}
|
|
214
214
|
return interceptor[0](config);
|
|
@@ -224,8 +224,8 @@ const request: IRequest = (url: string, opts: any = { method: 'GET' }) => {
|
|
|
224
224
|
})
|
|
225
225
|
}
|
|
226
226
|
});
|
|
227
|
-
const responseInterceptorsToEject = responseInterceptors?.map((interceptor) => {
|
|
228
|
-
return interceptor instanceof Array ?
|
|
227
|
+
const responseInterceptorsToEject = responseInterceptors?.map((interceptor) => {
|
|
228
|
+
return interceptor instanceof Array ?
|
|
229
229
|
requestInstance.interceptors.response.use(interceptor[0], interceptor[1]):
|
|
230
230
|
requestInstance.interceptors.response.use(interceptor);
|
|
231
231
|
});
|
|
@@ -119,6 +119,14 @@ export function genMount(mountElementId: string) {
|
|
|
119
119
|
defer.resolve();
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
+
// 如果需要手动控制 loading,通过主应用配置 props.autoSetLoading false 可以关闭
|
|
123
|
+
// 考虑到 react 18 之后 callback 不再准
|
|
124
|
+
// 所以在这里直接返回,而不使用 ReactDOM.render 的第三个参数
|
|
125
|
+
if (typeof props !== 'undefined') {
|
|
126
|
+
if (props.autoSetLoading && typeof props.setLoading === 'function') {
|
|
127
|
+
props.setLoading(false);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
122
130
|
hasMountedAtLeastOnce = true;
|
|
123
131
|
};
|
|
124
132
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umijs/plugins",
|
|
3
|
-
"version": "4.0.0-canary.
|
|
3
|
+
"version": "4.0.0-canary.20220512.1",
|
|
4
4
|
"description": "@umijs/plugins",
|
|
5
5
|
"homepage": "https://github.com/umijs/umi-next/tree/master/packages/plugins#readme",
|
|
6
6
|
"bugs": "https://github.com/umijs/umi-next/issues",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"@ahooksjs/use-request": "^2.0.0",
|
|
26
26
|
"@ant-design/icons": "^4.7.0",
|
|
27
27
|
"@ant-design/pro-layout": "^6.38.0",
|
|
28
|
-
"@umijs/bundler-utils": "4.0.0-canary.
|
|
28
|
+
"@umijs/bundler-utils": "4.0.0-canary.20220512.1",
|
|
29
29
|
"antd-dayjs-webpack-plugin": "^1.0.6",
|
|
30
30
|
"axios": "^0.27.2",
|
|
31
31
|
"babel-plugin-import": "^1.13.3",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"warning": "^4.0.3"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"umi": "4.0.0-canary.
|
|
47
|
+
"umi": "4.0.0-canary.20220512.1"
|
|
48
48
|
},
|
|
49
49
|
"publishConfig": {
|
|
50
50
|
"access": "public"
|