Files
tidefront/apps/web/vite.config.ts
T

56 lines
2.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { defineConfig, type Plugin } from "vite";
import react from "@vitejs/plugin-react";
import tailwindcss from "@tailwindcss/vite";
import { readFileSync } from "node:fs";
// Versionsnummer aus der Wurzel-package.json und Build-Zeitpunkt für die Anzeige in der App
const rootPkg = JSON.parse(readFileSync(new URL("../../package.json", import.meta.url), "utf8")) as { version: string };
const target = process.env.TF_API ?? "http://localhost:18080";
// Liste aller gebauten Dateien (auch der erst bei Bedarf geladenen Teile wie Karte, Anmeldung, „Was ist neu?“) für den
// Service Worker: Er legt sie beim Installieren und nach jedem App-Start vorab ab, damit die App offline vollständig ist.
function precacheList(): Plugin {
return {
name: "tf-precache-list",
apply: "build",
generateBundle(_opts, bundle) {
const files = Object.keys(bundle).filter((f) => /\.(js|css|woff2?|svg|png|webp)$/.test(f)).map((f) => `/${f}`).sort();
this.emitFile({ type: "asset", fileName: "precache.json", source: JSON.stringify({ version: rootPkg.version, files }) });
},
};
}
export default defineConfig({
plugins: [react(), tailwindcss(), precacheList()],
define: {
__APP_VERSION__: JSON.stringify(rootPkg.version),
__BUILD_TIME__: JSON.stringify(new Date().toISOString()),
},
build: {
outDir: "dist",
emptyOutDir: true,
chunkSizeWarningLimit: 400,
rolldownOptions: {
output: {
// Bibliotheken in eigene, lange cachebare Chunks: ein Spiel-Update lädt nur den App-Code neu.
// PixiJS bleibt bewusst außen vor – es hängt nur an der verzögert geladenen Karte.
codeSplitting: {
groups: [
{ name: "react", test: /node_modules[\\/](react|react-dom|scheduler)[\\/]/, priority: 20 },
{ name: "query", test: /node_modules[\\/]@(tanstack|trpc)[\\/]/, priority: 10 },
// Alles, was der Start ohnehin braucht, in einen App-Chunk statt vieler Kleinstteile.
{ name: "app", tags: ["$initial"], priority: 0 },
],
},
},
},
},
server: {
proxy: {
"/trpc": { target, changeOrigin: true },
"/ws": { target, ws: true, changeOrigin: true },
},
},
});