import react from '@vitejs/plugin-react';
import { defineConfig } from 'vite';
import { VitePWA } from 'vite-plugin-pwa';
import { visualizer } from 'rollup-plugin-visualizer';
import { rtlTextAlias, plyrSpriteAlias } from './rtlTextAlias.js';
import { readFileSync } from 'node:fs';
// The version this bundle is built as, baked in at build time. The release image
// bumps every package.json before it builds, so this matches the server's
// APP_VERSION there; a source checkout matches the server's own package.json.
// The server hands the release notice only to a bundle built for its version.
const UI_VERSION = JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf8')).version;
// `npm run build:analyze` writes dist/stats.html — a treemap of what actually ended
// up in each chunk. The plain build only reports chunk sizes, which tells you a chunk
// is too big but not which dependency made it so.
// Mehrere Worktrees laufen hier parallel. Ohne diese beiden Variablen streiten
// sie sich um 5173 und 3001; mit ihnen bekommt jeder seinen eigenen Satz.
const DEV_PORT = Number(process.env.TREK_DEV_PORT) || 5173;
const API_TARGET = process.env.TREK_DEV_API || 'http://localhost:3001';
export default defineConfig(({ mode }) => ({
define: { __TREK_UI_VERSION__: JSON.stringify(UI_VERSION) },
plugins: [
react(),
mode === 'analyze' &&
visualizer({ filename: 'dist/stats.html', gzipSize: true, brotliSize: true }),
VitePWA({
registerType: 'autoUpdate',
// Serve the generated manifest (+ dev SW) in development too, so the installed
// PWA can be tested against the dev server. Without this, dev ships no
// , so iOS falls back to legacy standalone
// (apple-mobile-web-app-capable only) and pops the Safari chrome on every
// in-app navigation away from the start URL. Prod already serves the manifest.
devOptions: {
enabled: true,
type: 'module',
suppressWarnings: true,
/*
* No navigation fallback from the dev service worker.
*
* `workbox.navigateFallback` below is right for production: offline, a
* deep link has to be answered by the cached shell. In development it
* means the worker answers a reload with the index.html it cached
* earlier, whose