-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathvite.config.ts
More file actions
308 lines (284 loc) Β· 12.3 KB
/
Copy pathvite.config.ts
File metadata and controls
308 lines (284 loc) Β· 12.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
import path from 'node:path';
import { codecovVitePlugin } from '@codecov/vite-plugin';
import tailwindcss from '@tailwindcss/vite';
import react from '@vitejs/plugin-react';
import { visualizer } from 'rollup-plugin-visualizer';
import { defineConfig } from 'vite';
import { VitePWA } from 'vite-plugin-pwa';
import { GITHUB_PAGES_BASE, isTauriBuild, resolveViteBase } from './config/resolveViteBase';
const isAnalyze = process.env['ANALYZE'] === 'true';
// QNBS-v3: explicit CI-only flag β bundle upload never fires merely because CODECOV_TOKEN happens to be set locally.
const enableCodecovBundleAnalysis = process.env['CODECOV_BUNDLE_ANALYSIS'] === 'true';
const codecovToken = process.env['CODECOV_TOKEN'] || undefined;
const codecovBundleSha = process.env['CODECOV_BUNDLE_SHA'] || undefined;
const deployBase = resolveViteBase();
const isTauri = isTauriBuild();
export default defineConfig({
base: deployBase,
// Default dependency crawl uses every *.html under the repo; reports (Playwright, Storybook, etc.) are not app entries and can break `vite dev`.
optimizeDeps: {
entries: [path.resolve(__dirname, 'index.html')],
},
server: {
port: 3000,
// QNBS-v3: Default to loopback for security; opt-in to 0.0.0.0 via VITE_DEV_HOST for Codespaces.
host: process.env['VITE_DEV_HOST'] || '127.0.0.1',
},
preview: {
port: 4173,
host: process.env['VITE_DEV_HOST'] || '127.0.0.1',
},
plugins: [
tailwindcss(),
react(),
{
name: 'worldscript-deploy-base-html',
transformIndexHtml(html) {
if (deployBase === GITHUB_PAGES_BASE) return html;
// QNBS-v3: only rewrite app-relative paths (preceded by quote/space) so
// absolute URLs like https://worldscript-studio.app/WorldScript-Studio/
// are not corrupted when deployBase is './'.
return html.replace(/(?<=["'\s])\/WorldScript-Studio\//g, deployBase);
},
},
VitePWA({
// register-sw.ts handles manual registration
injectRegister: false,
registerType: 'prompt',
// public/sw.js is preserved; VitePWA only injects the precache manifest list
strategies: 'injectManifest',
srcDir: 'public',
filename: 'sw.js',
// QNBS-v3: inlineDynamicImports: false prevents dynamic imports from being inlined into the SW bundle
// (Workbox 7.x uses this property; VitePWA will warn but it's the correct option)
injectManifest: {
maximumFileSizeToCacheInBytes: 8 * 1024 * 1024,
globPatterns: [
'**/*.{js,css,html,svg,ico,woff,woff2,png,webp}',
'community-templates/**/*.json',
'locales/**/bundle.json',
],
// QNBS-v3: Exclude heavy optional chunks from SW precache β loaded lazily when flag=on.
// vendor-ai-core is now the small orchestration layer and can be precached.
globIgnores: [
'**/vendor-duckdb*',
'**/vendor-webllm*',
'**/vendor-onnx*',
'**/vendor-transformers*',
'**/vendor-voice-wasm*',
'**/*.wasm',
// QNBS-v3 (F-09): self-hosted duckdb-wasm *.worker.js (scripts/copy-duckdb-assets.mjs) matches the **/*.js allowlist above unlike the already-excluded *.wasm β exclude explicitly, same feature-flag-gated reasoning as vendor-duckdb*.
'**/duckdb/**',
],
},
// Manifest bereits in public/manifest.json eingebunden
manifest: false,
}),
...(isAnalyze
? [
visualizer({
open: process.env['CI'] !== 'true',
filename: 'dist/bundle-analysis.html',
gzipSize: true,
brotliSize: true,
}),
]
: []),
// QNBS-v3: Codecov docs require this plugin to run last; only enabled for the CI analysis build, never local `pnpm run build`/`analyze`.
codecovVitePlugin({
enableBundleAnalysis: enableCodecovBundleAnalysis,
bundleName: 'worldscript-studio-web',
gitService: 'github',
telemetry: false,
// QNBS-v3: exactOptionalPropertyTypes forbids passing `undefined` for an optional string key β omit it entirely instead of assigning undefined (fork PRs run tokenless).
...(codecovToken ? { uploadToken: codecovToken } : {}),
...(codecovBundleSha ? { uploadOverrides: { sha: codecovBundleSha } } : {}),
}),
],
resolve: {
alias: {
'@': path.resolve(__dirname, '.'),
// QNBS-v3: @huggingface/transformers (transformers.js v3) lives in packages/ai-core; Rolldown
// can't hoist it from a nested workspace node_modules. Alias mirrors the vitest.config.ts fix.
// v3 ships a bundled web entry at dist/transformers.web.js (no src/ in the published package).
'@huggingface/transformers': path.resolve(
__dirname,
'./packages/ai-core/node_modules/@huggingface/transformers/dist/transformers.web.js',
),
// QNBS-v3: B-3 vendor fork β resolve @domain/collab-transport to the workspace package source
'@domain/collab-transport': path.resolve(
__dirname,
'./packages/collab-transport/src/index.ts',
),
// QNBS-v3: WorkerBus v2 β resolve workspace package for production builds (mirrors vitest alias)
'@domain/worker-bus': path.resolve(__dirname, './packages/worker-bus/src/index.ts'),
// QNBS-v3: Wave 1 DesktopPlatform contract β resolve workspace package for production builds (mirrors vitest alias)
'@domain/desktop-contracts': path.resolve(
__dirname,
'./packages/desktop-contracts/src/index.ts',
),
},
},
build: {
target: 'es2022',
minify: 'esbuild',
sourcemap: false,
cssCodeSplit: true,
chunkSizeWarningLimit: 600,
reportCompressedSize: true,
modulePreload: {
polyfill: false,
resolveDependencies: (_filename: string, deps: string[]) =>
deps.filter(
(d) =>
!/ai-vendor|ai-sdk-vendor|export-vendor|data-vendor|collaboration-vendor|plot-board|canvas-vendor|vendor-duckdb|vendor-ai-onnx|vendor-webllm|vendor-onnx|vendor-transformers|vendor-voice-wasm|vendor-ai-core/.test(
d,
),
),
},
rollupOptions: {
// QNBS-v3: externalizing @tauri-apps/* must NOT apply to the Tauri desktop build itself β
// services/localServerHttp.ts's dynamic `await import('@tauri-apps/plugin-http')` would be
// left as an unresolvable bare specifier in the packaged .deb/.msi, silently breaking local
// Ollama/LM Studio/vLLM discovery (see docs/adr/0012-local-server-connectivity-tauri-http.md).
// Web/Vercel builds still externalize them β those code paths are gated by isTauriRuntime()
// and never exercised there.
external: isTauri ? [] : [/^@tauri-apps\//],
output: {
// Asset hashing for cache busting
entryFileNames: 'assets/[name]-[hash].js',
chunkFileNames: 'assets/[name]-[hash].js',
assetFileNames: 'assets/[name]-[hash][extname]',
// Code splitting for better load times
manualChunks: (id) => {
// QNBS-v3: Workspace packages - handle before node_modules check
// Proxy entry files for heavy AI runtimes β route to dedicated chunks.
if (id.includes('packages/ai-core/src/vendor-webllm')) {
return 'vendor-webllm';
}
if (id.includes('packages/ai-core/src/vendor-transformers')) {
return 'vendor-transformers';
}
if (id.includes('packages/ai-core/src/vendor-onnx')) {
return 'vendor-onnx';
}
// QNBS-v3: Heavy AI runtimes route to dedicated lazy chunks. These MUST match BEFORE the
// @domain/ai-core source catch-all below β otherwise deps resolved under
// packages/ai-core/node_modules/* get swept into the precacheable vendor-ai-core chunk,
// re-bloating it and defeating lazy-loading (CodeAnt PR #130). The generic
// `node_modules/<pkg>` substring already covers the packages/ai-core/node_modules/<pkg> case.
// WebLLM runtime (~4-5 MB uncompressed) β lazy-loaded when local GPU inference is requested.
if (id.includes('.pnpm/@mlc-ai+web-llm') || id.includes('node_modules/@mlc-ai/web-llm')) {
return 'vendor-webllm';
}
// ONNX Runtime Web (~0.5 MB uncompressed) β shared by transformers.js and the ONNX engine.
if (id.includes('.pnpm/onnxruntime-web') || id.includes('node_modules/onnxruntime-web')) {
return 'vendor-onnx';
}
// Transformers.js (~1 MB uncompressed) β lazy-loaded for WASM text-generation fallback.
if (
id.includes('.pnpm/@huggingface+transformers') ||
id.includes('node_modules/@huggingface/transformers')
) {
return 'vendor-transformers';
}
// @domain/ai-core source code (orchestration, tab leader, model lists) β small and
// precacheable. Heavy runtimes are already routed above, so this only captures ai-core
// source plus any lightweight deps it pulls in.
if (id.includes('packages/ai-core') || id.includes('.pnpm/@domain+ai-core')) {
return 'vendor-ai-core';
}
if (id.includes('packages/collab-transport')) {
return 'collaboration-vendor';
}
if (id.includes('packages/worker-bus')) {
return 'worker-bus';
}
if (id.includes('packages/ui')) {
return 'ui-vendor';
}
// QNBS-v3: Scene board chunk
if (id.includes('components/scene-board/') || id.includes('SceneBoardView')) {
return 'plot-board';
}
// QNBS-v3: Voice WASM engines - lazy-loaded when enableVoiceWasm=on
if (
id.includes('services/voice/wasmSttEngine') ||
id.includes('services/voice/sileroVadEngine')
) {
return 'vendor-voice-wasm';
}
// QNBS-v3: LoRA feature chunk - lazy-loaded
if (
id.includes('features/lora/') ||
id.includes('components/lora/') ||
id.includes('services/lora/')
) {
return 'lora-feature';
}
// QNBS-v3: Plugin worker - isolated execution context
if (id.includes('workers/plugin.worker')) {
return 'plugin-worker';
}
// QNBS-v3: Only apply node_modules chunking for non-workspace packages.
// Workspace packages (packages/*) are handled above.
if (!id?.includes('node_modules')) return undefined;
// React vendor
if (id.includes('/react-dom/') || id.includes('/react/')) {
return 'react-vendor';
}
// Redux vendor
if (
id.includes('@reduxjs') ||
id.includes('/react-redux/') ||
id.includes('/redux-undo/')
) {
return 'redux-vendor';
}
// AI vendors
if (id.includes('@google/genai')) {
return 'ai-vendor';
}
// QNBS-v3: Vercel AI SDK + provider packages bundled together
if (
id.includes('node_modules/ai/') ||
id.includes('/node_modules/ai/') ||
id.includes('@ai-sdk/')
) {
return 'ai-sdk-vendor';
}
// Collaboration vendor (yjs, y-webrtc)
if (id.includes('y-webrtc') || id.includes('yjs')) {
return 'collaboration-vendor';
}
// Interaction vendor
if (id.includes('@dnd-kit') || id.includes('/dnd-kit/')) {
return 'interaction-vendor';
}
// Data vendor
if (id.includes('recharts') || id.includes('react-force-graph-2d')) {
return 'data-vendor';
}
// Export vendors
if (id.includes('/jspdf/')) {
return 'export-vendor-pdf';
}
if (id.includes('/docx/') || id.includes('/jszip/') || id.includes('mammoth')) {
return 'export-vendor-docx-ebook';
}
// QNBS-v3: DuckDB-WASM bundle is ~2 MB gzip; isolate for SW cache exclusion
if (id.includes('@duckdb/duckdb-wasm')) {
return 'vendor-duckdb';
}
return undefined;
},
},
},
// QNBS-v3: Rolldown code splitting optimization for Vite 8
rolldownOptions: {
output: {
codeSplitting: true,
},
},
},
});