import { defineConfig } from "vite"; import react from "@vitejs/plugin-react"; import { VitePWA } from "vite-plugin-pwa"; const backend = process.env.CODECRAFT_BACKEND ?? "http://127.0.0.1:8787"; const BUILD_ID = Date.now().toString(36); export default defineConfig({ plugins: [ react(), VitePWA({ registerType: "autoUpdate", // A new file name per build: reverse proxies with "cache assets" (e.g. Nginx // Proxy Manager) cache *.js by URL – a stale service worker would break // updates and installation. /sw.js is a kill switch for old installations. filename: `sw-${BUILD_ID}.js`, injectRegister: false, includeAssets: ["icon.svg", "apple-touch-icon.png"], manifest: { name: "CodeCraft", short_name: "CodeCraft", description: "Web-based coding harness for AI models", theme_color: "#282828", background_color: "#282828", display: "standalone", start_url: "/", id: "/", scope: "/", orientation: "any", categories: ["developer", "productivity"], // Android "Share" sheet: text/links become a new chat or go into a recent one. share_target: { action: "/", method: "GET", params: { title: "share_title", text: "share_text", url: "share_url" } }, icons: [ { src: "icon-192.png", sizes: "192x192", type: "image/png" }, { src: "icon-512.png", sizes: "512x512", type: "image/png" }, { src: "icon-maskable-512.png", sizes: "512x512", type: "image/png", purpose: "maskable" }, { src: "icon.svg", sizes: "any", type: "image/svg+xml" }, ], screenshots: [ { src: "screenshots/wide.png", sizes: "1400x860", type: "image/png", form_factor: "wide", label: "Chat with an agent" }, { src: "screenshots/narrow.png", sizes: "780x1688", type: "image/png", form_factor: "narrow", label: "CodeCraft on the phone" }, ], }, workbox: { // The API is always live data; only the app shell is cached. navigateFallbackDenylist: [/^\/api/, /^\/cli/], runtimeCaching: [], // The STEP importer (OpenCascade, ~8 MB) is loaded only when needed. globIgnores: ["**/occt-import-js*", "**/screenshots/**", "sw.js"], // Web Push handlers (push, notificationclick). importScripts: ["push-sw.mjs"], }, }), ], server: { proxy: { "/api": { target: backend, ws: true, changeOrigin: true }, }, }, });