-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
106 lines (103 loc) · 3.32 KB
/
Copy pathvite.config.ts
File metadata and controls
106 lines (103 loc) · 3.32 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
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import { VitePWA } from 'vite-plugin-pwa';
import { readFileSync } from 'node:fs';
const pkg = JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf-8')) as {
version: string;
};
// COOP/COEP headers are required for SharedArrayBuffer (multi-threaded WASM in
// onnxruntime-web). They're set during dev/preview here. For static hosting
// (e.g. GitHub Pages) we additionally ship coi-serviceworker as a fallback so
// the app can self-promote to a cross-origin-isolated context.
const crossOriginIsolationHeaders = {
'Cross-Origin-Opener-Policy': 'same-origin',
'Cross-Origin-Embedder-Policy': 'require-corp',
'Cross-Origin-Resource-Policy': 'same-origin',
};
export default defineConfig({
define: {
__APP_VERSION__: JSON.stringify(pkg.version),
},
plugins: [
react(),
VitePWA({
registerType: 'autoUpdate',
injectRegister: 'auto',
strategies: 'generateSW',
includeAssets: ['favicon.svg', 'coi-serviceworker.min.js'],
manifest: {
name: 'TAMIAS — Transparent locAl Medical Image AnalysiS',
short_name: 'TAMIAS',
description:
'Browser-only medical image analysis. Runs ONNX models on local DICOM/NIfTI files via WebGPU. No upload.',
theme_color: '#0b1d3a',
background_color: '#ffffff',
display: 'standalone',
start_url: '/',
scope: '/',
icons: [
{
src: 'icons/icon-192.png',
sizes: '192x192',
type: 'image/png',
purpose: 'any maskable',
},
{
src: 'icons/icon-512.png',
sizes: '512x512',
type: 'image/png',
purpose: 'any maskable',
},
],
},
workbox: {
// Precache only the small, always-needed shell. WASM (25+ MB ORT
// bundle) and large model files are deliberately fetched on demand
// via runtimeCaching, so the first install pays only ~1 MB.
globPatterns: ['**/*.{js,css,html,ico,png,svg,json,webmanifest}'],
// Some shell assets (sourcemaps in dev builds, large JS chunks) can
// breach the default 2 MB cap; lift it to 8 MB so precache succeeds.
maximumFileSizeToCacheInBytes: 8 * 1024 * 1024,
navigateFallback: 'index.html',
runtimeCaching: [
{
// Lazily cache ORT WASM/JSEP on first inference run.
urlPattern: ({ url }) => url.pathname.endsWith('.wasm'),
handler: 'CacheFirst',
options: {
cacheName: 'wasm-cache',
expiration: { maxEntries: 32, maxAgeSeconds: 60 * 60 * 24 * 90 },
cacheableResponse: { statuses: [0, 200] },
},
},
],
},
}),
],
server: {
headers: crossOriginIsolationHeaders,
fs: { strict: true },
},
preview: {
headers: crossOriginIsolationHeaders,
},
worker: {
format: 'es',
},
optimizeDeps: {
// ORT ships its own WASM/glue; pre-bundling breaks the worker imports.
exclude: ['onnxruntime-web'],
},
build: {
target: 'es2022',
sourcemap: true,
rollupOptions: {
output: {
manualChunks: {
niivue: ['@niivue/niivue'],
ort: ['onnxruntime-web'],
},
},
},
},
});