Files
crypto_trading/frontend/vite.config.js
T
matitos 7b97f010c9 Self-heal a stale cached bundle via a build version
Phones kept running old JS because their cached index.html pointed at an old
hashed asset. Both images now bake the commit SHA as BUILD_VERSION; the backend
exposes it at GET /api/version and the client reloads once with a cache-busting
query when its own baked version differs. Guarded by sessionStorage so it cannot
loop. /api/version is unauthenticated like /api/health.
2026-09-21 00:16:43 +00:00

36 lines
881 B
JavaScript

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { execSync } from 'node:child_process'
// Short git SHA (or a timestamp fallback) baked into the bundle so the client
// can detect when the server is running a newer build and reload itself.
let buildVersion = process.env.VITE_BUILD_VERSION || String(Date.now())
if (!process.env.VITE_BUILD_VERSION) {
try {
buildVersion = execSync('git rev-parse --short HEAD').toString().trim()
} catch {
// not a git checkout; keep the timestamp
}
}
export default defineConfig({
define: {
__BUILD_VERSION__: JSON.stringify(buildVersion),
},
plugins: [vue()],
server: {
port: 5173,
proxy: {
'/api': {
target: 'http://localhost:8000',
changeOrigin: true,
ws: true,
},
},
},
test: {
environment: 'jsdom',
globals: true,
},
})