import { readFile } from 'node:fs/promises' import { fileURLToPath } from 'node:url' import { defineConfig } from 'vitest/config' import type { Plugin } from 'vite' import react from '@vitejs/plugin-react' const openapiSpecPath = fileURLToPath(new URL('../backend/openapi/openapi.yaml', import.meta.url)) function openapiSpec(): Plugin { return { name: 'kereru-openapi-spec', configureServer(server) { server.middlewares.use('/openapi.yaml', (_req, res, next) => { readFile(openapiSpecPath) .then((data) => { res.setHeader('Content-Type', 'application/yaml') res.end(data) }) .catch(next) }) }, async generateBundle() { this.emitFile({ type: 'asset', fileName: 'openapi.yaml', source: await readFile(openapiSpecPath, 'utf8'), }) }, } } export default defineConfig({ plugins: [react(), openapiSpec()], server: { port: 5173, proxy: { '/api': { target: 'http://localhost:8080', changeOrigin: true, }, }, }, test: { environment: 'jsdom', globals: true, setupFiles: ['./src/test/setup.ts'], css: false, }, })