tidy build config and deps

strip ollama proxy from vite, add deployment html injection plugin,
bump zxing dep for barcode scanning, ignore deploy artifacts
This commit is contained in:
Ned Halksworth
2026-05-27 17:31:09 +01:00
committed by Ned
parent add2586cb1
commit 7bc92a92d7
4 changed files with 82 additions and 38 deletions
+31 -38
View File
@@ -1,44 +1,37 @@
import { existsSync, readFileSync } from "node:fs";
import react from "@vitejs/plugin-react";
import { defineConfig, loadEnv } from "vite";
import type { Plugin } from "vite";
import { defineConfig } from "vite";
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), "");
const ollamaProxy = {
target: "https://ollama.com",
changeOrigin: true,
rewrite: () => "/api/chat",
configure(proxy: { on: (event: "proxyReq", handler: (proxyReq: { setHeader: (name: string, value: string) => void }) => void) => void }) {
proxy.on("proxyReq", (proxyReq) => {
if (env.OLLAMA_API_KEY) {
proxyReq.setHeader("Authorization", `Bearer ${env.OLLAMA_API_KEY}`);
}
});
},
};
return {
plugins: [react()],
server: {
proxy: {
"/api/ollama-chat": ollamaProxy,
},
},
preview: {
proxy: {
"/api/ollama-chat": ollamaProxy,
},
},
build: {
chunkSizeWarningLimit: 700,
rollupOptions: {
output: {
manualChunks: {
charts: ["recharts"],
motion: ["framer-motion"],
icons: ["lucide-react"],
},
export default defineConfig(({ command }) => ({
plugins: [react(), deploymentHtml(command === "build")],
build: {
chunkSizeWarningLimit: 700,
rollupOptions: {
output: {
manualChunks: {
charts: ["recharts"],
motion: ["framer-motion"],
icons: ["lucide-react"],
},
},
},
},
}));
function deploymentHtml(enabled: boolean): Plugin {
return {
name: "deployment-html",
transformIndexHtml(html) {
if (!enabled) return html;
return html
.replace("</head>", `${readOptional(".deploy/head.html")}</head>`)
.replace("</body>", `${readOptional(".deploy/body-end.html")}</body>`);
},
};
});
}
function readOptional(path: string) {
if (!existsSync(path)) return "";
return `\n${readFileSync(path, "utf8").trim()}\n`;
}