@dd-code/uni-tools 1.0.15 → 1.0.16
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 +10 -24
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
## 特性
|
|
6
6
|
- 主/子应用模块化:主应用负责壳与公共能力,子应用以分包形式接入。
|
|
7
7
|
- 配置自动合并:自动汇总各子应用的 `pages.json` 并生成最终 `app.json`。
|
|
8
|
-
-
|
|
8
|
+
- 开发态联调:监听子应用构建输出并同步至主应用分包目录,支持实时同步。
|
|
9
9
|
- 运行时暴露:通过 `@dd-code/runtime` 统一导出公共模块(如 `store/index.js`)。
|
|
10
10
|
- 一体化 CLI:拉取子应用仓库、启动开发、执行构建,开箱即用。
|
|
11
11
|
|
|
@@ -16,13 +16,12 @@
|
|
|
16
16
|
- 可选参数:
|
|
17
17
|
- `-p <platform>`:平台,默认 `h5`,支持 `mp-weixin`。
|
|
18
18
|
- `--mode <mode>`:模式,默认 `development`。
|
|
19
|
-
- `--b <buildDir>`:指定构建目标输出路径(部分场景有效)。
|
|
20
19
|
|
|
21
20
|
## 是干嘛的 / 实现的效果是什么
|
|
22
21
|
- 统一管理主/子应用:自动收集各子应用的页面配置,合并生成主应用最终 `app.json`。
|
|
23
22
|
- 开发态联动:
|
|
24
23
|
- 子应用构建产物变更后,自动同步到主应用分包目录;
|
|
25
|
-
-
|
|
24
|
+
- 在主子应用之间自动同步页面/静态资源变更,减少手动刷新与重复构建。
|
|
26
25
|
- 生产构建可控:按环境与模式输出稳定的主应用与分包结构,避免配置漂移与遗漏。
|
|
27
26
|
- 仓库管理简化:通过交互命令拉取/更新子应用仓库,快速搭建本地联调环境。
|
|
28
27
|
|
|
@@ -31,13 +30,13 @@
|
|
|
31
30
|
- 目录分层:`core/ + plugins/ + server/ + utils`,职责明确、低耦合
|
|
32
31
|
- `core`:运行时与 `app.json` 处理(如 `core/app-json.ts`、`core/runtime.ts`)
|
|
33
32
|
- `plugins`:Vite 插件(主应用、exposes 等)
|
|
34
|
-
- `server
|
|
33
|
+
- `server`:通信服务
|
|
35
34
|
- `utils`:通用工具(文件复制、下载等)
|
|
36
35
|
- Manifest 管理与 `app.json` 合并:`packages/uni-tools/src/plugins/modules/mp-weixin/plugins/main-app.ts:31-76, 105-119, 261-279`
|
|
37
36
|
- 汇总子应用 `pages.json`,渲染为主应用分包配置并写入 `app.json`
|
|
38
37
|
- 写入采用内容比较,避免频繁重启与重复打包(`core/app-json.ts`)
|
|
39
38
|
- 开发态联调:`packages/uni-tools/src/plugins/modules/mp-weixin/plugins/main-app.ts:121-156, 187-245`
|
|
40
|
-
-
|
|
39
|
+
- 主应用启动通信服务,子应用变更触发同步与增量更新
|
|
41
40
|
- 监听拷贝使用内容比较,避免无效触发(`utils/copy.ts`)
|
|
42
41
|
|
|
43
42
|
## 运行时暴露(Runtime Exposes)
|
|
@@ -68,15 +67,12 @@
|
|
|
68
67
|
- `MFE_UNI_IS_ROOT=true|false`:是否主应用(影响 `appCode` 填充与插件行为)(packages/uni-tools/src/config/config.ts:130-141)。
|
|
69
68
|
- `MFE_UNI_CODE=your-project-code`:项目代码,用于 CDN 路径拼接与 Manifest 标识(packages/uni-tools/src/config/config.ts:90-105, 116-141)。
|
|
70
69
|
- `MFE_APP_CODE=__MFE_APP_ROOT__|modules/manage`:当前应用的 `appCode`。
|
|
71
|
-
- `MFE_UNI_SERVE=true|false`:开发态是否启用联调(WS/监听)(packages/uni-tools/src/plugins/modules/mp-weixin/manifest-core.ts:75-87)。
|
|
72
70
|
- `MFE_CDN_HOST=https://static.example.com`:CDN 域名,供 Manifest 资源定位(packages/uni-tools/src/config/config.ts:116-141)。
|
|
73
|
-
- `UNI_PLATFORM=mp-weixin`:平台选择(packages/uni-tools/src/config/config.ts:103-105)。
|
|
74
71
|
- 运行时自动设置的变量(无需手动维护)
|
|
75
72
|
- `MFE_SOURCE_OUTPUT_DIR`:当前应用构建输出目录(packages/uni-tools/src/plugins/modules/mp-weixin/output.ts:64)。
|
|
76
73
|
- `MFE_ROOT_OUTPUT_DIR`:主应用根输出目录(packages/uni-tools/src/plugins/modules/mp-weixin/output.ts:65-69)。
|
|
77
74
|
- `UNI_OUTPUT_DIR`:根输出目录,生成/读取 `app.json`(packages/uni-tools/src/plugins/modules/mp-weixin/output.ts:72-76)。
|
|
78
75
|
- `MFE_INNER_BUILD=true`:子应用处于“内部构建”模式(packages/uni-tools/src/utils/utils.ts:204)。
|
|
79
|
-
- `MFE_TARGET_DIR=root`:由 `--b root` 触发,用于判断内部构建(packages/uni-tools/src/utils/utils.ts:202)。
|
|
80
76
|
|
|
81
77
|
## 快速开始
|
|
82
78
|
1. 安装依赖:
|
|
@@ -104,22 +100,18 @@
|
|
|
104
100
|
```
|
|
105
101
|
MFE_UNI_IS_ROOT=true
|
|
106
102
|
MFE_UNI_CODE=your-project-code
|
|
107
|
-
MFE_UNI_SERVE=true
|
|
108
|
-
UNI_PLATFORM=mp-weixin
|
|
109
103
|
```
|
|
110
104
|
- 启动:`npx uni-tools serve -p mp-weixin --mode development`
|
|
111
|
-
-
|
|
105
|
+
- 行为:开启通信服务与合并逻辑,动态维护最终 `app.json`(packages/uni-tools/src/plugins/modules/mp-weixin/plugins/main-app.ts:121-143, 261-279)。
|
|
112
106
|
- 子应用开发(联调)
|
|
113
107
|
- `.env.development` 示例:
|
|
114
108
|
```
|
|
115
109
|
MFE_UNI_IS_ROOT=false
|
|
116
110
|
MFE_UNI_CODE=your-project-code
|
|
117
111
|
MFE_APP_CODE=modules/manage
|
|
118
|
-
MFE_UNI_SERVE=true
|
|
119
|
-
UNI_PLATFORM=mp-weixin
|
|
120
112
|
```
|
|
121
113
|
- 启动:`npx uni-tools serve -p mp-weixin --mode development`
|
|
122
|
-
-
|
|
114
|
+
- 行为:与主应用服务通信,监听自身输出变更并同步到主应用分包路径(packages/uni-tools/src/plugins/modules/mp-weixin/plugins/main-app.ts:145-156, 78-103)。
|
|
123
115
|
- 子应用构建(不联调,直接写入主应用)
|
|
124
116
|
- 前置:主应用开发态启动但 `MFE_UNI_SERVE=false`,提供 HTTP 接口返回主应用 `UNI_OUTPUT_DIR`(packages/uni-tools/src/plugins/modules/mp-weixin/plugins/main-app.ts:190-200)。
|
|
125
117
|
- 子应用构建命令:`npx uni-tools build -p mp-weixin --mode development --b root`
|
|
@@ -131,7 +123,6 @@
|
|
|
131
123
|
- Manifest 与分包配置生成:读取各子应用 `pages.json` 并渲染至主应用 `subPackages`(packages/uni-tools/src/plugins/modules/mp-weixin/plugins/main-app.ts:41-69)。
|
|
132
124
|
|
|
133
125
|
## 常见问题
|
|
134
|
-
- 端口被占用(`MFE_UNI_SERVE=true`):HTTP/WS 服务具备幂等复用与端口探测,避免重复 `listen`(packages/uni-tools/src/plugins/modules/mp-weixin/server/http-server.ts)。
|
|
135
126
|
- 开发态频繁重启/重复打包:写入 `app.json` 与文件拷贝均进行内容比较,仅在变更时写入(`core/app-json.ts`、`utils/copy.ts`)。
|
|
136
127
|
- CLI 交互报错(inquirer 兼容):已采用动态导入并移动到依赖,`npx` 下可正常使用(packages/uni-tools/src/plugins/modules/mp-weixin/gitlib/index.ts, packages/uni-tools/package.json)。
|
|
137
128
|
|
|
@@ -141,7 +132,7 @@
|
|
|
141
132
|
- 多仓库协作,希望有一套拉取、开发、构建的统一流程。
|
|
142
133
|
|
|
143
134
|
## 注意
|
|
144
|
-
- 开发态会根据 `mode`、`isRoot`
|
|
135
|
+
- 开发态会根据 `mode`、`isRoot` 等状态决定是否启动通信服务与目录监听。
|
|
145
136
|
- 请确保各子应用的 `pages.json` 合法且页面路径正确,便于自动合并。
|
|
146
137
|
- 使用 `--b root` 时需先启动主应用的 HTTP 服务,以便子应用定位 `UNI_OUTPUT_DIR`(packages/uni-tools/src/plugins/modules/mp-weixin/output.ts:39-59)。
|
|
147
138
|
|
|
@@ -151,12 +142,12 @@
|
|
|
151
142
|
```ts
|
|
152
143
|
import { defineConfig } from 'vite';
|
|
153
144
|
import uni from '@dcloudio/vite-plugin-uni';
|
|
154
|
-
import
|
|
145
|
+
import {chageeUniModulePlugin} from '@dd-code/uni-tools';
|
|
155
146
|
|
|
156
147
|
export default defineConfig({
|
|
157
148
|
plugins: [
|
|
158
149
|
uni(),
|
|
159
|
-
|
|
150
|
+
chageeUniModulePlugin({
|
|
160
151
|
exposes: {
|
|
161
152
|
'.': '@/store/index', // -> @dd-code/runtime
|
|
162
153
|
'./axios': '@/axios/index', // -> @dd-code/runtime/axios
|
|
@@ -178,18 +169,13 @@
|
|
|
178
169
|
```
|
|
179
170
|
MFE_UNI_IS_ROOT=true
|
|
180
171
|
MFE_UNI_CODE=your-project-code
|
|
181
|
-
MFE_UNI_SERVE=true
|
|
182
|
-
UNI_PLATFORM=mp-weixin
|
|
183
172
|
```
|
|
184
173
|
- 子应用 `.env.development`:
|
|
185
174
|
```
|
|
186
|
-
MFE_UNI_IS_ROOT=false
|
|
187
175
|
MFE_UNI_CODE=your-project-code
|
|
188
176
|
MFE_APP_CODE=modules/your-app
|
|
189
|
-
MFE_UNI_SERVE=true
|
|
190
|
-
UNI_PLATFORM=mp-weixin
|
|
191
177
|
```
|
|
192
|
-
- 开发:主/子应用分别执行 `npx uni-tools serve -p mp-weixin --mode development
|
|
178
|
+
- 开发:主/子应用分别执行 `npx uni-tools serve -p mp-weixin --mode development`,联调时主应用作为服务端,子应用作为客户端。
|
|
193
179
|
- 子应用直写主应用(不联调):在主应用启动 HTTP 接口后执行 `npx uni-tools build -p mp-weixin --mode development --b root`,产物将按 `appCode` 写入主应用输出目录。
|
|
194
180
|
- 验证与排错
|
|
195
181
|
- 构建后检查根目录是否存在 `__mfe_runtime__.js`。
|