@xfe-repo/web-app 1.6.3 → 2.0.0-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 +60 -1
- package/client.d.ts +1 -0
- package/deploy/.drone.yml +11 -4
- package/deploy/Dockerfile +14 -6
- package/deploy/helm/templates/deployment.yaml +5 -18
- package/deploy/helm/templates/svc.yaml +1 -1
- package/dist/cli.js +275 -413
- package/dist/cli.mjs +273 -267
- package/dist/config.d.mts +20 -6
- package/dist/config.d.ts +20 -6
- package/dist/config.js +83 -297
- package/dist/config.mjs +69 -2
- package/dist/framework.d.mts +10 -0
- package/dist/framework.d.ts +10 -0
- package/dist/framework.js +174 -0
- package/dist/framework.mjs +137 -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 +66 -0
- package/dist/react-router-config.mjs +35 -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 +9 -0
- package/dist/vite.d.ts +9 -0
- package/dist/vite.js +135 -0
- package/dist/vite.mjs +100 -0
- package/package.json +22 -71
- 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,65 @@
|
|
|
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 静态产物 `build/client/index.html`;`xfe-web start` 使用框架内的 Express 静态服务,支持 `basename` 下的深链接回退,缺失的 `/assets` 文件仍返回 404,不需要 server bundle 或运行时 JWT 私钥。现有 Docker 启动命令无需修改,也可把 `build/client` 交给外部静态托管并配置 index.html 回退。`"server"`(兼容旧项目的默认值)保留服务端构建与 React Router 服务;切换为 SSR 前仍需实现请求隔离的 Store/Context。其他可选项:`basename`、`host`、`lang`(默认 `zh-CN`)、`themeColor`。`HOST/PORT` 环境变量可覆盖 SPA 启动地址。修改启动配置后重新运行 CLI。
|
|
39
|
+
|
|
40
|
+
原生扩展保持兼容:已有 `src/root.tsx` 优先于默认根布局;其中的 Framework value exports 使用直接的 `export const/function/class` 声明。原生 `route.tsx` 和标准导出仍可使用,其 API 和类型同样从 `@xfe-repo/web-router` 导入,不要求业务另装 React Router。
|
|
41
|
+
|
|
42
|
+
命令保持不变:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
xfe-web dev
|
|
46
|
+
xfe-web build
|
|
47
|
+
xfe-web typegen
|
|
48
|
+
xfe-web typecheck
|
|
49
|
+
xfe-web start
|
|
50
|
+
xfe-web config
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
`typecheck` 先在与 dev/build 相同的隐藏目录生成路由类型,再运行 TypeScript。项目 tsconfig 继承 `@xfe-repo/web-app/tsconfig.json`,只保留业务别名和源码范围;客户端环境类型引用 `@xfe-repo/web-app/client`,无需配置生成类型的路径。重复生成只更新内容变化的文件,不删除正在运行的开发缓存。
|
|
54
|
+
|
|
55
|
+
业务 `package.json` 的类型检查脚本使用 `"typecheck": "xfe-web typecheck"`;类型声明文件加入 `/// <reference types="@xfe-repo/web-app/client" />`,不再直接配置 `vite/client` 或隐藏缓存的 `rootDirs/include`。
|
|
56
|
+
|
|
57
|
+
框架将 React、ReactDOM、React Redux 与 RTK 去重到消费应用的依赖,支持 workspace 和本地链接联调。React 组件仍依赖 React;这里隔离的是路由和构建实现,不承诺任意 UI 技术栈之间零修改迁移。
|
|
58
|
+
|
|
59
|
+
`dev` 和 SSR `start` 获取完整 JWT 环境,SPA `start` 不获取私钥;
|
|
60
|
+
`build` 只向客户端注入 aud/keyId,明确丢弃私钥。
|
|
61
|
+
|
|
62
|
+
SSR `start` 使用与构建一致的隐藏工作目录,使官方 serve 正确解析 `build/client` 静态资源;启动时仅保证该目录存在,不读取 `src/pages` 或重新生成入口。
|
|
4
63
|
|
|
5
64
|
构建会先加载 `react-app-polyfill/stable`,并在应用原有 browserslist 的基础上,补充 Edge 18、Chrome 64、Firefox 60、Safari/iOS 12 及以上的 JS 编译目标,业务代码和第三方依赖使用同一目标。
|
|
6
65
|
|
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
|
package/deploy/Dockerfile
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
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
|
-
COPY
|
|
9
|
+
COPY build ./build
|
|
10
|
+
COPY deploy/static ./build/client
|
|
11
|
+
COPY deploy/modules ./node_modules
|
|
12
|
+
COPY package.json xfe.json ./
|
|
8
13
|
|
|
9
|
-
|
|
10
|
-
|
|
14
|
+
EXPOSE 3000
|
|
15
|
+
|
|
16
|
+
USER node
|
|
17
|
+
|
|
18
|
+
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
|
---
|