Files
mobile.derez.ai/app/vite.config.ts
T
oliver b2bee03ca2 Show build date next to "Settings" heading
Inject a yyyy-mm-dd_hh:mm timestamp at build time via Vite's `define`
(app/vite.config.ts: __BUILD_DATE__, computed fresh on every
`vite build`/`vite dev` invocation) and render it next to the
Settings panel's title, so it's easy to tell which build is deployed.

- app/vite.config.ts: buildDateString() + define.__BUILD_DATE__
- app/src/vite-env.d.ts: ambient declaration for the injected constant
- app/src/components/SettingsPanel.tsx: render it next to "Settings"
- app/src/styles.css: .build-date styling

Rebuilt and redeployed to the repo root.
2026-11-04 15:46:58 -03:00

105 lines
3.2 KiB
TypeScript

import { readFileSync } from "node:fs";
import { fileURLToPath } from "node:url";
import { defineConfig, loadEnv, type Plugin } from "vite";
import react from "@vitejs/plugin-react";
import { VitePWA } from "vite-plugin-pwa";
/** `yyyy-mm-dd_hh:mm` timestamp of this build/dev-server start, shown in the UI. */
function buildDateString(): string {
const d = new Date();
const pad = (n: number) => String(n).padStart(2, "0");
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}_${pad(d.getHours())}:${pad(d.getMinutes())}`;
}
/** Emits the repo's LICENSE file into the build output. */
function licensePlugin(): Plugin {
return {
name: "hermes-pwa-license",
apply: "build",
generateBundle() {
this.emitFile({
type: "asset",
fileName: "LICENSE",
source: readFileSync(fileURLToPath(new URL("../LICENSE", import.meta.url)), "utf-8"),
});
},
};
}
// During `npm run dev` you can point the dev server at a Hermes host to avoid
// CORS entirely: set HERMES_DEV_TARGET=https://hermes.example.com in a .env file
// (or the environment) and the dev server proxies /api/* to it.
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, ".", "");
const target = env.HERMES_DEV_TARGET;
return {
define: {
__BUILD_DATE__: JSON.stringify(buildDateString()),
},
server: {
port: 5173,
proxy: target
? Object.fromEntries(
["/api", "/v1", "/health"].map((prefix) => [
prefix,
{
target,
changeOrigin: true,
secure: false,
// SSE needs buffering disabled.
configure: (proxy) => {
proxy.on("proxyRes", (proxyRes) => {
proxyRes.headers["x-accel-buffering"] = "no";
});
},
},
]),
)
: undefined,
},
plugins: [
react(),
licensePlugin(),
VitePWA({
registerType: "autoUpdate",
includeAssets: ["icons/apple-touch-icon.png", "favicon.svg"],
manifest: {
name: "Hermes",
short_name: "Hermes",
description: "Chat with your Hermes Agent profiles, sessions, voice and images.",
theme_color: "#000810",
background_color: "#000810",
display: "standalone",
orientation: "portrait-primary",
start_url: "/",
scope: "/",
icons: [
{ src: "icons/icon-192.png", sizes: "192x192", type: "image/png" },
{ src: "icons/icon-512.png", sizes: "512x512", type: "image/png" },
{
src: "icons/maskable-512.png",
sizes: "512x512",
type: "image/png",
purpose: "maskable",
},
],
},
workbox: {
// Never cache API traffic — it is authenticated and dynamic.
navigateFallbackDenylist: [/^\/api\//],
runtimeCaching: [
{
urlPattern: ({ url }) => url.pathname.startsWith("/api/"),
handler: "NetworkOnly",
},
],
},
devOptions: {
enabled: false,
},
}),
],
};
});