Files
eranos/vite.config.ts
T
Alex Gleason be6980359f Eliminate duplicated schema by deriving DittoConfigSchema from AppConfigSchema
Delete the separate config/schema.ts that duplicated every Zod schema.
DittoConfigSchema is now simply AppConfigSchema.partial().strict(),
defined in src/lib/schemas.ts alongside everything else. vite.config.ts
imports it directly via a relative path.
2026-02-26 17:57:55 -06:00

63 lines
1.5 KiB
TypeScript

import fs from "node:fs";
import path from "node:path";
import react from "@vitejs/plugin-react-swc";
import { defineConfig } from "vitest/config";
import { DittoConfigSchema } from "./src/lib/schemas";
/**
* Load and validate the build-time ditto.json configuration file.
* Returns the parsed config object, or `undefined` if the file doesn't exist.
* Set the CONFIG_FILE env var to override the default path ("./ditto.json").
*/
function loadDittoConfig(): object | undefined {
const configPath = path.resolve(process.env.CONFIG_FILE ?? "./ditto.json");
let raw: string;
try {
raw = fs.readFileSync(configPath, "utf-8");
} catch {
// File not found — no build-time config
return undefined;
}
const json = JSON.parse(raw);
const result = DittoConfigSchema.parse(json);
return result;
}
const dittoConfig = loadDittoConfig();
// https://vitejs.dev/config/
export default defineConfig(() => ({
server: {
host: "::",
port: 8080,
},
plugins: [
react(),
],
define: {
__DITTO_CONFIG__: JSON.stringify(dittoConfig ?? null),
},
test: {
globals: true,
environment: 'jsdom',
setupFiles: './src/test/setup.ts',
onConsoleLog(log) {
return !log.includes("React Router Future Flag Warning");
},
env: {
DEBUG_PRINT_LIMIT: '0', // Suppress DOM output that exceeds AI context windows
},
},
build: {
target: 'esnext',
},
resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),
},
},
}));