Bakes the git short commit hash into the client bundle at build time and exposes the same info from the server via GET /api/version. The header displays the loaded build's commit and flags when it no longer matches what the server is running, so a stale open tab is easy to spot after a deploy. The Docker build now includes .git so the hash can be resolved during the image build. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
83 lines
2.1 KiB
TypeScript
83 lines
2.1 KiB
TypeScript
import { execSync } from 'node:child_process';
|
|
import { defineConfig } from 'vite';
|
|
import react from '@vitejs/plugin-react';
|
|
import { VitePWA } from 'vite-plugin-pwa';
|
|
|
|
function getCommit(): string {
|
|
try {
|
|
return execSync('git rev-parse --short HEAD').toString().trim();
|
|
} catch {
|
|
return 'dev';
|
|
}
|
|
}
|
|
|
|
export default defineConfig({
|
|
define: {
|
|
__APP_VERSION__: JSON.stringify({ commit: getCommit(), builtAt: new Date().toISOString() }),
|
|
},
|
|
plugins: [
|
|
react(),
|
|
VitePWA({
|
|
registerType: 'autoUpdate',
|
|
injectRegister: false,
|
|
devOptions: {
|
|
enabled: false,
|
|
},
|
|
manifest: {
|
|
name: 'CityTracker',
|
|
short_name: 'CityTracker',
|
|
description: "Track cities you've visited or plan to visit on a map.",
|
|
start_url: '/',
|
|
scope: '/',
|
|
display: 'standalone',
|
|
theme_color: '#1971c2',
|
|
background_color: '#f7f7f5',
|
|
icons: [
|
|
{
|
|
src: '/pwa-192x192.png',
|
|
sizes: '192x192',
|
|
type: 'image/png',
|
|
},
|
|
{
|
|
src: '/pwa-512x512.png',
|
|
sizes: '512x512',
|
|
type: 'image/png',
|
|
},
|
|
{
|
|
src: '/maskable-512x512.png',
|
|
sizes: '512x512',
|
|
type: 'image/png',
|
|
purpose: 'maskable',
|
|
},
|
|
],
|
|
},
|
|
workbox: {
|
|
// /api and /uploads are intentionally left uncached so city data and
|
|
// photos always come from the network, never a stale service worker cache.
|
|
runtimeCaching: [
|
|
{
|
|
urlPattern: /^https:\/\/[abc]\.tile\.openstreetmap\.org\/.*/,
|
|
handler: 'CacheFirst',
|
|
options: {
|
|
cacheName: 'osm-tiles',
|
|
expiration: {
|
|
maxEntries: 500,
|
|
maxAgeSeconds: 60 * 60 * 24 * 7,
|
|
},
|
|
},
|
|
},
|
|
],
|
|
},
|
|
}),
|
|
],
|
|
server: {
|
|
port: 5173,
|
|
proxy: {
|
|
'/api': 'http://localhost:3000',
|
|
'/uploads': 'http://localhost:3000',
|
|
},
|
|
},
|
|
build: {
|
|
outDir: 'dist',
|
|
},
|
|
});
|