-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
147 lines (142 loc) · 5.17 KB
/
vite.config.ts
File metadata and controls
147 lines (142 loc) · 5.17 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
import { defineConfig } from 'vite';
import { svelte } from '@sveltejs/vite-plugin-svelte';
import { VitePWA } from 'vite-plugin-pwa';
import { execSync } from 'child_process';
const host = process.env.TAURI_DEV_HOST;
function git(cmd: string): string {
try { return execSync(`git ${cmd}`, { encoding: 'utf-8' }).trim(); }
catch { return ''; }
}
const commitHash = git('rev-parse --short HEAD');
const commitDate = git('log -1 --format=%ci');
function buttplugWasmPlugin() {
const VIRTUAL_ENV = '\0wasm-env';
const VIRTUAL_WS = '\0stub-ws';
return {
name: 'buttplug-wasm-stubs',
resolveId(id: string) {
if (id === 'env') return VIRTUAL_ENV;
if (id === 'ws') return VIRTUAL_WS;
},
load(id: string) {
if (id === VIRTUAL_ENV) return 'export function now() { return performance.now(); }';
if (id === VIRTUAL_WS) return 'export const WebSocket = globalThis.WebSocket;';
},
};
}
export default defineConfig({
clearScreen: false,
define: {
__COMMIT_HASH__: JSON.stringify(commitHash),
__COMMIT_DATE__: JSON.stringify(commitDate),
__FORCED_TEXTURE_QUALITY__: JSON.stringify(process.env.VITE_TEXTURE_QUALITY || ''),
__DATA_MIRROR__: JSON.stringify(process.env.VITE_DATA_MIRROR || ''),
__CELESTRAK_BASE__: JSON.stringify(process.env.VITE_CELESTRAK_BASE || ''),
__SATNOGS_BASE__: JSON.stringify(process.env.VITE_SATNOGS_BASE || ''),
__TLE_CACHE_MAX_AGE_H__: JSON.stringify(Number(process.env.VITE_TLE_CACHE_MAX_AGE_H) || 1),
__TLE_CACHE_EVICT_AGE_H__: JSON.stringify(Number(process.env.VITE_TLE_CACHE_EVICT_AGE_H) || 24),
__FEEDBACK_TOYS__: JSON.stringify(process.env.VITE_FEEDBACK_TOYS !== 'false'),
},
optimizeDeps: {
exclude: ['@satvisorcom/buttplug-wasm'],
include: ['eventemitter3'],
},
server: {
port: 1420,
strictPort: true,
host: host || false,
watch: { ignored: ['**/src-tauri/**'] },
},
build: {
rollupOptions: {
output: {
manualChunks: {
three: ['three'],
},
},
},
},
plugins: [
{
name: 'html-texture-quality',
transformIndexHtml(html) {
return html.replace(/%VITE_TEXTURE_QUALITY%/g, process.env.VITE_TEXTURE_QUALITY || '');
},
},
buttplugWasmPlugin(),
svelte(),
VitePWA({
registerType: 'autoUpdate',
injectRegister: false,
manifest: {
name: 'Satvisor',
short_name: 'Satvisor',
description: '3D satellite tracker with pass predictions, antenna rotator control, sky view, and Doppler analysis. Free, open source, runs in your browser.',
theme_color: '#101010',
background_color: '#101010',
display: 'standalone',
icons: [
{ src: '/textures/icons/icon-192.png', sizes: '192x192', type: 'image/png', purpose: 'any' },
{ src: '/textures/icons/icon-512.png', sizes: '512x512', type: 'image/png', purpose: 'any' },
{ src: '/textures/icons/icon-maskable-192.png', sizes: '192x192', type: 'image/png', purpose: 'maskable' },
{ src: '/textures/icons/icon-maskable-512.png', sizes: '512x512', type: 'image/png', purpose: 'maskable' },
]
},
workbox: {
clientsClaim: true,
skipWaiting: true,
globPatterns: ['**/*.{js,css,png,jpg,ttf,json}'],
globIgnores: [
'**/textures/icons/**',
'**/buttplug_wasm*',
// In lite mode, don't precache full-size country grid
...(process.env.VITE_TEXTURE_QUALITY === 'lite' ? ['**/countries-110m.json'] : ['**/countries-110m.lite.json']),
// Never precache elevation.bin (18MB, loaded lazily and skipped in lite)
'**/elevation.bin',
],
maximumFileSizeToCacheInBytes: 5 * 1024 * 1024,
// Don't auto-create a NavigationRoute that serves precached index.html
// — we add our own NetworkFirst navigation rule below
navigationPreload: true,
navigateFallbackDenylist: [/./],
runtimeCaching: [
{
// Navigation requests: always try network first so deploys are picked up immediately.
// Falls back to cache when offline (3s timeout).
urlPattern: ({ request }) => request.mode === 'navigate',
handler: 'NetworkFirst',
options: {
cacheName: 'pages-cache',
networkTimeoutSeconds: 1,
}
},
{
urlPattern: process.env.VITE_CELESTRAK_BASE
? new RegExp(`^${process.env.VITE_CELESTRAK_BASE.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}`)
: /^https:\/\/celestrak\.org\//,
handler: 'NetworkFirst',
options: {
cacheName: 'tle-data-cache',
expiration: { maxAgeSeconds: 86400 }
}
},
{
urlPattern: /\/data\//,
handler: 'StaleWhileRevalidate',
options: {
cacheName: 'data-cache',
}
},
{
urlPattern: /\/textures\/.*\.webp$/,
handler: 'StaleWhileRevalidate',
options: {
cacheName: 'texture-cache',
expiration: { maxEntries: 60 }
}
}
]
}
})
]
});