@xfe-repo/web-app 1.6.4 → 2.0.0-beta.2
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 +118 -1
- package/client.d.ts +1 -0
- package/deploy/.drone.yml +13 -4
- package/deploy/Dockerfile +15 -6
- package/deploy/helm/templates/deployment.yaml +5 -18
- package/deploy/helm/templates/svc.yaml +1 -1
- package/dist/cli.js +577 -416
- package/dist/cli.mjs +562 -256
- package/dist/config.d.mts +30 -6
- package/dist/config.d.ts +30 -6
- package/dist/config.js +142 -298
- package/dist/config.mjs +124 -2
- package/dist/framework.d.mts +10 -0
- package/dist/framework.d.ts +10 -0
- package/dist/framework.js +220 -0
- package/dist/framework.mjs +182 -0
- package/dist/node-dev.d.mts +2 -0
- package/dist/node-dev.d.ts +2 -0
- package/dist/node-dev.js +358 -0
- package/dist/node-dev.mjs +332 -0
- package/dist/node.d.mts +27 -0
- package/dist/node.d.ts +27 -0
- package/dist/node.js +381 -0
- package/dist/node.mjs +343 -0
- package/dist/react-router-config.d.mts +11 -0
- package/dist/react-router-config.d.ts +11 -0
- package/dist/react-router-config.js +111 -0
- package/dist/react-router-config.mjs +77 -0
- package/dist/root.d.mts +17 -0
- package/dist/root.d.ts +17 -0
- package/dist/root.js +61 -0
- package/dist/root.mjs +34 -0
- package/dist/serve.d.mts +10 -0
- package/dist/serve.d.ts +10 -0
- package/dist/serve.js +71 -0
- package/dist/serve.mjs +36 -0
- package/dist/vite.d.mts +10 -0
- package/dist/vite.d.ts +10 -0
- package/dist/vite.js +182 -0
- package/dist/vite.mjs +146 -0
- package/package.json +27 -72
- package/tsconfig.json +4 -1
- package/config/env.js +0 -104
- package/config/getHttpsConfig.js +0 -66
- package/config/jest/babelTransform.js +0 -29
- package/config/jest/cssTransform.js +0 -14
- package/config/jest/fileTransform.js +0 -40
- package/config/modules.js +0 -133
- package/config/paths.js +0 -65
- package/config/webpack/persistentCache/createEnvironmentHash.js +0 -9
- package/config/webpack/webpack.config.js +0 -737
- package/config/webpack/webpackDevServer.config.js +0 -122
- package/deploy/nginx.conf +0 -62
- package/dist/chunk-75BJNL7E.mjs +0 -239
- package/scripts/build.js +0 -217
- package/scripts/dev.js +0 -162
package/README.md
CHANGED
|
@@ -1,6 +1,123 @@
|
|
|
1
1
|
# `@xfe-repo/web-app`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
统一管理 Web 配置、页面入口、类型检查与构建;当前内部使用 React Router 8 Framework Mode 和 Vite 8。
|
|
4
|
+
|
|
5
|
+
要求 Node.js `>=22.22.0`、React/ReactDOM `>=19.2.7`。业务项目只维护:
|
|
6
|
+
|
|
7
|
+
- `src/layout.tsx`(可选),只编写业务 Provider 与布局,接收 `children`
|
|
8
|
+
- `src/app.ts`,服务端上下文存在时再增加 `src/app.server.ts`
|
|
9
|
+
- `src/pages/**/index.tsx`
|
|
10
|
+
- `xfe.json.webapp`
|
|
11
|
+
|
|
12
|
+
`react-router.config`、Vite 配置由 app 包维护,路由收集器由 `@xfe-repo/web-router/routes` 维护;CLI 在 `node_modules/.cache/xfe-web/react-router`
|
|
13
|
+
生成 React Router 必需的隐藏 shim。`home/index.tsx`、`index/index.tsx` 和旧的
|
|
14
|
+
`_index/index.tsx`/`route.tsx` 映射 `/`;页面目录支持 `$id`、`[id]` 动态参数。普通页面只需:
|
|
15
|
+
|
|
16
|
+
不能直接把隐藏 app 生成到 `@xfe-repo/web-app` 包目录:React Router 会按物理路径发现 config/routes,dev watcher 和 typegen 还会向相邻目录写入状态;共享包目录既不属于业务项目,也会让多个项目互相覆盖。项目本地的 `node_modules/.cache` 可写、默认忽略,且仍处于依赖解析范围内。
|
|
17
|
+
|
|
18
|
+
客户端与服务端复用已锁定版本的 React Router 官方默认 entry,业务项目不再维护 entry 文件;服务端入口由 CLI 显式转发,避免底层工具向业务清单添加 `isbot` 并自动安装。HTML 文档、路由出口与默认 loading/error 由框架生成。
|
|
19
|
+
|
|
20
|
+
`vite`、`less` 和 `isbot` 由本包安装和维护;SSR 产物打包 `isbot`,不要求部署项目另装它。`react-router` 由本包与 `web-router` 固定为同一版本,业务从 `@xfe-repo/web-router` 导入路由 API 和类型,无需直接声明这四个依赖。
|
|
21
|
+
|
|
22
|
+
```tsx
|
|
23
|
+
export const page = app.registerPage(config, Component)
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
默认使用框架的 404/500 边界,业务无需创建 `pages/$`;可在 `layout.tsx` 直接导出 `ErrorView({ error })` 自定义错误展示。
|
|
27
|
+
|
|
28
|
+
```json
|
|
29
|
+
{
|
|
30
|
+
"webapp": {
|
|
31
|
+
"renderMode": "client",
|
|
32
|
+
"title": "商户后台",
|
|
33
|
+
"port": 3001
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
`renderMode: "client"` 生成 SPA 静态产物 `dist/client/index.html`;`xfe-web start` 使用框架内的 Express 静态服务,支持 `basename` 下的深链接回退,缺失的 `/assets` 文件仍返回 404,不需要 server bundle 或运行时 JWT 私钥。现有 Docker 启动命令无需修改,也可把 `dist/client` 交给外部静态托管并配置 index.html 回退。`"server"`(兼容旧项目的默认值)保留服务端构建与 React Router 服务;切换为 SSR 前仍需实现请求隔离的 Store/Context。其他可选项:`basename`、`host`、`lang`(默认 `zh-CN`)、`themeColor`。`HOST/PORT` 环境变量可覆盖 SPA 启动地址。修改启动配置后重新运行 CLI。
|
|
39
|
+
|
|
40
|
+
构建目录通过 `xfe.json.webapp.buildDirectory` 配置,省略时统一输出到 `dist`。SPA 产物位于 `<buildDirectory>/client`,SSR 额外生成 `<buildDirectory>/server/index.js`;`xfe-web build/start/config` 使用同一配置,无需移动产物或修改隐藏的 React Router/Vite 配置。
|
|
41
|
+
|
|
42
|
+
```json
|
|
43
|
+
{
|
|
44
|
+
"webapp": {
|
|
45
|
+
"buildDirectory": "dist"
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
升级注意:此前默认目录为 `build`。部署或脚本仍使用旧路径的项目可显式设置 `"buildDirectory": "build"`,待相关路径一起调整后再移除配置。目录必须是项目内独立的相对路径,也支持 `artifacts/web` 这样的多级目录;不能指向项目根目录、项目外或 `src/types/public/node_modules/.git`。输出目录及其上级不能是符号链接。构建会清空目标目录,请勿放入需要保留的文件;修改配置后需要重新构建。
|
|
51
|
+
|
|
52
|
+
框架 Docker 模板默认复制 `dist`。`xfe-web config` 会把配置后的相对路径写入 Drone 镜像构建参数 `XFE_BUILD_DIRECTORY`;使用模板手动构建镜像时,需传入与 `xfe.json` 相同的路径,例如 `docker build --build-arg XFE_BUILD_DIRECTORY=artifacts/web -f deploy/Dockerfile .`。仅更新目录配置时,需重新生成流水线配置并同步模板。
|
|
53
|
+
|
|
54
|
+
可选 Node 入口:
|
|
55
|
+
|
|
56
|
+
```json
|
|
57
|
+
{
|
|
58
|
+
"webapp": {
|
|
59
|
+
"serverEntry": "src/server.ts",
|
|
60
|
+
"buildDirectory": "dist",
|
|
61
|
+
"renderMode": "client"
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
`serverEntry` 是项目内默认导出服务工厂的 TypeScript / JavaScript ESM 文件:
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
import { createServer } from 'node:http'
|
|
70
|
+
import type { NodeServerFactory } from '@xfe-repo/web-app/dist/node'
|
|
71
|
+
|
|
72
|
+
/** 业务先处理自己的请求,剩余请求交给框架前端。 */
|
|
73
|
+
const createApplication: NodeServerFactory = ({ frontend }) => ({
|
|
74
|
+
server: createServer(
|
|
75
|
+
/** API、认证、Host 检查可在这里先于前端执行。 */ (request, response) => {
|
|
76
|
+
if (request.url === '/healthz') {
|
|
77
|
+
response.end('ok')
|
|
78
|
+
return
|
|
79
|
+
}
|
|
80
|
+
frontend(request, response)
|
|
81
|
+
},
|
|
82
|
+
),
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
export default createApplication
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
命令仍是 `xfe-web dev/build/start`。开发时后端由 `tsx watch` 监督应用进程重启,前端复用现有 Vite / React Router 配置;HTTP、业务 WebSocket 与 HMR 使用同一个端口、同一个应用 Node 进程(开发监听器由 tsx 维护)。页面变化继续走 Vite HMR,不重启业务实例;后端变化通过退出信号关闭旧进程、释放资源,再由 tsx 创建新进程;开发报错后继续监听,源码修复后重新启动。开发进程读取 Vite 约定的 `.env` 文件,已有环境变量优先。
|
|
89
|
+
|
|
90
|
+
工厂接收 `frontend`(原生 Node 请求处理器)和 `mode`(`development` / `production`),返回未监听的 `http.Server`。可选 `upgrade(request, socket, head)` 处理业务 WebSocket;框架先分流保留的 `<basename>/_xfe/hmr`,其余升级再交给业务。WebSocket 库使用 `noServer` 模式,不要自行给 server 注册 `upgrade` 事件;业务处理器应关闭不接受的升级连接。可选异步 `close()` 在 HTTP 排空后释放数据库等资源。工厂内初始化尚未返回就失败时,由工厂回收自己已取得的资源。
|
|
91
|
+
|
|
92
|
+
框架负责唯一的 `listen`、SIGINT / SIGTERM 和关闭流程;入口不要自行监听端口或接管进程退出。生产停机时普通 HTTP 请求最多等待 30 秒排空;开发重启超时遵循 tsx 的原生行为,升级连接在后端重载及停机时断开。自定义入口通过 `HOST/PORT` 或 `webapp.host/port` 设置地址,不接收额外 CLI 参数。
|
|
93
|
+
|
|
94
|
+
构建先生成前端,再输出 `<buildDirectory>/server/node.mjs` 和 sourcemap,SSR 模式不覆盖 React Router 的 `server/index.js`;SPA 模式清理预渲染的 server 中间产物。`xfe-web start` 只加载产物,部署无需源码或隐藏生成缓存。业务 Node 依赖保持 external,必须放在业务 `dependencies`;通过 `xfe-web start` 启动时 `@xfe-repo/web-app` 也必须保留在生产依赖中。生产地址和密钥通过进程环境传入,启动不读取开发 `.env`。
|
|
95
|
+
|
|
96
|
+
`src/app.server.ts` 继续只负责 React Router 请求 middleware,不能替代 `serverEntry`。省略 `serverEntry` 的项目保留原有 SPA / SSR 分支。此最小版本不提供自定义打包插件、任意服务端多入口或生产热重载;后端重启交给 tsx,不维护进程内模块缓存或热重载状态机。
|
|
97
|
+
|
|
98
|
+
原生扩展保持兼容:已有 `src/root.tsx` 优先于默认根布局;其中的 Framework value exports 使用直接的 `export const/function/class` 声明。原生 `route.tsx` 和标准导出仍可使用,其 API 和类型同样从 `@xfe-repo/web-router` 导入,不要求业务另装 React Router。
|
|
99
|
+
|
|
100
|
+
命令保持不变:
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
xfe-web dev
|
|
104
|
+
xfe-web build
|
|
105
|
+
xfe-web typegen
|
|
106
|
+
xfe-web typecheck
|
|
107
|
+
xfe-web start
|
|
108
|
+
xfe-web config
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
`typecheck` 先在与 dev/build 相同的隐藏目录生成路由类型,再运行 TypeScript。项目 tsconfig 继承 `@xfe-repo/web-app/tsconfig.json`,只保留业务别名和源码范围;客户端环境类型引用 `@xfe-repo/web-app/client`,无需配置生成类型的路径。重复生成只更新内容变化的文件,不删除正在运行的开发缓存。
|
|
112
|
+
|
|
113
|
+
业务 `package.json` 的类型检查脚本使用 `"typecheck": "xfe-web typecheck"`;类型声明文件加入 `/// <reference types="@xfe-repo/web-app/client" />`,不再直接配置 `vite/client` 或隐藏缓存的 `rootDirs/include`。
|
|
114
|
+
|
|
115
|
+
框架将 React、ReactDOM、React Redux 与 RTK 去重到消费应用的依赖,支持 workspace 和本地链接联调。React 组件仍依赖 React;这里隔离的是路由和构建实现,不承诺任意 UI 技术栈之间零修改迁移。
|
|
116
|
+
|
|
117
|
+
`dev` 和 SSR `start` 获取完整 JWT 环境,SPA `start` 不获取私钥;
|
|
118
|
+
`build` 只向客户端注入 aud/keyId,明确丢弃私钥。
|
|
119
|
+
|
|
120
|
+
SSR `start` 使用与构建一致的隐藏工作目录,使官方 serve 正确解析 `dist/client` 静态资源;启动时仅保证该目录存在,不读取 `src/pages` 或重新生成入口。
|
|
4
121
|
|
|
5
122
|
构建会先加载 `react-app-polyfill/stable`,并在应用原有 browserslist 的基础上,补充 Edge 18、Chrome 64、Firefox 60、Safari/iOS 12 及以上的 JS 编译目标,业务代码和第三方依赖使用同一目标。
|
|
6
123
|
|
package/client.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/// <reference types="vite/client" />
|
package/deploy/.drone.yml
CHANGED
|
@@ -18,17 +18,19 @@ resources:
|
|
|
18
18
|
steps:
|
|
19
19
|
- name: install
|
|
20
20
|
pull: if-not-exists
|
|
21
|
-
image:
|
|
21
|
+
image: node:22.22.0-bookworm
|
|
22
22
|
volumes:
|
|
23
23
|
- name: node-modules
|
|
24
24
|
path: /drone/src/node_modules
|
|
25
25
|
commands:
|
|
26
|
+
- corepack enable
|
|
27
|
+
- corepack prepare pnpm@10.30.3 --activate
|
|
26
28
|
- pnpm config set registry https://registry.npmmirror.com
|
|
27
29
|
- pnpm i
|
|
28
30
|
|
|
29
31
|
- name: build
|
|
30
32
|
pull: if-not-exists
|
|
31
|
-
image:
|
|
33
|
+
image: node:22.22.0-bookworm
|
|
32
34
|
resources:
|
|
33
35
|
limits:
|
|
34
36
|
memory: 8192MiB
|
|
@@ -36,11 +38,16 @@ steps:
|
|
|
36
38
|
- name: node-modules
|
|
37
39
|
path: /drone/src/node_modules
|
|
38
40
|
commands:
|
|
41
|
+
- corepack enable
|
|
42
|
+
- corepack prepare pnpm@10.30.3 --activate
|
|
39
43
|
- cp -r node_modules/@xfe-repo/web-app/deploy deploy
|
|
40
44
|
- export NODE_OPTIONS="--max-old-space-size=8192"
|
|
41
|
-
- export
|
|
42
|
-
-
|
|
45
|
+
- export XFE_RELEASE=$DRONE_REPO_NAME@${DRONE_TAG:CI_COMMIT_SHA}
|
|
46
|
+
- export REACT_APP_RELEASE=$XFE_RELEASE
|
|
47
|
+
- printf '%s' "$XFE_RELEASE" > deploy/static/release
|
|
48
|
+
- cp deploy/static/release deploy/static/check-update
|
|
43
49
|
- pnpm build
|
|
50
|
+
- cp -a node_modules deploy/modules
|
|
44
51
|
|
|
45
52
|
- name: image-build
|
|
46
53
|
image: xhj-prod-registry-vpc.cn-hangzhou.cr.aliyuncs.com/image-common/kaniko:latest
|
|
@@ -52,6 +59,8 @@ steps:
|
|
|
52
59
|
password:
|
|
53
60
|
from_secret: password
|
|
54
61
|
dockerfile: deploy/Dockerfile
|
|
62
|
+
build_args:
|
|
63
|
+
- "XFE_BUILD_DIRECTORY=dist"
|
|
55
64
|
repo_path: xhj-prod-registry-vpc.cn-hangzhou.cr.aliyuncs.com/xhj-image/
|
|
56
65
|
repo_name: ${DRONE_REPO}
|
|
57
66
|
tags:
|
package/deploy/Dockerfile
CHANGED
|
@@ -1,10 +1,19 @@
|
|
|
1
|
-
FROM
|
|
1
|
+
FROM node:22.22.0-bookworm-slim
|
|
2
2
|
|
|
3
|
-
WORKDIR /
|
|
3
|
+
WORKDIR /app
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
ENV NODE_ENV=production
|
|
6
|
+
ENV HOST=0.0.0.0
|
|
7
|
+
ENV PORT=3000
|
|
6
8
|
|
|
7
|
-
|
|
9
|
+
ARG XFE_BUILD_DIRECTORY=dist
|
|
10
|
+
COPY ["${XFE_BUILD_DIRECTORY}", "./${XFE_BUILD_DIRECTORY}"]
|
|
11
|
+
COPY ["deploy/static", "./${XFE_BUILD_DIRECTORY}/client"]
|
|
12
|
+
COPY deploy/modules ./node_modules
|
|
13
|
+
COPY package.json xfe.json ./
|
|
8
14
|
|
|
9
|
-
|
|
10
|
-
|
|
15
|
+
EXPOSE 3000
|
|
16
|
+
|
|
17
|
+
USER node
|
|
18
|
+
|
|
19
|
+
CMD ["./node_modules/.bin/xfe-web", "start"]
|
|
@@ -30,8 +30,12 @@ spec:
|
|
|
30
30
|
requests:
|
|
31
31
|
cpu: "0.01"
|
|
32
32
|
memory: "100Mi"
|
|
33
|
-
{{if $.Values.hostPrefix}}
|
|
34
33
|
env:
|
|
34
|
+
- name: HOST
|
|
35
|
+
value: "0.0.0.0"
|
|
36
|
+
- name: PORT
|
|
37
|
+
value: "3000"
|
|
38
|
+
{{if $.Values.hostPrefix}}
|
|
35
39
|
- name: HOST_PREFIX
|
|
36
40
|
value: "{{ $.Values.hostPrefix }}"
|
|
37
41
|
{{end}}
|
|
@@ -40,21 +44,4 @@ spec:
|
|
|
40
44
|
- configMapRef:
|
|
41
45
|
name: "app-common-config"
|
|
42
46
|
{{- end }}
|
|
43
|
-
volumeMounts:
|
|
44
|
-
- mountPath: /var/log/nginx
|
|
45
|
-
subPath: "xfe/{{ $.Values.app }}"
|
|
46
|
-
name: log
|
|
47
|
-
command:
|
|
48
|
-
- bash
|
|
49
|
-
- "-c"
|
|
50
|
-
- |
|
|
51
|
-
nginx
|
|
52
|
-
while :
|
|
53
|
-
do
|
|
54
|
-
sleep 10
|
|
55
|
-
done
|
|
56
|
-
volumes:
|
|
57
|
-
- name: log
|
|
58
|
-
hostPath:
|
|
59
|
-
path: /var/log
|
|
60
47
|
---
|