-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvite.config.ts
More file actions
191 lines (183 loc) · 6.05 KB
/
vite.config.ts
File metadata and controls
191 lines (183 loc) · 6.05 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
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import { VitePWA } from 'vite-plugin-pwa';
import path from 'path';
// Determine base path based on deployment target
const BASE_PATH = process.env.VERCEL ? '/' : '/TrustVault-PWA/';
// https://vitejs.dev/config/
export default defineConfig({
// CRITICAL: Set base to '/' for Vercel deployment, '/TrustVault-PWA/' for GitHub Pages
// Use VERCEL environment variable to detect Vercel deployment
base: BASE_PATH,
plugins: [
react(),
VitePWA({
registerType: 'prompt', // Changed from 'autoUpdate' to give user control
includeAssets: ['favicon.ico', 'apple-touch-icon.png', 'pwa-192x192.png', 'pwa-512x512.png'],
manifest: {
name: 'TrustVault PWA',
short_name: 'TrustVault',
description: 'Secure offline-first password manager',
theme_color: '#1976d2',
background_color: '#ffffff',
display: 'standalone',
scope: BASE_PATH,
start_url: BASE_PATH,
icons: [
{
src: 'pwa-192x192.png',
sizes: '192x192',
type: 'image/png',
purpose: 'any'
},
{
src: 'pwa-512x512.png',
sizes: '512x512',
type: 'image/png',
purpose: 'any'
},
{
src: 'pwa-maskable-192x192.png',
sizes: '192x192',
type: 'image/png',
purpose: 'maskable'
},
{
src: 'pwa-maskable-512x512.png',
sizes: '512x512',
type: 'image/png',
purpose: 'maskable'
}
]
},
workbox: {
globPatterns: ['**/*.{js,css,html,ico,png,svg,woff2,wasm}'],
runtimeCaching: [
{
urlPattern: /^https:\/\/fonts\.googleapis\.com\/.*/i,
handler: 'CacheFirst',
options: {
cacheName: 'google-fonts-cache',
expiration: {
maxEntries: 10,
maxAgeSeconds: 60 * 60 * 24 * 365 // 1 year
},
cacheableResponse: {
statuses: [0, 200]
}
}
},
// Tesseract.js WASM core and worker scripts
{
urlPattern: /^https:\/\/cdn\.jsdelivr\.net\/npm\/tesseract\.js@.*/i,
handler: 'CacheFirst',
options: {
cacheName: 'tesseract-core-cache',
expiration: {
maxEntries: 10,
maxAgeSeconds: 60 * 60 * 24 * 30 // 30 days
},
cacheableResponse: {
statuses: [0, 200]
}
}
},
// Tesseract.js language data (eng.traineddata ~15MB)
{
urlPattern: /^https:\/\/cdn\.jsdelivr\.net\/npm\/tesseract\.js-data@.*/i,
handler: 'CacheFirst',
options: {
cacheName: 'tesseract-lang-cache',
expiration: {
maxEntries: 5,
maxAgeSeconds: 60 * 60 * 24 * 90 // 90 days
},
cacheableResponse: {
statuses: [0, 200]
}
}
},
// Tesseract.js WASM core from tessdata CDN
{
urlPattern: /^https:\/\/cdn\.jsdelivr\.net\/npm\/tesseract\.js-core@.*/i,
handler: 'CacheFirst',
options: {
cacheName: 'tesseract-wasm-cache',
expiration: {
maxEntries: 5,
maxAgeSeconds: 60 * 60 * 24 * 90 // 90 days
},
cacheableResponse: {
statuses: [0, 200]
}
}
}
],
skipWaiting: false, // Don't auto-skip waiting - let user control it
clientsClaim: false, // Don't auto-claim clients
// Inject custom code for version and message handling
navigateFallback: null,
additionalManifestEntries: undefined,
},
// Inject version constant into generated SW
useCredentials: false,
devOptions: {
enabled: true
}
})
],
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
}
},
optimizeDeps: {
exclude: ['argon2-browser']
},
build: {
target: 'esnext',
outDir: 'dist',
sourcemap: false,
minify: 'terser',
terserOptions: {
compress: {
drop_console: true,
drop_debugger: true
}
},
rollupOptions: {
output: {
manualChunks: {
'react-vendor': ['react', 'react-dom', 'react-router-dom'],
'mui-vendor': ['@mui/material', '@mui/icons-material'],
'storage-vendor': ['dexie'],
'security-vendor': ['@noble/hashes']
}
}
}
},
server: {
port: 3000,
strictPort: false,
headers: {
'X-Content-Type-Options': 'nosniff',
'X-Frame-Options': 'DENY',
'X-XSS-Protection': '1; mode=block',
'Referrer-Policy': 'strict-origin-when-cross-origin',
'Permissions-Policy': 'camera=(self), microphone=(), geolocation=()',
'Content-Security-Policy': "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval' https://cdn.jsdelivr.net; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; font-src 'self' https://fonts.gstatic.com; img-src 'self' data: blob:; connect-src 'self' https://cdn.jsdelivr.net; worker-src 'self' blob:;"
}
},
preview: {
port: 4173,
strictPort: false,
headers: {
'X-Content-Type-Options': 'nosniff',
'X-Frame-Options': 'DENY',
'X-XSS-Protection': '1; mode=block',
'Referrer-Policy': 'strict-origin-when-cross-origin',
'Permissions-Policy': 'camera=(self), microphone=(), geolocation=()',
'Content-Security-Policy': "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval' https://cdn.jsdelivr.net; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; font-src 'self' https://fonts.gstatic.com; img-src 'self' data: blob:; connect-src 'self' https://cdn.jsdelivr.net; worker-src 'self' blob:;"
}
}
});