-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathvite.config.ts
More file actions
59 lines (57 loc) · 1.91 KB
/
Copy pathvite.config.ts
File metadata and controls
59 lines (57 loc) · 1.91 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
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import tailwindcss from '@tailwindcss/vite';
import { VitePWA } from 'vite-plugin-pwa';
// https://vite.dev/config/
export default defineConfig({
plugins: [
react(),
tailwindcss(),
VitePWA({
registerType: 'autoUpdate',
// Use the existing manifest.json in public/
manifest: false,
workbox: {
// Precache ONLY small app-shell assets (JS/CSS/HTML/icons).
// DO NOT include .wasm or .onnx here — they are large (12–26 MB each)
// and would cause the Service Worker install to time out.
// They are handled below with lazy runtime caching instead.
globPatterns: ['**/*.{js,css,html,ico,svg,gif,png}'],
// Runtime caching: WASM and ONNX files are cached on first use
// (CacheFirst) so subsequent offline scans load instantly.
runtimeCaching: [
{
urlPattern: /\/models\/.*\.onnx$/i,
handler: 'CacheFirst',
options: {
cacheName: 'onnx-models',
expiration: { maxAgeSeconds: 30 * 24 * 60 * 60 }, // 30 days
cacheableResponse: { statuses: [0, 200] },
},
},
{
urlPattern: /.*\.wasm$/i,
handler: 'CacheFirst',
options: {
cacheName: 'wasm-cache',
expiration: { maxAgeSeconds: 30 * 24 * 60 * 60 },
cacheableResponse: { statuses: [0, 200] },
},
},
],
},
}),
],
server: {
// In local dev, proxy /api/* to the FastAPI backend at :8000.
// This avoids CORS issues and means the frontend never needs to
// hard-code the backend port.
// In production, VITE_API_URL is set externally so this block is unused.
proxy: {
'/api': {
target: 'http://localhost:8000',
changeOrigin: true,
},
},
},
});