generator-mico-cli 0.2.27 → 0.2.28
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/generators/micro-react/templates/apps/layout/config/config.dev.ts +3 -2
- package/generators/micro-react/templates/apps/layout/config/config.prod.development.ts +0 -2
- package/generators/micro-react/templates/apps/layout/config/config.prod.testing.ts +0 -2
- package/generators/micro-react/templates/apps/layout/config/config.prod.ts +1 -3
- package/generators/micro-react/templates/apps/layout/docs/feat-/346/236/204/345/273/272define/344/270/216/345/205/215/350/256/244/350/257/201/345/210/235/345/247/213/346/200/201.md +44 -0
- package/generators/micro-react/templates/apps/layout/docs/feature-/345/276/256/345/211/215/347/253/257/346/250/241/345/274/217.md +11 -6
- package/generators/micro-react/templates/apps/layout/src/app.tsx +2 -1
- package/generators/micro-react/templates/packages/common-intl/src/intl.ts +7 -1
- package/package.json +1 -1
|
@@ -33,6 +33,9 @@ const config: ReturnType<typeof defineConfig> = {
|
|
|
33
33
|
// noLayoutRouteList: [],
|
|
34
34
|
// 关闭权限控制(调试用)
|
|
35
35
|
disableAuth: false,
|
|
36
|
+
// SSO 外跳地址(与 resolveExternalLoginPath 读取的 externalLoginPath 一致;生产由注入的 __MICO_CONFIG__ 提供)
|
|
37
|
+
externalLoginPath:
|
|
38
|
+
'https://micous-idp.cig.tencentcs.com/sso/xxxxxxx/cas',
|
|
36
39
|
};
|
|
37
40
|
`,
|
|
38
41
|
},
|
|
@@ -68,8 +71,6 @@ const config: ReturnType<typeof defineConfig> = {
|
|
|
68
71
|
'https://dashboard-api-test.micoplatform.com/api/yufu_login/',
|
|
69
72
|
'process.env.REFRESH_ENDPOINT':
|
|
70
73
|
'https://dashboard-api-test.micoplatform.com/api/yufu_login/refresh/',
|
|
71
|
-
'process.env.EXTERNAL_LOGIN_PATH':
|
|
72
|
-
'https://micous-idp.cig.tencentcs.com/sso/xxxxxxx/cas',
|
|
73
74
|
},
|
|
74
75
|
};
|
|
75
76
|
|
|
@@ -33,8 +33,6 @@ const config: ReturnType<typeof defineConfig> = {
|
|
|
33
33
|
'https://dashboard-api-test.micoplatform.com/api/yufu_login/',
|
|
34
34
|
'process.env.REFRESH_ENDPOINT':
|
|
35
35
|
'https://dashboard-api-test.micoplatform.com/api/yufu_login/refresh/',
|
|
36
|
-
'process.env.EXTERNAL_LOGIN_PATH':
|
|
37
|
-
'https://micous-idp.cig.tencentcs.com/sso/xxxxxxx/cas',
|
|
38
36
|
},
|
|
39
37
|
};
|
|
40
38
|
|
|
@@ -33,8 +33,6 @@ const config: ReturnType<typeof defineConfig> = {
|
|
|
33
33
|
'https://dashboard-api-test.micoplatform.com/api/yufu_login/',
|
|
34
34
|
'process.env.REFRESH_ENDPOINT':
|
|
35
35
|
'https://dashboard-api-test.micoplatform.com/api/yufu_login/refresh/',
|
|
36
|
-
'process.env.EXTERNAL_LOGIN_PATH':
|
|
37
|
-
'https://micous-idp.cig.tencentcs.com/sso/xxxxxxx/cas',
|
|
38
36
|
},
|
|
39
37
|
};
|
|
40
38
|
|
|
@@ -21,8 +21,6 @@ const config: ReturnType<typeof defineConfig> = {
|
|
|
21
21
|
'https://dashboard-api.micoplatform.com/api/yufu_login/',
|
|
22
22
|
'process.env.REFRESH_ENDPOINT':
|
|
23
23
|
'https://dashboard-api.micoplatform.com/api/yufu_login/refresh/',
|
|
24
|
-
'process.env.EXTERNAL_LOGIN_PATH':
|
|
25
|
-
'https://micous-idp.cig.tencentcs.com/sso/xxxxxxx/cas',
|
|
26
24
|
},
|
|
27
25
|
externals: {
|
|
28
26
|
react: 'React',
|
|
@@ -33,7 +31,7 @@ const config: ReturnType<typeof defineConfig> = {
|
|
|
33
31
|
extraBabelPlugins: ['babel-plugin-dynamic-import-node'],
|
|
34
32
|
|
|
35
33
|
// 禁用代码分割,只输出一个 JS 和一个 CSS
|
|
36
|
-
chainWebpack(memo) {
|
|
34
|
+
chainWebpack(memo: any) {
|
|
37
35
|
// 禁用 splitChunks
|
|
38
36
|
memo.optimization.splitChunks(false);
|
|
39
37
|
// 禁用 runtimeChunk
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# 构建 define 精简与免认证页初始态
|
|
2
|
+
|
|
3
|
+
> 创建时间:2026-03-24
|
|
4
|
+
|
|
5
|
+
## 功能概述
|
|
6
|
+
|
|
7
|
+
1. **Umi `define`**:不再通过构建期注入 `process.env.EXTERNAL_LOGIN_PATH`(本模板从未注入 `APP_ID`);SSO 外跳等依赖运行时 `window.__MICO_CONFIG__`。
|
|
8
|
+
2. **`getInitialState`**:免认证路由下即使本地仍有 token,也不请求用户信息接口,减少无效调用。
|
|
9
|
+
|
|
10
|
+
## 技术方案
|
|
11
|
+
|
|
12
|
+
### 开发环境
|
|
13
|
+
|
|
14
|
+
`config/config.dev.ts` 的 `headScripts` 中 `window.__MICO_CONFIG__` 增加 **`externalLoginPath`**(模板默认为占位 URL,生成项目后请按实际 IdP 修改)。
|
|
15
|
+
|
|
16
|
+
`define` 仅保留 `NODE_ENV`、`API_BASE_URL`、`LOGIN_ENDPOINT`、`REFRESH_ENDPOINT`。
|
|
17
|
+
|
|
18
|
+
### 生产 / 测试构建
|
|
19
|
+
|
|
20
|
+
`config.prod.ts`、`config.prod.development.ts`、`config.prod.testing.ts` 的 `define` 中同样**不包含** `EXTERNAL_LOGIN_PATH`,由部署时注入的 `__MICO_CONFIG__.externalLoginPath`(或 `__MICO_WORKSPACE__.casServerLoginUrl`)提供。
|
|
21
|
+
|
|
22
|
+
### 初始态
|
|
23
|
+
|
|
24
|
+
`src/app.tsx` 中仅在 `getStoredAuthToken() && !skipAuth` 时调用 `fetchUserInfoFn()`;`skipAuth = isNoAuthRoute || isPageAuthFree`。
|
|
25
|
+
|
|
26
|
+
## 文件清单
|
|
27
|
+
|
|
28
|
+
| 文件路径 | 说明 |
|
|
29
|
+
| --- | --- |
|
|
30
|
+
| `config/config.dev.ts` | `__MICO_CONFIG__.externalLoginPath`;移除 `EXTERNAL_LOGIN_PATH` define |
|
|
31
|
+
| `config/config.prod.ts` | 移除 `EXTERNAL_LOGIN_PATH` define |
|
|
32
|
+
| `config/config.prod.development.ts` | 同上 |
|
|
33
|
+
| `config/config.prod.testing.ts` | 同上 |
|
|
34
|
+
| `src/app.tsx` | `fetchUserInfo` 条件增加 `!skipAuth` |
|
|
35
|
+
|
|
36
|
+
## 部署注意
|
|
37
|
+
|
|
38
|
+
- 生产 HTML 或网关需保证 `window.__MICO_CONFIG__` 含 **`appId`**、**`externalLoginPath`**(或与现有网关字段对齐),否则代理前缀、SSO 外跳可能异常。
|
|
39
|
+
- 详见 `src/common/request/config.ts` 中 `buildDefaultClientOptions` 的解析顺序。
|
|
40
|
+
|
|
41
|
+
## 相关文档
|
|
42
|
+
|
|
43
|
+
- [fix-SSO无限重定向](./fix-SSO无限重定向.md)
|
|
44
|
+
- [arch-请求模块](./arch-请求模块.md)
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
|
|
46
46
|
```typescript
|
|
47
47
|
interface MicroAppLoaderProps {
|
|
48
|
-
/**
|
|
48
|
+
/** 微应用在主应用中的挂载路径前缀(来自 ParsedRoute.base / 页面配置 base),经 normalizeMicroAppBase 后传给子应用 */
|
|
49
49
|
base: string;
|
|
50
50
|
/** 微应用入口 URL */
|
|
51
51
|
entry: string;
|
|
@@ -76,10 +76,10 @@ interface MicroAppLoaderProps {
|
|
|
76
76
|
|
|
77
77
|
| 字段 | 含义 |
|
|
78
78
|
| --- | --- |
|
|
79
|
-
| **base** |
|
|
79
|
+
| **base** | 该微应用在主应用中的**挂载前缀**,来自中台 **`page.base`**,解析为 **`ParsedRoute.base`**(缺省时解析为 **`'/'`**);可与动态路由 **`path`** 不同(如 `path` 为 `/subapp/*` 时 `base` 可为 `/subapp`)。 |
|
|
80
80
|
| **routePath** | 当前激活的**完整路由路径**,随浏览器 URL 变化,用于通知子应用做**内部路由同步**。 |
|
|
81
81
|
|
|
82
|
-
|
|
82
|
+
`routePath` 在布局内为 **`currentRoute.path`**。`base` 在 **`patchClientRoutes`** 与布局内均为 **`route.base` / `currentRoute.base`**。**`name`** 在布局侧常为基于 **`entry`** 的 **`getAppNameFromEntry`**,与 **`base`** 来源不同,需注意。
|
|
83
83
|
|
|
84
84
|
#### `normalizeMicroAppBase`
|
|
85
85
|
|
|
@@ -96,8 +96,8 @@ export const normalizeMicroAppBase = (path: string): string =>
|
|
|
96
96
|
|
|
97
97
|
| 位置 | 说明 |
|
|
98
98
|
| --- | --- |
|
|
99
|
-
| `src/app.tsx` `patchClientRoutes` | 动态注册微应用路由时:`React.createElement(MicroAppLoader, { entry, name: route.path, base: route.
|
|
100
|
-
| `src/layouts/index.tsx` | 布局内渲染:`<MicroAppLoader base={currentRoute.
|
|
99
|
+
| `src/app.tsx` `patchClientRoutes` | 动态注册微应用路由时:`React.createElement(MicroAppLoader, { entry, name: route.path, base: route.base, ... })` |
|
|
100
|
+
| `src/layouts/index.tsx` | 布局内渲染:`<MicroAppLoader base={currentRoute.base} routePath={currentRoute.path} ... />` |
|
|
101
101
|
|
|
102
102
|
#### 加载门控(认证)
|
|
103
103
|
|
|
@@ -165,6 +165,8 @@ export async function update(props: MicroAppProps) {
|
|
|
165
165
|
```typescript
|
|
166
166
|
interface ParsedRoute {
|
|
167
167
|
path: string;
|
|
168
|
+
/** 微应用挂载前缀(来自 page.base,解析缺省为 '/') */
|
|
169
|
+
base: string;
|
|
168
170
|
name: string;
|
|
169
171
|
icon: string;
|
|
170
172
|
/** 加载类型: internal(内部路由) | microapp(qiankun微应用) */
|
|
@@ -182,6 +184,8 @@ interface PageConfig {
|
|
|
182
184
|
id: number;
|
|
183
185
|
name: string;
|
|
184
186
|
route: string;
|
|
187
|
+
/** 微应用挂载前缀(可与 route 不同) */
|
|
188
|
+
base: string;
|
|
185
189
|
enabled: boolean;
|
|
186
190
|
/** 微应用 HTML 入口 URL (优先使用) */
|
|
187
191
|
htmlUrl: string | null;
|
|
@@ -254,7 +258,8 @@ const renderContent = () => {
|
|
|
254
258
|
<MicroAppLoader
|
|
255
259
|
entry={currentRoute.entry}
|
|
256
260
|
name={currentRoute.name}
|
|
257
|
-
base={currentRoute.
|
|
261
|
+
base={currentRoute.base}
|
|
262
|
+
routePath={currentRoute.path}
|
|
258
263
|
/>
|
|
259
264
|
);
|
|
260
265
|
}
|
|
@@ -138,7 +138,8 @@ export async function getInitialState(): Promise<{
|
|
|
138
138
|
}
|
|
139
139
|
|
|
140
140
|
// 有 token 就获取用户信息(无论在哪个页面,支持登录后 refresh 场景)
|
|
141
|
-
|
|
141
|
+
// 当页面免认证时,不获取用户信息
|
|
142
|
+
if (getStoredAuthToken() && !skipAuth) {
|
|
142
143
|
const userInfo = await fetchUserInfoFn();
|
|
143
144
|
if (userInfo) {
|
|
144
145
|
clearRedirectCount();
|
|
@@ -37,7 +37,13 @@ const intlProxy = new Proxy(intl, {
|
|
|
37
37
|
}
|
|
38
38
|
// 不存在的 key,返回一个兜底函数
|
|
39
39
|
console.warn(`[common-intl] Missing intl key: ${prop}`);
|
|
40
|
-
|
|
40
|
+
// 未预定义的 key:仍从缓存(接口拉取的多语言数据)中查找,支持动态 key
|
|
41
|
+
return (...interpolations: Array<string | number | undefined>) =>
|
|
42
|
+
i18n({
|
|
43
|
+
key: prop,
|
|
44
|
+
interpolations,
|
|
45
|
+
defaultMessage: prop, // 缓存无值时用 key 兜底
|
|
46
|
+
});
|
|
41
47
|
},
|
|
42
48
|
});
|
|
43
49
|
|