generator-mico-cli 0.1.29 → 0.2.2-8.beta.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/README.md +199 -15
- package/bin/mico.js +232 -27
- package/generators/micro-react/index.js +200 -18
- package/generators/micro-react/meta.json +13 -0
- package/generators/micro-react/templates/.commitlintrc.js +1 -0
- package/generators/micro-react/templates/.cursor/rules/always-read-docs.mdc +14 -4
- package/generators/micro-react/templates/.cursor/rules/cicd-deploy.mdc +10 -8
- package/generators/micro-react/templates/.cursor/rules/coding-conventions.mdc +1 -1
- package/generators/micro-react/templates/.cursor/rules/development-guide.mdc +3 -4
- package/generators/micro-react/templates/.cursor/rules/layout-app.mdc +38 -31
- package/generators/micro-react/templates/.cursor/rules/project-overview.mdc +7 -4
- package/generators/micro-react/templates/.cursor/rules/theme-system.mdc +10 -12
- package/generators/micro-react/templates/.eslintrc.js +25 -1
- package/generators/micro-react/templates/AGENTS.md +5 -2
- package/generators/micro-react/templates/CICD/before_build.sh +76 -0
- package/generators/micro-react/templates/CICD/start_dev.sh +27 -3
- package/generators/micro-react/templates/CICD/start_prod.sh +26 -3
- package/generators/micro-react/templates/CICD/start_test.sh +28 -3
- package/generators/micro-react/templates/CICD/wangsu_fresh_dev.sh +4 -4
- package/generators/micro-react/templates/CICD/wangsu_fresh_prod.sh +4 -4
- package/generators/micro-react/templates/CICD/wangsu_fresh_test.sh +4 -4
- package/generators/micro-react/templates/CLAUDE.md +16 -9
- package/generators/micro-react/templates/README.md +42 -4
- package/generators/micro-react/templates/_gitignore +4 -0
- package/generators/micro-react/templates/_npmrc +4 -0
- package/generators/micro-react/templates/apps/layout/config/config.dev.ts +33 -17
- package/generators/micro-react/templates/apps/layout/config/config.prod.development.ts +24 -29
- package/generators/micro-react/templates/apps/layout/config/config.prod.testing.ts +25 -6
- package/generators/micro-react/templates/apps/layout/config/config.prod.ts +16 -7
- package/generators/micro-react/templates/apps/layout/config/config.ts +27 -4
- package/generators/micro-react/templates/apps/layout/config/routes.ts +10 -5
- package/generators/micro-react/templates/apps/layout/docs/arch-/346/227/245/345/277/227/344/270/216/345/270/270/351/207/217.md +2 -2
- package/generators/micro-react/templates/apps/layout/docs/arch-/350/257/267/346/261/202/346/250/241/345/235/227.md +1 -1
- package/generators/micro-react/templates/apps/layout/docs/common-intl.md +372 -0
- 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-404/351/241/265/351/235/242.md +103 -0
- package/generators/micro-react/templates/apps/layout/docs/feature-/344/270/273/351/242/230/350/211/262/345/210/207/346/215/242.md +22 -26
- 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 +185 -28
- package/generators/micro-react/templates/apps/layout/docs/feature-/350/217/234/345/215/225/346/235/203/351/231/220/346/216/247/345/210/266.md +420 -0
- package/generators/micro-react/templates/apps/layout/docs/feature-/350/267/257/347/224/261/344/270/216/350/217/234/345/215/225/350/247/243/350/200/246.md +179 -0
- package/generators/micro-react/templates/apps/layout/docs/fix-SSO/346/227/240/351/231/220/351/207/215/345/256/232/345/220/221.md +88 -0
- package/generators/micro-react/templates/apps/layout/docs/utils-timezone.md +324 -0
- package/generators/micro-react/templates/apps/layout/mock/api.mock.ts +81 -61
- package/generators/micro-react/templates/apps/layout/mock/menus.ts +114 -4
- package/generators/micro-react/templates/apps/layout/mock/pages.ts +86 -0
- package/generators/micro-react/templates/apps/layout/package.json +7 -4
- package/generators/micro-react/templates/apps/layout/src/app.tsx +122 -83
- package/generators/micro-react/templates/apps/layout/src/common/auth/index.ts +3 -0
- package/generators/micro-react/templates/apps/layout/src/common/helpers.ts +177 -0
- package/generators/micro-react/templates/apps/layout/src/common/locale.ts +22 -17
- package/generators/micro-react/templates/apps/layout/src/common/menu/parser.ts +283 -28
- package/generators/micro-react/templates/apps/layout/src/common/menu/types.ts +69 -5
- package/generators/micro-react/templates/apps/layout/src/common/micro/index.ts +34 -0
- package/generators/micro-react/templates/apps/layout/src/common/micro-prefetch.ts +109 -0
- package/generators/micro-react/templates/apps/layout/src/common/portal-data.ts +45 -0
- package/generators/micro-react/templates/apps/layout/src/common/request/config.ts +72 -10
- package/generators/micro-react/templates/apps/layout/src/common/request/index.ts +2 -2
- package/generators/micro-react/templates/apps/layout/src/common/request/interceptors.ts +31 -3
- package/generators/micro-react/templates/apps/layout/src/common/request/sso.ts +29 -11
- package/generators/micro-react/templates/apps/layout/src/common/request/url-resolver.ts +23 -8
- package/generators/micro-react/templates/apps/layout/src/common/route-guard.ts +345 -0
- package/generators/micro-react/templates/apps/layout/src/common/theme.ts +2 -4
- package/generators/micro-react/templates/apps/layout/src/common/upload/oss.ts +3 -4
- package/generators/micro-react/templates/apps/layout/src/common/upload/types.ts +1 -1
- package/generators/micro-react/templates/apps/layout/src/common/uploadFiles.ts +1 -1
- package/generators/micro-react/templates/apps/layout/src/components/AppTabs/index.less +8 -3
- package/generators/micro-react/templates/apps/layout/src/components/AppTabs/index.tsx +25 -8
- package/generators/micro-react/templates/apps/layout/src/components/HeaderDropdown/index.tsx +20 -0
- package/generators/micro-react/templates/apps/layout/src/components/IconFont/index.tsx +5 -6
- package/generators/micro-react/templates/apps/layout/src/components/MicroAppLoader/index.less +21 -6
- package/generators/micro-react/templates/apps/layout/src/components/MicroAppLoader/index.tsx +83 -107
- package/generators/micro-react/templates/apps/layout/src/components/MicroAppLoader/micro-app-manager.ts +569 -0
- package/generators/micro-react/templates/apps/layout/src/components/RightContent/AvatarDropdown.tsx +383 -0
- package/generators/micro-react/templates/apps/layout/src/components/RightContent/avatar-dropdown.less +35 -0
- package/generators/micro-react/templates/apps/layout/src/components/RightContent/index.ts +2 -0
- package/generators/micro-react/templates/apps/layout/src/constants/index.ts +170 -6
- package/generators/micro-react/templates/apps/layout/src/global.less +19 -6
- package/generators/micro-react/templates/apps/layout/src/hooks/useMenu.ts +3 -2
- package/generators/micro-react/templates/apps/layout/src/hooks/useRoutePermissionRefresh.ts +72 -0
- package/generators/micro-react/templates/apps/layout/src/layouts/components/header/index.less +3 -1
- package/generators/micro-react/templates/apps/layout/src/layouts/components/header/index.tsx +10 -55
- package/generators/micro-react/templates/apps/layout/src/layouts/components/menu/index.less +34 -4
- package/generators/micro-react/templates/apps/layout/src/layouts/components/menu/index.tsx +33 -9
- package/generators/micro-react/templates/apps/layout/src/layouts/index.less +84 -13
- package/generators/micro-react/templates/apps/layout/src/layouts/index.tsx +178 -47
- package/generators/micro-react/templates/apps/layout/src/locales/en-US.ts +12 -0
- package/generators/micro-react/templates/apps/layout/src/locales/zh-CN.ts +12 -0
- package/generators/micro-react/templates/apps/layout/src/pages/403/index.tsx +34 -0
- package/generators/micro-react/templates/apps/layout/src/pages/404/index.tsx +78 -0
- package/generators/micro-react/templates/apps/layout/src/pages/Home/index.less +3 -0
- package/generators/micro-react/templates/apps/layout/src/pages/Home/index.tsx +7 -1
- package/generators/micro-react/templates/apps/layout/src/pages/User/Login/index.less +1 -1
- package/generators/micro-react/templates/apps/layout/src/pages/User/Login/index.tsx +9 -5
- package/generators/micro-react/templates/apps/layout/src/requestErrorConfig.ts +1 -1
- package/generators/micro-react/templates/apps/layout/src/services/config/index.ts +63 -0
- package/generators/micro-react/templates/apps/layout/src/services/config/type.ts +30 -0
- package/generators/micro-react/templates/apps/layout/src/services/user.ts +29 -2
- package/generators/micro-react/templates/apps/layout/tailwind.config.js +3 -0
- package/generators/micro-react/templates/deployDesc.md +3 -3
- package/generators/micro-react/templates/dev.preset.json +14 -0
- package/generators/micro-react/templates/docs/dev-preset.md +130 -0
- package/generators/micro-react/templates/package.json +21 -6
- package/generators/micro-react/templates/packages/common-intl/README.md +427 -0
- package/generators/micro-react/templates/packages/common-intl/package.json +34 -0
- package/generators/micro-react/templates/packages/common-intl/src/index.ts +7 -0
- package/generators/micro-react/templates/packages/common-intl/src/indexedDBUtils.ts +51 -0
- package/generators/micro-react/templates/packages/common-intl/src/intl.ts +50 -0
- package/generators/micro-react/templates/packages/common-intl/src/utils.ts +482 -0
- package/generators/micro-react/templates/packages/common-intl/tsconfig.json +22 -0
- package/generators/micro-react/templates/packages/common-intl/vite.config.ts +25 -0
- package/generators/micro-react/templates/scripts/apply-sentry-plugin.ts +45 -0
- package/generators/micro-react/templates/scripts/collect-dist.js +10 -0
- package/generators/micro-react/templates/scripts/dev-preset.js +265 -0
- package/generators/micro-react/templates/scripts/dev-preset.schema.json +39 -0
- package/generators/micro-react/templates/turbo.json +4 -1
- package/generators/subapp-react/index.js +326 -40
- package/generators/subapp-react/meta.json +10 -0
- package/generators/subapp-react/templates/homepage/.env +2 -1
- package/generators/subapp-react/templates/homepage/README.md +3 -3
- package/generators/subapp-react/templates/homepage/config/config.dev.ts +14 -7
- package/generators/subapp-react/templates/homepage/config/config.prod.development.ts +16 -5
- package/generators/subapp-react/templates/homepage/config/config.prod.testing.ts +16 -5
- package/generators/subapp-react/templates/homepage/config/config.prod.ts +14 -5
- package/generators/subapp-react/templates/homepage/config/config.ts +27 -0
- package/generators/subapp-react/templates/homepage/config/routes.ts +2 -2
- package/generators/subapp-react/templates/homepage/mock/api.mock.ts +2 -2
- package/generators/subapp-react/templates/homepage/package.json +7 -4
- package/generators/subapp-react/templates/homepage/src/app.tsx +18 -27
- package/generators/subapp-react/templates/homepage/src/common/request.ts +29 -2
- package/generators/subapp-react/templates/homepage/src/global.less +6 -5
- package/generators/subapp-react/templates/homepage/src/pages/index.less +3 -3
- package/generators/subapp-react/templates/homepage/src/pages/index.tsx +99 -60
- package/generators/subapp-react/templates/homepage/src/styles/theme.less +1 -1
- package/generators/subapp-umd/ignore-list.json +5 -0
- package/generators/subapp-umd/index.js +309 -0
- package/generators/subapp-umd/meta.json +11 -0
- package/generators/subapp-umd/templates/README.md +94 -0
- package/generators/subapp-umd/templates/package.json +35 -0
- package/generators/subapp-umd/templates/public/index.html +34 -0
- package/generators/subapp-umd/templates/src/App.less +15 -0
- package/generators/subapp-umd/templates/src/App.tsx +13 -0
- package/generators/subapp-umd/templates/src/index.ts +2 -0
- package/generators/subapp-umd/templates/tsconfig.json +27 -0
- package/generators/subapp-umd/templates/webpack.config.js +70 -0
- package/lib/utils.js +332 -2
- package/package.json +15 -2
- package/generators/micro-react/templates/apps/layout/mock/menus.json +0 -100
- package/generators/micro-react/templates/apps/layout/src/common/constants.ts +0 -38
- package/generators/micro-react/templates/apps/layout/src/components/MicroAppLoader/container-manager.ts +0 -202
- package/generators/micro-react/templates/packages/shared-styles/README.md +0 -124
- package/generators/micro-react/templates/packages/shared-styles/arco-design-mobile-override.less +0 -91
- package/generators/micro-react/templates/packages/shared-styles/arco-override.less +0 -119
- package/generators/micro-react/templates/packages/shared-styles/index.d.ts +0 -44
- package/generators/micro-react/templates/packages/shared-styles/index.less +0 -13
- package/generators/micro-react/templates/packages/shared-styles/package.json +0 -30
- package/generators/micro-react/templates/packages/shared-styles/theme-inject.less +0 -10
- package/generators/micro-react/templates/packages/shared-styles/themes/dark/custom-var.less +0 -290
- package/generators/micro-react/templates/packages/shared-styles/themes/normal/custom-var.less +0 -269
- package/generators/micro-react/templates/packages/shared-styles/variables-only.less +0 -433
- package/generators/micro-react/templates/packages/shared-styles/variables.less +0 -452
|
@@ -55,6 +55,6 @@ git 地址: https://gitlab.example.com/your-org/<%= projectName %>
|
|
|
55
55
|
|
|
56
56
|
# 三、CDN路径示例
|
|
57
57
|
|
|
58
|
-
- 开发环境域名:cdn-portal-dev.micoplatform.com/<%= projectName %>/{version}/{app}
|
|
59
|
-
- 测试环境域名:cdn-portal-test.micoplatform.com/<%= projectName %>/{version}/{app}
|
|
60
|
-
- 正式环境域名:cdn-portal.micoplatform.com/<%= projectName %>/{version}/{app}
|
|
58
|
+
- 开发环境域名:cdn-portal-dev.micoplatform.com/<%= cdnPrefixPath %><%= projectName %>/{version}/{app}
|
|
59
|
+
- 测试环境域名:cdn-portal-test.micoplatform.com/<%= cdnPrefixPath %><%= projectName %>/{version}/{app}
|
|
60
|
+
- 正式环境域名:cdn-portal.micoplatform.com/<%= cdnPrefixPath %><%= projectName %>/{version}/{app}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# 多应用并行启动 (dev:preset)
|
|
2
|
+
|
|
3
|
+
## 功能概述
|
|
4
|
+
|
|
5
|
+
通过配置文件 `dev.preset.json` 定义多个启动预设,一条命令并行启动多个应用的开发服务器,适用于需要同时调试多个微前端子应用的场景。
|
|
6
|
+
|
|
7
|
+
## 快速使用
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
# 使用默认预设启动
|
|
11
|
+
pnpm dev:preset
|
|
12
|
+
|
|
13
|
+
# 使用指定预设
|
|
14
|
+
pnpm dev:preset full
|
|
15
|
+
|
|
16
|
+
# 查看所有预设
|
|
17
|
+
pnpm list:preset
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## 配置文件
|
|
21
|
+
|
|
22
|
+
配置文件位于项目根目录 `dev.preset.json`:
|
|
23
|
+
|
|
24
|
+
```json
|
|
25
|
+
{
|
|
26
|
+
"$schema": "./scripts/dev-preset.schema.json",
|
|
27
|
+
"presets": {
|
|
28
|
+
"full": {
|
|
29
|
+
"description": "启动所有应用",
|
|
30
|
+
"apps": ["layout", "subapp"]
|
|
31
|
+
},
|
|
32
|
+
"minimal": {
|
|
33
|
+
"description": "最小化启动(仅主应用)",
|
|
34
|
+
"apps": ["layout"]
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"default": "minimal"
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### 配置项说明
|
|
42
|
+
|
|
43
|
+
| 字段 | 类型 | 说明 |
|
|
44
|
+
|------|------|------|
|
|
45
|
+
| `$schema` | string | JSON Schema 引用,提供编辑器智能提示 |
|
|
46
|
+
| `presets` | object | 预设配置,key 为预设名称 |
|
|
47
|
+
| `presets.<name>.description` | string | 预设描述(可选) |
|
|
48
|
+
| `presets.<name>.apps` | string[] | 要启动的应用列表 |
|
|
49
|
+
| `default` | string | 默认使用的预设名称 |
|
|
50
|
+
|
|
51
|
+
## 命令参数
|
|
52
|
+
|
|
53
|
+
| 命令 | 说明 |
|
|
54
|
+
|------|------|
|
|
55
|
+
| `pnpm dev:preset` | 使用 `default` 指定的预设启动 |
|
|
56
|
+
| `pnpm dev:preset <name>` | 使用指定预设启动 |
|
|
57
|
+
| `pnpm dev:preset --list` | 列出所有可用预设 |
|
|
58
|
+
| `pnpm dev:preset --config` | 输出配置文件路径 |
|
|
59
|
+
| `pnpm list:preset` | `--list` 的快捷方式 |
|
|
60
|
+
|
|
61
|
+
## 功能特性
|
|
62
|
+
|
|
63
|
+
### 1. 并行启动
|
|
64
|
+
|
|
65
|
+
所有应用同时启动,无需手动打开多个 Terminal。
|
|
66
|
+
|
|
67
|
+
### 2. 日志区分
|
|
68
|
+
|
|
69
|
+
每个应用的日志输出带有彩色前缀,便于区分来源:
|
|
70
|
+
|
|
71
|
+
```
|
|
72
|
+
[layout] info - Umi @ 4.x
|
|
73
|
+
[subapp] info - Umi @ 4.x
|
|
74
|
+
[layout] ready - Local: http://localhost:8000
|
|
75
|
+
[subapp] ready - Local: http://localhost:8001
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### 3. 统一终止
|
|
79
|
+
|
|
80
|
+
按 `Ctrl+C` 会同时停止所有正在运行的应用。
|
|
81
|
+
|
|
82
|
+
### 4. 预设验证
|
|
83
|
+
|
|
84
|
+
启动前自动验证:
|
|
85
|
+
- 预设是否存在
|
|
86
|
+
- 应用是否存在
|
|
87
|
+
- 应用是否有 `dev` 脚本
|
|
88
|
+
|
|
89
|
+
### 5. 编辑器智能提示
|
|
90
|
+
|
|
91
|
+
配置文件引用了 JSON Schema,支持:
|
|
92
|
+
- 字段自动补全
|
|
93
|
+
- 类型校验
|
|
94
|
+
- 悬停提示
|
|
95
|
+
|
|
96
|
+
## 文件清单
|
|
97
|
+
|
|
98
|
+
| 文件路径 | 说明 |
|
|
99
|
+
|------|------|
|
|
100
|
+
| `dev.preset.json` | 预设配置文件 |
|
|
101
|
+
| `scripts/dev-preset.js` | 启动脚本 |
|
|
102
|
+
| `scripts/dev-preset.schema.json` | JSON Schema |
|
|
103
|
+
|
|
104
|
+
## 自定义预设
|
|
105
|
+
|
|
106
|
+
根据开发需求添加自定义预设:
|
|
107
|
+
|
|
108
|
+
```json
|
|
109
|
+
{
|
|
110
|
+
"presets": {
|
|
111
|
+
"my-preset": {
|
|
112
|
+
"description": "自定义组合",
|
|
113
|
+
"apps": ["layout", "subapp-a", "subapp-b"]
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
然后使用:
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
pnpm dev:preset my-preset
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## 注意事项
|
|
126
|
+
|
|
127
|
+
- 应用名称必须与 `apps/` 目录下的文件夹名称一致
|
|
128
|
+
- 应用必须在 `package.json` 中定义 `dev` 脚本
|
|
129
|
+
- 端口冲突需在各应用配置中自行处理
|
|
130
|
+
- 日志输出为合并流,适合快速调试;复杂调试建议使用多 Terminal 方式
|
|
@@ -6,30 +6,45 @@
|
|
|
6
6
|
"pnpm": {
|
|
7
7
|
"overrides": {
|
|
8
8
|
"@types/react": "^18.3.26",
|
|
9
|
-
"@types/react-dom": "^18.3.7"
|
|
9
|
+
"@types/react-dom": "^18.3.7",
|
|
10
|
+
"@mico-platform/hooks": "^0.0.1",
|
|
11
|
+
"@mico-platform/utils": "^0.0.1"
|
|
10
12
|
}
|
|
11
13
|
},
|
|
12
14
|
"scripts": {
|
|
13
15
|
"dev": "node scripts/dev.js",
|
|
16
|
+
"dev:preset": "node scripts/dev-preset.js",
|
|
17
|
+
"list:preset": "node scripts/dev-preset.js --list",
|
|
14
18
|
"build": "dotenv -e .env -e .env.local -e .env.production -e .env.production.local -- turbo run build && node scripts/collect-dist.js",
|
|
15
|
-
"build:development": "dotenv -e .env -e .env.local -e .env.development -e .env.development.local -- turbo run build:development && node scripts/collect-dist.js",
|
|
16
|
-
"build:testing": "dotenv -e .env -e .env.local -e .env.testing -e .env.testing.local -- turbo run build:testing && node scripts/collect-dist.js",
|
|
17
|
-
"build:production": "dotenv -e .env -e .env.local -e .env.production -e .env.production.local -- turbo run build:production && node scripts/collect-dist.js",
|
|
19
|
+
"build:development": "dotenv -e .env -e .env.local -e .env.development -e .env.development.local -- turbo run build:development ${TURBO_FILTER:+--filter=${TURBO_FILTER}} && node scripts/collect-dist.js",
|
|
20
|
+
"build:testing": "dotenv -e .env -e .env.local -e .env.testing -e .env.testing.local -- turbo run build:testing ${TURBO_FILTER:+--filter=${TURBO_FILTER}} && node scripts/collect-dist.js",
|
|
21
|
+
"build:production": "dotenv -e .env -e .env.local -e .env.production -e .env.production.local -- turbo run build:production ${TURBO_FILTER:+--filter=${TURBO_FILTER}} && node scripts/collect-dist.js",
|
|
18
22
|
"build:local": "dotenv -e .env -e .env.local -- turbo run build:local && node scripts/collect-dist.js",
|
|
19
23
|
"lint": "eslint . --ext .js,.jsx,.ts,.tsx && turbo run lint",
|
|
20
24
|
"lint:fix": "eslint . --ext .js,.jsx,.ts,.tsx --fix && turbo run lint:fix",
|
|
25
|
+
"check-types": "turbo run check-types",
|
|
21
26
|
"lint-staged": "pnpm exec lint-staged --quiet",
|
|
22
|
-
"prepare": "husky
|
|
27
|
+
"prepare": "husky",
|
|
23
28
|
"test": "dotenv -e .env -e .env.local -- turbo run test",
|
|
24
|
-
"create:umi-app": "./scripts/create-umi-app.sh"
|
|
29
|
+
"create:umi-app": "./scripts/create-umi-app.sh",
|
|
30
|
+
"upgrade:mico": "npx @mico-platform/mico-up"
|
|
25
31
|
},
|
|
26
32
|
"devDependencies": {
|
|
27
33
|
"@commitlint/cli": "^19.5.0",
|
|
28
34
|
"@commitlint/config-conventional": "^19.5.0",
|
|
35
|
+
"@common-web/sentry": "^0.0.4",
|
|
36
|
+
"@sentry/webpack-plugin": "^4.9.1",
|
|
37
|
+
"@typescript-eslint/eslint-plugin": "^8.54.0",
|
|
38
|
+
"@typescript-eslint/parser": "^8.54.0",
|
|
29
39
|
"dotenv-cli": "^7.4.1",
|
|
30
40
|
"eslint": "^8.57.0",
|
|
31
41
|
"husky": "^9.1.7",
|
|
32
42
|
"lint-staged": "^16.1.2",
|
|
33
43
|
"turbo": "^2.5.8"
|
|
44
|
+
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"@types/lodash-es": "^4.17.12",
|
|
47
|
+
"classnames": "^2.5.1",
|
|
48
|
+
"lodash-es": "^4.17.23"
|
|
34
49
|
}
|
|
35
50
|
}
|
|
@@ -0,0 +1,427 @@
|
|
|
1
|
+
# <%= packageScope %>/common-intl
|
|
2
|
+
|
|
3
|
+
通用国际化(i18n)库,用于 Portal 多应用间的多语言文案管理。
|
|
4
|
+
|
|
5
|
+
## 功能特性
|
|
6
|
+
|
|
7
|
+
- **跨端兼容**:不内置 UI 提示能力,通过外部注入 `messageInstance` 实现跨平台兼容
|
|
8
|
+
- **缓存机制**:支持 IndexedDB 持久化存储 + 内存缓存双重保障
|
|
9
|
+
- **插值替换**:支持 `%AA%`、`%BB%` 等占位符的动态替换
|
|
10
|
+
- **降级处理**:当翻译 key 不存在时,自动返回兜底文案
|
|
11
|
+
- **环境感知**:自动根据 `NODE_ENV` 切换开发/生产 API 地址
|
|
12
|
+
- **微前端共享**:主应用获取的文案数据自动共享给所有子应用
|
|
13
|
+
|
|
14
|
+
## 安装
|
|
15
|
+
|
|
16
|
+
在 monorepo 项目中,通过 workspace 引用:
|
|
17
|
+
|
|
18
|
+
```json
|
|
19
|
+
{
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"<%= packageScope %>/common-intl": "workspace:*"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## 两种使用模式
|
|
27
|
+
|
|
28
|
+
根据应用架构的不同,`<%= packageScope %>/common-intl` 支持两种使用模式:
|
|
29
|
+
|
|
30
|
+
| 模式 | 适用场景 | 示例应用 |
|
|
31
|
+
| ------------ | ------------------------------------------------ | ------------------------------------------------------------ |
|
|
32
|
+
| 微前端模式 | qiankun 主子应用架构,主应用获取文案后子应用共享 | layout、conversation-v2、session、workorder、faq、permission |
|
|
33
|
+
| 独立应用模式 | 独立运行的应用,自己获取和管理文案 | mico-cs-mobile |
|
|
34
|
+
|
|
35
|
+
### 微前端模式
|
|
36
|
+
|
|
37
|
+
在 qiankun 微前端架构中,**主应用负责获取文案**,子应用直接使用共享的文案对象,无需重复初始化。
|
|
38
|
+
|
|
39
|
+
**工作原理**:
|
|
40
|
+
|
|
41
|
+
- 主应用调用 `initIntl()` 获取远程文案
|
|
42
|
+
- 文案数据存储到 `window.__MICO_COMMON_INTL_TRANSLATIONS__`
|
|
43
|
+
- 子应用直接使用 `intl` 对象,自动从 window 读取共享数据
|
|
44
|
+
|
|
45
|
+
**主应用配置**(参考 `apps/layout/src/app.tsx`):
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
import {
|
|
49
|
+
getCurrentLocale,
|
|
50
|
+
initIntl,
|
|
51
|
+
type ILang,
|
|
52
|
+
} from "<%= packageScope %>/common-intl";
|
|
53
|
+
import { Message } from "@mico-platform/ui";
|
|
54
|
+
import { request } from "@umijs/max";
|
|
55
|
+
|
|
56
|
+
// 初始化国际化模块
|
|
57
|
+
const fetchMultilingualData = initIntl({
|
|
58
|
+
requestInstance: request,
|
|
59
|
+
messageInstance: {
|
|
60
|
+
error: (msg: string) => Message.error(msg),
|
|
61
|
+
warning: (msg: string) => Message.warning(msg),
|
|
62
|
+
},
|
|
63
|
+
fetchMultilingualDataParams: {
|
|
64
|
+
tag: "cs_fe_pc",
|
|
65
|
+
lang: getCurrentLocale() as ILang,
|
|
66
|
+
app_name: "middle",
|
|
67
|
+
},
|
|
68
|
+
indexedDBParams: {
|
|
69
|
+
dbName: "mico_cs_web_i18n_db",
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
// 在应用渲染前加载多语言数据
|
|
74
|
+
export function render(oldRender: () => void): void {
|
|
75
|
+
fetchMultilingualData()
|
|
76
|
+
.then(oldRender)
|
|
77
|
+
.catch((error: Error) => {
|
|
78
|
+
console.error("获取多语言文案失败", error);
|
|
79
|
+
oldRender(); // 失败时继续渲染,使用兜底文案
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
**子应用使用**(无需初始化):
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
// apps/conversation-v2、apps/session、apps/workorder 等子应用
|
|
88
|
+
import { intl } from "<%= packageScope %>/common-intl";
|
|
89
|
+
|
|
90
|
+
// 直接使用,文案来自主应用
|
|
91
|
+
<h1>{intl.cs_web_workbench_conversation_record()}</h1>;
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### 独立应用模式
|
|
95
|
+
|
|
96
|
+
对于非 qiankun 架构的独立应用(如 H5 应用),需要自己调用 `initIntl()` 获取文案,并维护独立的文案文件。
|
|
97
|
+
|
|
98
|
+
**独立应用配置**(参考 `apps/mico-cs-mobile/src/app.ts`):
|
|
99
|
+
|
|
100
|
+
```typescript
|
|
101
|
+
import { initIntl } from "<%= packageScope %>/common-intl";
|
|
102
|
+
import { request } from "@umijs/max";
|
|
103
|
+
import { convertLocaleToLangParam } from "./locales/utils";
|
|
104
|
+
import { getSearchParams } from "@/common/jsbridge/jsbridge";
|
|
105
|
+
|
|
106
|
+
// 初始化国际化模块
|
|
107
|
+
const fetchMultilingualData = initIntl({
|
|
108
|
+
// 请求实例(必填)
|
|
109
|
+
requestInstance: request,
|
|
110
|
+
// 消息提示实例(必填)
|
|
111
|
+
messageInstance: {
|
|
112
|
+
error: (msg: string) => console.error(msg),
|
|
113
|
+
warning: (msg: string) => console.warn(msg),
|
|
114
|
+
},
|
|
115
|
+
// 多语言中台接口参数(必填)
|
|
116
|
+
fetchMultilingualDataParams: {
|
|
117
|
+
tag: 'cs_fe_mobile', // 多语言标签,参考翻译中台-文案管理列表页-Tags 表格列 https://lang-test.micoplatform.com/lang/#/langs
|
|
118
|
+
lang: convertLocaleToLangParam(getSearchParams().language as string),
|
|
119
|
+
app_name: 'middle', // 应用名称,参考翻译中台左上角 https://lang-test.micoplatform.com/lang/#/langs
|
|
120
|
+
},
|
|
121
|
+
// IndexedDB 参数(可选)
|
|
122
|
+
indexedDBParams: {
|
|
123
|
+
dbName: 'mico_cs_mobile_i18n_db',
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
// 在应用渲染前加载多语言数据
|
|
128
|
+
// 如果是基于 umi 的项目,可以在 app.tsx 的 render 函数中调用加载函数 https://umijs.org/docs/api/runtime-config#render
|
|
129
|
+
export function render(oldRender: () => void): void {
|
|
130
|
+
fetchMultilingualData()
|
|
131
|
+
.then(oldRender)
|
|
132
|
+
.catch((error: Error) => {
|
|
133
|
+
console.error('获取多语言文案失败', error);
|
|
134
|
+
// 即使失败也继续渲染,使用兜底文案
|
|
135
|
+
oldRender();
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
**独立应用的文案文件**(`apps/mico-cs-mobile/src/locales/index.ts`):集中管理所有国际化文案
|
|
141
|
+
|
|
142
|
+
```typescript
|
|
143
|
+
import { i18n } from "<%= packageScope %>/common-intl";
|
|
144
|
+
|
|
145
|
+
const intl = {
|
|
146
|
+
// 无插值示例
|
|
147
|
+
sdk_h5_ticket_record: () =>
|
|
148
|
+
i18n({
|
|
149
|
+
key: 'sdk_h5_ticket_record',
|
|
150
|
+
defaultMessage: '工单记录',
|
|
151
|
+
}),
|
|
152
|
+
|
|
153
|
+
// 单个插值示例
|
|
154
|
+
sdk_h5_common_request_failed_aa: (code: string | number) =>
|
|
155
|
+
i18n({
|
|
156
|
+
key: 'sdk_h5_common_request_failed_aa',
|
|
157
|
+
interpolations: [code],
|
|
158
|
+
defaultMessage: `请求失败 (${code})`,
|
|
159
|
+
}),
|
|
160
|
+
|
|
161
|
+
// 多个插值示例
|
|
162
|
+
sdk_h5_common_upload_failed_status_aa_bb: (
|
|
163
|
+
statusCode: string | number,
|
|
164
|
+
responseText: string,
|
|
165
|
+
) =>
|
|
166
|
+
i18n({
|
|
167
|
+
key: 'sdk_h5_common_upload_failed_status_aa_bb',
|
|
168
|
+
interpolations: [statusCode, responseText],
|
|
169
|
+
defaultMessage: `上传失败,状态码 ${statusCode}${responseText}`,
|
|
170
|
+
}),
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
export default intl;
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
**在组件中使用**:
|
|
177
|
+
|
|
178
|
+
```tsx
|
|
179
|
+
import intl from '@/locales';
|
|
180
|
+
|
|
181
|
+
function MyComponent() {
|
|
182
|
+
return (
|
|
183
|
+
<div>
|
|
184
|
+
<h1>{intl.sdk_h5_ticket_record()}</h1>
|
|
185
|
+
<p>{intl.sdk_h5_common_request_failed_aa(404)}</p>
|
|
186
|
+
</div>
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
## API 参考
|
|
192
|
+
|
|
193
|
+
### `initIntl(params: IInitIntlParams)`
|
|
194
|
+
|
|
195
|
+
初始化国际化模块,返回 `fetchMultilingualData` 函数。
|
|
196
|
+
|
|
197
|
+
#### 参数
|
|
198
|
+
|
|
199
|
+
| 参数 | 类型 | 必填 | 说明 |
|
|
200
|
+
| -------------------------------------- | ------------------ | ---- | -------------------------------------------- |
|
|
201
|
+
| `requestInstance` | `Function` | ✅ | HTTP 请求函数,用于请求多语言中台接口 |
|
|
202
|
+
| `messageInstance` | `IMessageInstance` | ✅ | 消息提示实例,包含 `error` 和 `warning` 方法 |
|
|
203
|
+
| `fetchMultilingualDataParams` | `Object` | ✅ | 多语言接口参数 |
|
|
204
|
+
| `fetchMultilingualDataParams.tag` | `string` | ✅ | 多语言标签 |
|
|
205
|
+
| `fetchMultilingualDataParams.lang` | `ILang` | ✅ | 语言类型 |
|
|
206
|
+
| `fetchMultilingualDataParams.app_name` | `string` | ✅ | 应用名称 |
|
|
207
|
+
| `indexedDBParams` | `Object` | ❌ | IndexedDB 配置参数 |
|
|
208
|
+
|
|
209
|
+
#### 返回值
|
|
210
|
+
|
|
211
|
+
返回 `fetchMultilingualData(): Promise<Record<string, string>>` 函数,调用后会:
|
|
212
|
+
|
|
213
|
+
1. 从多语言中台拉取翻译数据
|
|
214
|
+
2. 将数据存储到 IndexedDB 和全局变量缓存(`window.__MICO_COMMON_INTL_TRANSLATIONS__`)
|
|
215
|
+
3. 返回翻译数据对象
|
|
216
|
+
|
|
217
|
+
### `i18n(params: II18nParams)`
|
|
218
|
+
|
|
219
|
+
国际化翻译函数,同步返回翻译后的文案。
|
|
220
|
+
|
|
221
|
+
#### 参数
|
|
222
|
+
|
|
223
|
+
| 参数 | 类型 | 必填 | 说明 |
|
|
224
|
+
| ---------------- | ------------------------- | ---- | -------------------------------------------- |
|
|
225
|
+
| `key` | `string` | ✅ | 翻译文案的 key |
|
|
226
|
+
| `interpolations` | `Array<string \| number>` | ❌ | 插值数组,按顺序替换 `%AA%`、`%BB%` 等占位符 |
|
|
227
|
+
| `defaultMessage` | `string` | ✅ | 兜底文案,当找不到翻译时返回 |
|
|
228
|
+
|
|
229
|
+
#### 返回值
|
|
230
|
+
|
|
231
|
+
返回翻译后的字符串。
|
|
232
|
+
|
|
233
|
+
### `getCurrentLocale()`
|
|
234
|
+
|
|
235
|
+
获取当前语言环境,按优先级从高到低:
|
|
236
|
+
|
|
237
|
+
1. URL 参数 `lang`
|
|
238
|
+
2. localStorage 中的 `umi_locale`
|
|
239
|
+
3. 浏览器默认语言
|
|
240
|
+
|
|
241
|
+
#### 返回值
|
|
242
|
+
|
|
243
|
+
返回当前语言类型 `ILang`。
|
|
244
|
+
|
|
245
|
+
### `setLocaleToStorage(locale: ILang)`
|
|
246
|
+
|
|
247
|
+
将语言设置保存到 localStorage。
|
|
248
|
+
|
|
249
|
+
### `LANG`
|
|
250
|
+
|
|
251
|
+
支持的语言常量对象:
|
|
252
|
+
|
|
253
|
+
```typescript
|
|
254
|
+
const LANG = {
|
|
255
|
+
ZH_CN: "zh_CN", // 简体中文
|
|
256
|
+
EN: "en", // 英语
|
|
257
|
+
AR: "ar", // 阿拉伯语
|
|
258
|
+
TR: "tr", // 土耳其语
|
|
259
|
+
} as const;
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
### `LOCALE`
|
|
263
|
+
|
|
264
|
+
`LANG` 的别名,用于兼容现有代码。
|
|
265
|
+
|
|
266
|
+
### `SUPPORTED_LOCALES`
|
|
267
|
+
|
|
268
|
+
支持的语言列表数组:`['zh_CN', 'en', 'ar', 'tr']`
|
|
269
|
+
|
|
270
|
+
### 类型定义
|
|
271
|
+
|
|
272
|
+
```typescript
|
|
273
|
+
// 语言类型
|
|
274
|
+
type ILang = "zh_CN" | "en" | "ar" | "tr";
|
|
275
|
+
|
|
276
|
+
// TLocale 是 ILang 的别名,用于兼容
|
|
277
|
+
type TLocale = ILang;
|
|
278
|
+
|
|
279
|
+
// 消息提示实例接口
|
|
280
|
+
interface IMessageInstance {
|
|
281
|
+
error: (message: string) => unknown;
|
|
282
|
+
warning: (message: string) => unknown;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// 初始化参数接口
|
|
286
|
+
interface IInitIntlParams {
|
|
287
|
+
requestInstance: (
|
|
288
|
+
url: string,
|
|
289
|
+
options: { method: string; params: Record<string, string> }
|
|
290
|
+
) => Promise<{
|
|
291
|
+
code: number;
|
|
292
|
+
data?: Record<string, string>;
|
|
293
|
+
errorMessage?: string;
|
|
294
|
+
}>;
|
|
295
|
+
messageInstance: IMessageInstance;
|
|
296
|
+
fetchMultilingualDataParams: {
|
|
297
|
+
tag: string;
|
|
298
|
+
lang: ILang;
|
|
299
|
+
app_name: string;
|
|
300
|
+
};
|
|
301
|
+
indexedDBParams?: {
|
|
302
|
+
dbName?: string;
|
|
303
|
+
dbVersion?: number;
|
|
304
|
+
storeName?: string;
|
|
305
|
+
keyPathKey?: string;
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// i18n 函数参数接口
|
|
310
|
+
interface II18nParams {
|
|
311
|
+
key: string;
|
|
312
|
+
interpolations?: Array<string | number | undefined>;
|
|
313
|
+
defaultMessage: string;
|
|
314
|
+
}
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
## 导出清单
|
|
318
|
+
|
|
319
|
+
| 导出 | 类型 | 说明 |
|
|
320
|
+
| -------------------- | ---- | --------------------------------------------------------- |
|
|
321
|
+
| `initIntl` | 函数 | 初始化国际化模块,返回 `fetchMultilingualData` 函数 |
|
|
322
|
+
| `i18n` | 函数 | 翻译函数,用于获取单条翻译文案 |
|
|
323
|
+
| `intl` | 对象 | PC 端主子应用共享的文案对象(仅供 layout 及其子应用使用) |
|
|
324
|
+
| `LANG` | 常量 | 支持的语言常量:`ZH_CN`、`EN`、`AR`、`TR` |
|
|
325
|
+
| `LOCALE` | 常量 | `LANG` 的别名,用于兼容 |
|
|
326
|
+
| `SUPPORTED_LOCALES` | 常量 | 支持的语言列表数组 |
|
|
327
|
+
| `getCurrentLocale` | 函数 | 获取当前语言环境(按优先级:URL > localStorage > 浏览器) |
|
|
328
|
+
| `setLocaleToStorage` | 函数 | 设置语言到 localStorage |
|
|
329
|
+
| `ILang` | 类型 | 语言类型定义 |
|
|
330
|
+
| `TLocale` | 类型 | `ILang` 的别名,用于兼容 |
|
|
331
|
+
|
|
332
|
+
## 占位符规则
|
|
333
|
+
|
|
334
|
+
翻译文案中的占位符使用大写字母对表示:
|
|
335
|
+
|
|
336
|
+
| 占位符 | 对应 interpolations 索引 |
|
|
337
|
+
| ------ | ------------------------ |
|
|
338
|
+
| `%AA%` | `interpolations[0]` |
|
|
339
|
+
| `%BB%` | `interpolations[1]` |
|
|
340
|
+
| `%CC%` | `interpolations[2]` |
|
|
341
|
+
| ... | ... |
|
|
342
|
+
| `%ZZ%` | `interpolations[25]` |
|
|
343
|
+
|
|
344
|
+
### 示例
|
|
345
|
+
|
|
346
|
+
```typescript
|
|
347
|
+
// 翻译文案: "共 %AA% 条记录,第 %BB% 页"
|
|
348
|
+
i18n({
|
|
349
|
+
key: "pagination_info",
|
|
350
|
+
interpolations: [100, 1],
|
|
351
|
+
defaultMessage: `共 100 条记录,第 1 页`,
|
|
352
|
+
});
|
|
353
|
+
// 输出: "共 100 条记录,第 1 页"
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
## 缓存策略
|
|
357
|
+
|
|
358
|
+
1. **内存缓存**:翻译数据首先存储在 `window.__MICO_COMMON_INTL_TRANSLATIONS__` 全局变量中,保证 `i18n()` 函数的同步调用,同时支持微前端主子应用间的数据共享
|
|
359
|
+
2. **IndexedDB 缓存**:同时持久化到 IndexedDB,支持离线访问和页面刷新后的快速加载
|
|
360
|
+
3. **降级处理**:当 IndexedDB 不可用时(如某些 WebView 环境),仅使用内存缓存
|
|
361
|
+
|
|
362
|
+
## 添加新翻译
|
|
363
|
+
|
|
364
|
+
1. 在 `src/intl.ts` 中添加新的 key:
|
|
365
|
+
|
|
366
|
+
```typescript
|
|
367
|
+
const intl = {
|
|
368
|
+
// ... 其他 keys ...
|
|
369
|
+
|
|
370
|
+
// 新增的 key(无参数)
|
|
371
|
+
cs_web_your_new_key: () =>
|
|
372
|
+
i18n({
|
|
373
|
+
key: "cs_web_your_new_key",
|
|
374
|
+
defaultMessage: "你的新文案",
|
|
375
|
+
}),
|
|
376
|
+
|
|
377
|
+
// 带参数的 key(单个参数)
|
|
378
|
+
cs_web_your_new_key_aa: (param: string | number) =>
|
|
379
|
+
i18n({
|
|
380
|
+
key: "cs_web_your_new_key_aa",
|
|
381
|
+
interpolations: [param],
|
|
382
|
+
defaultMessage: `你的新文案 ${param}`,
|
|
383
|
+
}),
|
|
384
|
+
|
|
385
|
+
// 带参数的 key(多个参数)
|
|
386
|
+
cs_web_your_new_key_multi: (a: string | number, b: string | number) =>
|
|
387
|
+
i18n({
|
|
388
|
+
key: "cs_web_your_new_key_multi",
|
|
389
|
+
interpolations: [a, b],
|
|
390
|
+
defaultMessage: `参数A: ${a},参数B: ${b}`,
|
|
391
|
+
}),
|
|
392
|
+
};
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
2. 在业务代码中使用:
|
|
396
|
+
|
|
397
|
+
```typescript
|
|
398
|
+
import { intl } from "<%= packageScope %>/common-intl";
|
|
399
|
+
|
|
400
|
+
// 使用新 key
|
|
401
|
+
intl.cs_web_your_new_key();
|
|
402
|
+
intl.cs_web_your_new_key_aa("参数值");
|
|
403
|
+
intl.cs_web_your_new_key_multi("值A", "值B");
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
3. 把 key 和兜底文案 defaultMessage 添加到 https://micoworld.feishu.cn/wiki/Ak4pwBl86ixhXyk39bKcgQbknTf?sheet=MzAybi ,并上传到翻译中台
|
|
407
|
+
|
|
408
|
+
## 开发命令
|
|
409
|
+
|
|
410
|
+
```bash
|
|
411
|
+
# 开发模式(监听文件变化)
|
|
412
|
+
pnpm dev
|
|
413
|
+
|
|
414
|
+
# 构建
|
|
415
|
+
pnpm build
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
## 注意事项
|
|
419
|
+
|
|
420
|
+
本项目暂时没有独立发包。各个业务应用 (/apps/\*) 通过 pnpm workspace 引入本项目,可参考 [/apps/mico-cs-mobile](../../apps/mico-cs-mobile/package.json)。原因:本项目代码量较少,暂时由各个业务应用各自把本项目打包到产物中,后续有必要时再优化。
|
|
421
|
+
|
|
422
|
+
1. **不要直接调用 `i18n` 函数**:应通过 `intl.xxx()` 方式调用
|
|
423
|
+
2. **参数类型**:插值参数支持 `string | number | undefined`。无插值时,`interpolations` 参数可以不传
|
|
424
|
+
3. **默认文案**:每个 key 都需要提供 `defaultMessage` 作为后备
|
|
425
|
+
4. **TypeScript 支持**:`intl` 对象有完整的类型提示
|
|
426
|
+
5. **同步调用**:`i18n` 函数是同步的,从全局变量缓存读取数据,因此必须确保在 `fetchMultilingualData()` 完成后才能使用
|
|
427
|
+
6. **离线支持**:即使网络请求失败,也会尝试从 IndexedDB 读取历史缓存,保证基本可用性
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "<%= packageScope %>/common-intl",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Portal common internationalization library",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./src/index.ts",
|
|
12
|
+
"types": "./src/index.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"src"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"dev": "vite build --watch",
|
|
21
|
+
"build": "vite build && tsc --emitDeclarationOnly"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"typescript": "^5.8.3",
|
|
25
|
+
"vite": "^7.2.4",
|
|
26
|
+
"vite-plugin-dts": "^4.5.4"
|
|
27
|
+
},
|
|
28
|
+
"keywords": [
|
|
29
|
+
"i18n",
|
|
30
|
+
"intl",
|
|
31
|
+
"internationalization",
|
|
32
|
+
"mico"
|
|
33
|
+
]
|
|
34
|
+
}
|