Files
Red-Bull-Tracker/vite.config.ts
T
Cursor Agent 64584315e5 Fix barcode scanner on iOS Safari
iOS WebKit does not provide a reliable native Barcode Detection API, and
ZXing often failed due to strict camera constraints and video startup timing.

- Install @undecaf/barcode-detector-polyfill (ZBar WASM) on Apple devices
- Fall back through progressively looser getUserMedia constraints
- Wait for video metadata/playback before decoding frames
- Throttle native scans on iOS and tune ZXing retry intervals
- Defer scanner startup until the modal video element is mounted

Co-authored-by: Ned Halksworth <hello@nedhalksworth.com>
2026-05-27 19:51:08 +00:00

39 lines
1.0 KiB
TypeScript

import { existsSync, readFileSync } from "node:fs";
import react from "@vitejs/plugin-react";
import type { Plugin } from "vite";
import { defineConfig } from "vite";
export default defineConfig(({ command }) => ({
plugins: [react(), deploymentHtml(command === "build")],
build: {
chunkSizeWarningLimit: 700,
rollupOptions: {
output: {
manualChunks: {
charts: ["recharts"],
motion: ["framer-motion"],
icons: ["lucide-react"],
barcode: ["@undecaf/barcode-detector-polyfill"],
},
},
},
},
}));
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`;
}