76 lines
2.1 KiB
TypeScript
76 lines
2.1 KiB
TypeScript
import { defineConfig } from "vite";
|
|
import react from "@vitejs/plugin-react";
|
|
import { resolve } from "path";
|
|
import { readFileSync, existsSync } from "node:fs";
|
|
|
|
let appVersion = "0.0.0";
|
|
const versionFile = resolve(__dirname, "../Docker/VERSION");
|
|
if (existsSync(versionFile)) {
|
|
appVersion = readFileSync(versionFile, "utf-8")
|
|
.trim()
|
|
.replace(/^v/, "");
|
|
}
|
|
|
|
// https://vitejs.dev/config/
|
|
export default defineConfig({
|
|
plugins: [react()],
|
|
define: {
|
|
/** BanGUI application version injected at build time from Docker/VERSION. */
|
|
__APP_VERSION__: JSON.stringify(appVersion),
|
|
},
|
|
resolve: {
|
|
alias: {
|
|
"@": resolve(__dirname, "src"),
|
|
},
|
|
},
|
|
server: {
|
|
port: 5173,
|
|
proxy: {
|
|
"/api": {
|
|
// In the dev compose stack the backend is reachable via its service
|
|
// name on the shared Docker/Podman network. Using "localhost" would
|
|
// resolve to the frontend container itself and cause ECONNREFUSED.
|
|
target: process.env["VITE_BACKEND_URL"] ?? "http://backend:8000",
|
|
changeOrigin: true,
|
|
},
|
|
},
|
|
},
|
|
build: {
|
|
rollupOptions: {
|
|
output: {
|
|
manualChunks(id: string) {
|
|
if (id.includes("/node_modules/")) {
|
|
if (
|
|
id.includes("/node_modules/react/") ||
|
|
id.includes("/node_modules/react-dom/") ||
|
|
id.includes("/node_modules/react-router-dom/")
|
|
) {
|
|
return "react-vendor";
|
|
}
|
|
|
|
if (
|
|
id.includes("/node_modules/@fluentui/") ||
|
|
id.includes("/node_modules/@griffel/") ||
|
|
id.includes("/node_modules/@radix-ui/")
|
|
) {
|
|
return "ui-vendor";
|
|
}
|
|
|
|
if (id.includes("/node_modules/recharts/")) {
|
|
return "chart-vendor";
|
|
}
|
|
|
|
if (
|
|
id.includes("/node_modules/d3-") ||
|
|
id.includes("/node_modules/topojson-client/") ||
|
|
id.includes("/node_modules/world-atlas/")
|
|
) {
|
|
return "geo-vendor";
|
|
}
|
|
}
|
|
},
|
|
},
|
|
},
|
|
},
|
|
});
|