Something went wrong. Try again.
geometric packing game (tetris-ish) on an icosahedron
Something went wrong. Try again.
rad-cohesion vite.config.ts
2.8 kB · 83 lines
TypeScript
at appview
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384import { readFile } from "node:fs/promises";import adapter from "@sveltejs/adapter-node";import { sveltekit } from "@sveltejs/kit/vite";import { defineConfig, loadEnv, type Plugin } from "vite";
// Browser fixtures are served only by the development server, never published.const browserFixture: Plugin = { name: "rad-browser-fixture", configureServer(server) { server.middlewares.use(async (request, response, next) => { const pathname = request.url?.split("?")[0];
if (pathname !== "/tests/fixture.html") return next();
try { const source = await readFile("tests/fixture.html", "utf8"); const html = await server.transformIndexHtml(request.url!, source); response.setHeader("Content-Type", "text/html"); response.end(html); } catch (error) { next(error); } }); },};
export default defineConfig(({ mode }) => { const env = loadEnv(mode, process.cwd(), ""); const siteUrl = env.SITE_URL?.trim(); const publicUrl = siteUrl ? new URL(siteUrl) : null; const resolverUrl = new URL(env.HANDLE_RESOLVER?.trim() || "https://bsky.social/");
if ( !["http:", "https:"].includes(resolverUrl.protocol) || resolverUrl.username || resolverUrl.password || resolverUrl.search || resolverUrl.hash || (resolverUrl.protocol === "http:" && !isLoopbackHostname(resolverUrl.hostname)) ) { throw new Error("HANDLE_RESOLVER must be an HTTPS base URL (HTTP is allowed for loopback development only)"); }
if (publicUrl) { if ( !["https:", "http:"].includes(publicUrl.protocol) || publicUrl.search || publicUrl.hash || publicUrl.username || publicUrl.password || (publicUrl.protocol === "http:" && !isLoopbackHostname(publicUrl.hostname)) ) { throw new Error("SITE_URL must be an HTTPS URL, or an HTTP loopback URL for local development"); }
if (!publicUrl.pathname.endsWith("/")) publicUrl.pathname += "/"; }
const requestedBase = publicUrl?.pathname.replace(/\/$/, "") ?? env.BASE_PATH ?? "";
if (requestedBase && (!requestedBase.startsWith("/") || requestedBase.endsWith("/"))) throw new Error("BASE_PATH must start with / and have no trailing slash"); const base = requestedBase ? `/${requestedBase.slice(1)}` as const : "";
return { define: { __SITE_URL__: JSON.stringify(publicUrl?.href ?? ""), __HANDLE_RESOLVER__: JSON.stringify(resolverUrl.href), __APP_BASE_PATH__: JSON.stringify(base), }, plugins: [ browserFixture, sveltekit({ adapter: adapter(), paths: { base, origin: publicUrl?.origin }, }), ], };});
function isLoopbackHostname(hostname: string): boolean { return hostname === "localhost" || hostname === "127.0.0.1" || hostname === "[::1]";}