@allbluecn/web-app 0.4.5 → 0.4.7
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/package.json +15 -8
- package/vite.shared.ts +135 -0
package/package.json
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@allbluecn/web-app",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.7",
|
|
4
4
|
"license": "AGPL-3.0-or-later",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
7
7
|
"src",
|
|
8
|
-
"public"
|
|
8
|
+
"public",
|
|
9
|
+
"vite.shared.ts"
|
|
9
10
|
],
|
|
11
|
+
"exports": {
|
|
12
|
+
"./vite.shared": {
|
|
13
|
+
"types": "./vite.shared.ts",
|
|
14
|
+
"default": "./vite.shared.ts"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
10
17
|
"publishConfig": {
|
|
11
18
|
"access": "public"
|
|
12
19
|
},
|
|
@@ -123,14 +130,14 @@
|
|
|
123
130
|
"three": "^0.180.0",
|
|
124
131
|
"tw-animate-css": "^1.4.0",
|
|
125
132
|
"zod": "^4.4.3",
|
|
126
|
-
"@allbluecn/ai-gateway": "0.4.
|
|
127
|
-
"@allbluecn/database": "0.4.
|
|
133
|
+
"@allbluecn/ai-gateway": "0.4.7",
|
|
134
|
+
"@allbluecn/database": "0.4.7",
|
|
128
135
|
"@allbluecn/prototype": "0.1.1",
|
|
129
|
-
"@allbluecn/shared": "0.4.
|
|
136
|
+
"@allbluecn/shared": "0.4.7",
|
|
130
137
|
"@allbluecn/kernel": "0.3.0",
|
|
131
|
-
"@allbluecn/
|
|
132
|
-
"@allbluecn/
|
|
133
|
-
"@allbluecn/
|
|
138
|
+
"@allbluecn/plugins-core": "0.4.7",
|
|
139
|
+
"@allbluecn/tiptap": "0.4.7",
|
|
140
|
+
"@allbluecn/ui": "0.4.7"
|
|
134
141
|
},
|
|
135
142
|
"devDependencies": {
|
|
136
143
|
"@babel/parser": "^8.0.4",
|
package/vite.shared.ts
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
2
|
+
// AllBlue - 理想之海
|
|
3
|
+
// Copyright (C) 2026 AllBlue Contributors
|
|
4
|
+
//
|
|
5
|
+
// This program is free software: you can redistribute it and/or modify
|
|
6
|
+
// it under the terms of the GNU Affero General Public License as published by
|
|
7
|
+
// the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
// (at your option) any later version.
|
|
9
|
+
//
|
|
10
|
+
// This program is distributed in the hope that it will be useful,
|
|
11
|
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
// GNU Affero General Public License for more details.
|
|
14
|
+
//
|
|
15
|
+
// You should have received a copy of the GNU Affero General Public License
|
|
16
|
+
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
17
|
+
|
|
18
|
+
// AllBlue web 端 Vite 配置共享工厂(单一事实源)。
|
|
19
|
+
// 主仓库 apps/web/vite.config.ts 与 AllBlue-Pro apps/web-saas/vite.config.ts
|
|
20
|
+
// 均为调用本工厂的薄壳。
|
|
21
|
+
//
|
|
22
|
+
// ⚠ 插件注入设计:本文件**不 import** 任何 Vite 插件包(tanstackStart/viteReact/
|
|
23
|
+
// tailwindcss)。插件实例必须由调用方从「与 vite 本体同源的 node_modules」import
|
|
24
|
+
// 后经 basePlugins 注入——否则(如 web-saas 经 vendor 物理路径加载本文件时)
|
|
25
|
+
// 插件解析到 vendor 的另一份实例,与 vite 跨实例失配,SSR 中间件静默不注册
|
|
26
|
+
// (表现:所有路由 404 Cannot GET)。
|
|
27
|
+
//
|
|
28
|
+
// DEPLOY_TARGET 分支(vercel/cloudflare/desktop)内的 nitro/cloudflare 动态
|
|
29
|
+
// import 仅主仓库使用;web-saas 不得设置 DEPLOY_TARGET。
|
|
30
|
+
|
|
31
|
+
import { defineConfig, type PluginOption } from 'vite'
|
|
32
|
+
import path from 'node:path'
|
|
33
|
+
|
|
34
|
+
function prismaDirnamePolyfill(rootDir: string): PluginOption {
|
|
35
|
+
return {
|
|
36
|
+
name: 'prisma-dirname-polyfill',
|
|
37
|
+
async closeBundle() {
|
|
38
|
+
const { readdir, readFile, writeFile } = await import('node:fs/promises')
|
|
39
|
+
const polyfill = `import{fileURLToPath as __f2p}from"node:url";import{dirname as __dn}from"node:path";var __dirname=__dn(__f2p(import.meta.url)),__filename=__f2p(import.meta.url);\n`
|
|
40
|
+
const ssrDir = path.resolve(rootDir, '.vercel/output/functions/__server.func/_ssr')
|
|
41
|
+
try {
|
|
42
|
+
const files = await readdir(ssrDir)
|
|
43
|
+
for (const f of files) {
|
|
44
|
+
if (!f.startsWith('database-') || !f.endsWith('.mjs')) continue
|
|
45
|
+
const fp = path.join(ssrDir, f)
|
|
46
|
+
let code = await readFile(fp, 'utf8')
|
|
47
|
+
if (code.includes('__dirname')) {
|
|
48
|
+
await writeFile(fp, polyfill + code)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
} catch {}
|
|
52
|
+
},
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function tiptapAliasPlugin(rootDir: string): PluginOption {
|
|
57
|
+
const tiptapSrc = path.resolve(rootDir, '../../packages/tiptap/src')
|
|
58
|
+
return {
|
|
59
|
+
name: 'tiptap-alias',
|
|
60
|
+
resolveId(id, importer) {
|
|
61
|
+
if (!id.startsWith('@/')) return undefined
|
|
62
|
+
if (!importer || !importer.includes('/packages/tiptap/')) return undefined
|
|
63
|
+
return path.resolve(tiptapSrc, id.slice(2))
|
|
64
|
+
},
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface WebViteConfigOptions {
|
|
69
|
+
/** config 所在目录(传 import.meta.dirname),alias 与构建产物路径的解析基准 */
|
|
70
|
+
rootDir: string
|
|
71
|
+
/** @desktop alias 相对 rootDir 的路径(主仓库 '../desktop/src';web-saas 指向 vendor 内 desktop 源码) */
|
|
72
|
+
desktopAlias: string
|
|
73
|
+
/** 基础插件链(顺序:tailwindcss → tanstackStart → viteReact),由调用方从本地 node_modules import 注入 */
|
|
74
|
+
basePlugins: PluginOption[]
|
|
75
|
+
/** 调用方可追加的 resolve.alias 映射(会覆盖/合并工厂默认 alias),用于 Pro 等派生端注入 stub 或额外 alias */
|
|
76
|
+
extraAliases?: Record<string, string>
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function createWebViteConfig(opts: WebViteConfigOptions) {
|
|
80
|
+
return defineConfig(async () => {
|
|
81
|
+
const deployTarget = process.env.DEPLOY_TARGET
|
|
82
|
+
const plugins: PluginOption[] = [...opts.basePlugins, tiptapAliasPlugin(opts.rootDir)]
|
|
83
|
+
|
|
84
|
+
if (deployTarget === 'vercel') {
|
|
85
|
+
const { nitro } = await import('nitro/vite')
|
|
86
|
+
plugins.splice(2, 0, nitro({ preset: 'vercel' }))
|
|
87
|
+
plugins.push(prismaDirnamePolyfill(opts.rootDir))
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (deployTarget === 'cloudflare') {
|
|
91
|
+
const { cloudflare } = await import('@cloudflare/vite-plugin')
|
|
92
|
+
plugins.splice(0, 0, cloudflare({ viteEnvironment: { name: 'ssr' } }))
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (deployTarget === 'desktop') {
|
|
96
|
+
const { nitro } = await import('nitro/vite')
|
|
97
|
+
plugins.splice(2, 0, nitro({ preset: 'node-server' }))
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return {
|
|
101
|
+
define: {
|
|
102
|
+
'import.meta.env.VITE_DEPLOY_TARGET': JSON.stringify(
|
|
103
|
+
process.env.DEPLOY_TARGET ?? 'web',
|
|
104
|
+
),
|
|
105
|
+
},
|
|
106
|
+
server: {
|
|
107
|
+
port: 3000,
|
|
108
|
+
allowedHosts: ['192.168.106.16', '192.168.106.223', 'localhost'],
|
|
109
|
+
cors: { origin: false },
|
|
110
|
+
},
|
|
111
|
+
plugins,
|
|
112
|
+
resolve: {
|
|
113
|
+
alias: {
|
|
114
|
+
'@': path.resolve(opts.rootDir, './src'),
|
|
115
|
+
'@desktop': path.resolve(opts.rootDir, opts.desktopAlias),
|
|
116
|
+
...(opts.extraAliases ?? {}),
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
optimizeDeps: {
|
|
120
|
+
exclude: ['@allbluecn/ai-gateway', '@allbluecn/database', '@allbluecn/shared', '@allbluecn/ui', '@allbluecn/plugins-core'],
|
|
121
|
+
include: ['@tanstack/react-router'],
|
|
122
|
+
},
|
|
123
|
+
ssr: {
|
|
124
|
+
noExternal: [
|
|
125
|
+
'@allbluecn/ai-gateway',
|
|
126
|
+
'@allbluecn/ui',
|
|
127
|
+
'@allbluecn/shared',
|
|
128
|
+
'@allbluecn/database',
|
|
129
|
+
'@allblue/devtools',
|
|
130
|
+
'@allbluecn/plugins-core',
|
|
131
|
+
],
|
|
132
|
+
},
|
|
133
|
+
}
|
|
134
|
+
})
|
|
135
|
+
}
|