@tbox.cn/app-template-h5 0.1.19 → 0.1.21
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/.gitignore +6 -0
- package/README.md +3 -0
- package/apps/client/package.json +2 -1
- package/apps/client/src/business/routes.json +3 -0
- package/apps/client/src/main.tsx +4 -11
- package/apps/client/src/platform/bootstrap.ts +18 -0
- package/apps/client/src/platform/mount-page.tsx +34 -0
- package/apps/client/vite.config.ts +8 -0
- package/apps/server/src/dev.ts +6 -0
- package/apps/server/src/index.ts +16 -9
- package/package.json +2 -2
- package/pnpm-lock.template.yaml +14 -11
- package/pnpm-workspace.template.yaml +3 -3
package/.gitignore
CHANGED
package/README.md
CHANGED
|
@@ -23,6 +23,9 @@ pnpm install
|
|
|
23
23
|
## 目录边界
|
|
24
24
|
|
|
25
25
|
- `apps/client/src/business/`:业务应用唯一入口
|
|
26
|
+
- `apps/client/src/business/routes.json`:页面清单(MPA 文档模式唯一真源——在场时每条路由物化
|
|
27
|
+
一个物理 HTML 文档,未知页面 404 是文件系统的自然结果;删除文件 = 回到单页 legacy。`path`
|
|
28
|
+
纯静态段,增删路由需重启 dev 进程)
|
|
26
29
|
- `apps/server/src/index.ts`:静态入口(唯一 tsup entry)
|
|
27
30
|
- `apps/server/src/dev.ts`:vite dev 入口(仅本地开发)
|
|
28
31
|
- `scripts/`:平台生命周期脚本(prepare/dev/start/stop/build 固定名)
|
package/apps/client/package.json
CHANGED
package/apps/client/src/main.tsx
CHANGED
|
@@ -1,18 +1,11 @@
|
|
|
1
1
|
import { StrictMode } from 'react';
|
|
2
2
|
import { createRoot } from 'react-dom/client';
|
|
3
|
-
import {
|
|
4
|
-
configureRuntime,
|
|
5
|
-
ErrorBoundary,
|
|
6
|
-
installGlobalErrorReporting,
|
|
7
|
-
} from '@tbox.cn/app-sdk-client';
|
|
3
|
+
import { ErrorBoundary } from '@tbox.cn/app-sdk-client';
|
|
8
4
|
import BusinessApp from './business/App';
|
|
9
|
-
import './
|
|
5
|
+
import { bootstrap } from './platform/bootstrap';
|
|
10
6
|
|
|
11
|
-
//
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
// 全局错误兜底:未捕获异常/rejection → 统一日志行(上报扩展点见 SDK client logger)
|
|
15
|
-
installGlobalErrorReporting();
|
|
7
|
+
// 启动层(运行时注入/错误兜底/基础样式)——与生成 entry(mount-page)共享
|
|
8
|
+
bootstrap();
|
|
16
9
|
|
|
17
10
|
const el = document.getElementById('root');
|
|
18
11
|
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 客户端启动层(单一职责:一次进程级初始化,幂等)。
|
|
3
|
+
* 消费方 = 根 entry(main.tsx)与生成 entry(.tbox-gen/<id>.ts 经 mount-page)——
|
|
4
|
+
* 两侧共享同一实现(运行时注入/错误兜底/基础样式)。
|
|
5
|
+
*/
|
|
6
|
+
import { configureRuntime, installGlobalErrorReporting } from '@tbox.cn/app-sdk-client';
|
|
7
|
+
import '../styles/base.css';
|
|
8
|
+
|
|
9
|
+
let bootstrapped = false;
|
|
10
|
+
|
|
11
|
+
export function bootstrap(): void {
|
|
12
|
+
if (bootstrapped) return;
|
|
13
|
+
bootstrapped = true;
|
|
14
|
+
// H1:环境值注入点(SDK 零 Vite 依赖)——VITE_API_URL 空串/未设 = 同源相对路径
|
|
15
|
+
configureRuntime({ apiBaseUrl: import.meta.env.VITE_API_URL as string | undefined });
|
|
16
|
+
// 全局错误兜底:未捕获异常/rejection → 统一日志行(上报扩展点见 SDK client logger)
|
|
17
|
+
installGlobalErrorReporting();
|
|
18
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 生成 entry 的页面挂载点(跨包契约:mpa-build-plugin 生成的 .tbox-gen/<id>.ts 调用本模块)。
|
|
3
|
+
* bootstrap(幂等)+ ErrorBoundary + lazy 页面——与根 entry(main.tsx)同一启动语义。
|
|
4
|
+
*/
|
|
5
|
+
import { StrictMode } from 'react';
|
|
6
|
+
import { createRoot } from 'react-dom/client';
|
|
7
|
+
import { lazy, Suspense, type ComponentType } from 'react';
|
|
8
|
+
import { ErrorBoundary } from '@tbox.cn/app-sdk-client';
|
|
9
|
+
import { bootstrap } from './bootstrap';
|
|
10
|
+
|
|
11
|
+
export function mountPage(load: () => Promise<{ default: ComponentType }>): void {
|
|
12
|
+
bootstrap();
|
|
13
|
+
const Page = lazy(load);
|
|
14
|
+
const el = document.getElementById('root');
|
|
15
|
+
if (!el) return;
|
|
16
|
+
createRoot(el).render(
|
|
17
|
+
<StrictMode>
|
|
18
|
+
<ErrorBoundary
|
|
19
|
+
fallback={
|
|
20
|
+
<main>
|
|
21
|
+
<h1>页面暂时不可用</h1>
|
|
22
|
+
<button type="button" onClick={() => window.location.reload()}>
|
|
23
|
+
重新加载
|
|
24
|
+
</button>
|
|
25
|
+
</main>
|
|
26
|
+
}
|
|
27
|
+
>
|
|
28
|
+
<Suspense fallback={<div>加载中…</div>}>
|
|
29
|
+
<Page />
|
|
30
|
+
</Suspense>
|
|
31
|
+
</ErrorBoundary>
|
|
32
|
+
</StrictMode>,
|
|
33
|
+
);
|
|
34
|
+
}
|
|
@@ -9,6 +9,13 @@ import codeInspectPlugin from '@tbox.cn/app-sdk-client/platform/code-inspect';
|
|
|
9
9
|
// dev 期页面由 apps/server dev.ts 的 vite middleware 托管(本文件被其加载);
|
|
10
10
|
// build 恒走静态产物。无 .tbox-dev.local 探针段(h5 无 dev 装配面,native launch)。
|
|
11
11
|
export default defineConfig(async ({ command }) => {
|
|
12
|
+
// MPA 多页构建插件(v3.2 文档模式):routes.json 在场 ⇔ 端到端文档模式;缺席零注册零变化。
|
|
13
|
+
// 动态 import(对齐 previewErrorReporter 惯例)——vitest 零加载 Node 端依赖。
|
|
14
|
+
let mpaPlugin: Plugin | null = null;
|
|
15
|
+
if (!process.env.VITEST) {
|
|
16
|
+
const { tboxMpaPlugin } = await import('@tbox.cn/app-sdk-server/platform');
|
|
17
|
+
mpaPlugin = tboxMpaPlugin();
|
|
18
|
+
}
|
|
12
19
|
const devPlugins: Plugin[] = [];
|
|
13
20
|
// 只在开发服务装载异常上报插件;build/vitest 无需解析其 Node 端依赖。
|
|
14
21
|
if (command === 'serve' && !process.env.VITEST) {
|
|
@@ -18,6 +25,7 @@ export default defineConfig(async ({ command }) => {
|
|
|
18
25
|
return {
|
|
19
26
|
plugins: [
|
|
20
27
|
react({ babel: { plugins: command === 'serve' ? [codeInspectPlugin] : [] } }),
|
|
28
|
+
...(mpaPlugin ? [mpaPlugin] : []),
|
|
21
29
|
...devPlugins,
|
|
22
30
|
],
|
|
23
31
|
resolve: {
|
package/apps/server/src/dev.ts
CHANGED
|
@@ -82,6 +82,11 @@ const runtime = createTboxDevRuntime({
|
|
|
82
82
|
decorateHtml: (html) => (isReady() ? injectScript(html) : html),
|
|
83
83
|
logger: serverLogger,
|
|
84
84
|
sseKeepaliveMs: process.env.TBOX_DEV_SSE_KEEPALIVE_MS ? Number(process.env.TBOX_DEV_SSE_KEEPALIVE_MS) : undefined,
|
|
85
|
+
// v3.2 严格文档模式(G8 模式开关):routes.json 在场 ⇔ strict(dev 面 entry 替换 +
|
|
86
|
+
// public 目录索引;static 面 dist 文件真源)。缺席 = legacy SPA fallback,零变化。
|
|
87
|
+
pagePolicy: {
|
|
88
|
+
routesModule: path.join(clientRoot, 'src/business/routes.json'),
|
|
89
|
+
},
|
|
85
90
|
});
|
|
86
91
|
|
|
87
92
|
// 面裁决:dev 面 → vite middlewares;static 面 → next()(落 final 的 dist 静态)
|
|
@@ -106,6 +111,7 @@ if (protectedMode) {
|
|
|
106
111
|
const watcher = Array.isArray(result) ? result[0] : result;
|
|
107
112
|
if (!watcher || !('on' in watcher)) return;
|
|
108
113
|
watcher.on('event', (e) => {
|
|
114
|
+
if (e.code === 'BUNDLE_START') runtime.notifyBuildStart();
|
|
109
115
|
if (e.code === 'BUNDLE_END') runtime.notifyBuildEnd();
|
|
110
116
|
});
|
|
111
117
|
})
|
package/apps/server/src/index.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { existsSync } from 'node:fs';
|
|
|
8
8
|
import { fileURLToPath } from 'url';
|
|
9
9
|
import express from 'express';
|
|
10
10
|
import { createLogger } from '@tbox.cn/app-sdk-server';
|
|
11
|
-
import { installInspector } from '@tbox.cn/app-sdk-server/platform';
|
|
11
|
+
import { createStrictStaticHandler, installInspector } from '@tbox.cn/app-sdk-server/platform';
|
|
12
12
|
import { app, start } from './app.js';
|
|
13
13
|
|
|
14
14
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
@@ -23,13 +23,20 @@ if (!existsSync(path.join(clientDistPath, 'index.html'))) {
|
|
|
23
23
|
logger.warn(`client/dist 缺失(${clientDistPath})——页面将不可用;请先执行 pnpm build:client`);
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
});
|
|
26
|
+
// v3.2 严格文档模式(G8 模式开关):routes.json 在场 ⇔ strict(dist 文件存在性 =
|
|
27
|
+
// 唯一路由真源,未知页面 404 是文件系统的自然结果);缺席 = legacy SPA fallback(等价历史)。
|
|
28
|
+
const routesModule = path.join(__dirname, '../../client/src/business/routes.json');
|
|
29
|
+
if (existsSync(routesModule)) {
|
|
30
|
+
logger.info('page_mode', { mode: 'strict-pages' });
|
|
31
|
+
app.use(createStrictStaticHandler({ distDir: clientDistPath }));
|
|
32
|
+
} else {
|
|
33
|
+
logger.info('page_mode', { mode: 'legacy-spa' });
|
|
34
|
+
app.use(express.static(clientDistPath));
|
|
35
|
+
app.get('*', (req, res) => {
|
|
36
|
+
if (!req.path.startsWith('/api')) {
|
|
37
|
+
res.sendFile(path.join(clientDistPath, 'index.html'));
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
34
41
|
|
|
35
42
|
start();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tbox.cn/app-template-h5",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.21",
|
|
4
4
|
"description": "tbox Web 全栈模板(单 workspace:apps/client + apps/server;h5 为家族历史名,不预设端形态),运行时与页面微调经 @tbox.cn/app-sdk。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"eslint-plugin-react-hooks": "5.2.0",
|
|
36
36
|
"typescript-eslint": "8.67.0",
|
|
37
37
|
"vite": "6.4.3",
|
|
38
|
-
"@tbox.cn/app-sdk-server": "0.26.
|
|
38
|
+
"@tbox.cn/app-sdk-server": "0.26.4"
|
|
39
39
|
},
|
|
40
40
|
"scripts": {
|
|
41
41
|
"dev": "pnpm --filter ./apps/server dev",
|
package/pnpm-lock.template.yaml
CHANGED
|
@@ -10,8 +10,8 @@ catalogs:
|
|
|
10
10
|
specifier: 0.21.4
|
|
11
11
|
version: 0.21.4
|
|
12
12
|
'@tbox.cn/app-sdk-server':
|
|
13
|
-
specifier: 0.26.
|
|
14
|
-
version: 0.26.
|
|
13
|
+
specifier: 0.26.4
|
|
14
|
+
version: 0.26.4
|
|
15
15
|
'@types/express':
|
|
16
16
|
specifier: 4.17.25
|
|
17
17
|
version: 4.17.25
|
|
@@ -79,7 +79,7 @@ importers:
|
|
|
79
79
|
devDependencies:
|
|
80
80
|
'@tbox.cn/app-sdk-server':
|
|
81
81
|
specifier: 'catalog:'
|
|
82
|
-
version: 0.26.
|
|
82
|
+
version: 0.26.4
|
|
83
83
|
eslint:
|
|
84
84
|
specifier: 'catalog:'
|
|
85
85
|
version: 9.39.5
|
|
@@ -105,6 +105,9 @@ importers:
|
|
|
105
105
|
specifier: 'catalog:'
|
|
106
106
|
version: 18.3.1(react@18.3.1)
|
|
107
107
|
devDependencies:
|
|
108
|
+
'@tbox.cn/app-sdk-server':
|
|
109
|
+
specifier: 'catalog:'
|
|
110
|
+
version: 0.26.4
|
|
108
111
|
'@types/node':
|
|
109
112
|
specifier: 'catalog:'
|
|
110
113
|
version: 24.13.3
|
|
@@ -134,7 +137,7 @@ importers:
|
|
|
134
137
|
dependencies:
|
|
135
138
|
'@tbox.cn/app-sdk-server':
|
|
136
139
|
specifier: 'catalog:'
|
|
137
|
-
version: 0.26.
|
|
140
|
+
version: 0.26.4
|
|
138
141
|
express:
|
|
139
142
|
specifier: 'catalog:'
|
|
140
143
|
version: 4.22.2
|
|
@@ -971,13 +974,13 @@ packages:
|
|
|
971
974
|
resolution: {integrity: sha512-HLLRg1y2jB32uJPL3/a387eABdNZUxrmkGoJwIv44XV9B94DXmTgb9vxYzbyBa0FazxXG0WudyzFnmH5eeqqrw==}
|
|
972
975
|
engines: {node: '>=20.0.0'}
|
|
973
976
|
|
|
974
|
-
'@tbox.cn/app-sdk-server@0.26.
|
|
975
|
-
resolution: {integrity: sha512-
|
|
977
|
+
'@tbox.cn/app-sdk-server@0.26.4':
|
|
978
|
+
resolution: {integrity: sha512-U5dxB6y8mkDB8dF01uU82+2Qbzi8MU+3ChxiFB++Rpef5YeJ7v9DcqklXS+uNwI1cSK4qFSd67jPR/qfosTbdQ==}
|
|
976
979
|
engines: {node: '>=20.0.0'}
|
|
977
980
|
hasBin: true
|
|
978
981
|
|
|
979
|
-
'@tbox.cn/app-toolkit@0.8.
|
|
980
|
-
resolution: {integrity: sha512-
|
|
982
|
+
'@tbox.cn/app-toolkit@0.8.5':
|
|
983
|
+
resolution: {integrity: sha512-WyFbaEr8N064PFeWknfZfg5MMinEYI4xExbG2KnE4QPbvcS01NazA1vImPTidrOSXZ411PRFr/JNArS/38nv/w==}
|
|
981
984
|
engines: {node: '>=20.0.0'}
|
|
982
985
|
|
|
983
986
|
'@types/babel__core@7.20.5':
|
|
@@ -2840,19 +2843,19 @@ snapshots:
|
|
|
2840
2843
|
dependencies:
|
|
2841
2844
|
'@tbox.cn/app-contracts': 0.13.2
|
|
2842
2845
|
|
|
2843
|
-
'@tbox.cn/app-sdk-server@0.26.
|
|
2846
|
+
'@tbox.cn/app-sdk-server@0.26.4':
|
|
2844
2847
|
dependencies:
|
|
2845
2848
|
'@ag-ui/core': 0.0.47
|
|
2846
2849
|
'@tbox.cn/app-contracts': 0.13.3
|
|
2847
2850
|
'@tbox.cn/app-sdk-core': 0.20.5
|
|
2848
|
-
'@tbox.cn/app-toolkit': 0.8.
|
|
2851
|
+
'@tbox.cn/app-toolkit': 0.8.5
|
|
2849
2852
|
express: 4.22.2
|
|
2850
2853
|
jose: 6.2.8
|
|
2851
2854
|
zod: 3.25.76
|
|
2852
2855
|
transitivePeerDependencies:
|
|
2853
2856
|
- supports-color
|
|
2854
2857
|
|
|
2855
|
-
'@tbox.cn/app-toolkit@0.8.
|
|
2858
|
+
'@tbox.cn/app-toolkit@0.8.5':
|
|
2856
2859
|
dependencies:
|
|
2857
2860
|
ajv: 8.20.0
|
|
2858
2861
|
zod: 3.25.76
|
|
@@ -35,9 +35,9 @@ catalog:
|
|
|
35
35
|
"@types/express": 4.17.25
|
|
36
36
|
"@tbox.cn/app-sdk-core": 0.20.5
|
|
37
37
|
"@tbox.cn/app-sdk-client": 0.21.4
|
|
38
|
-
"@tbox.cn/app-sdk-server": 0.26.
|
|
39
|
-
"@tbox.cn/app-agent-sdk-server": 0.3.
|
|
40
|
-
"@tbox.cn/app-agent-sdk-client": 0.2.
|
|
38
|
+
"@tbox.cn/app-sdk-server": 0.26.4
|
|
39
|
+
"@tbox.cn/app-agent-sdk-server": 0.3.4
|
|
40
|
+
"@tbox.cn/app-agent-sdk-client": 0.2.2
|
|
41
41
|
"@tbox.cn/app-contracts": 0.13.3
|
|
42
42
|
"@tbox.cn/app-contracts-mall": 0.14.0
|
|
43
43
|
eslint: 9.39.5
|