import { defineConfig } from 'vite' import vue from '@vitejs/plugin-vue' import fs from 'fs' import yaml from 'js-yaml' import { fileURLToPath } from 'url' import { dirname, resolve } from 'path' const __filename = fileURLToPath(import.meta.url) const __dirname = dirname(__filename) const configPath = resolve(__dirname, '..', 'config.yml'); let config = {}; try { config = yaml.load(fs.readFileSync(configPath, 'utf-8')); } catch (e) { console.warn(`Config file not found at ${configPath}, using defaults.`); config = {}; } const frontend_port = process.env.VITE_FRONTEND_PORT || config.frontend_port || 4000; const backend_port = process.env.VITE_BACKEND_PORT || config.backend_port || 3000; export default defineConfig({ plugins: [vue()], server: { port: frontend_port, proxy: { '/api': { target: `http://localhost:${backend_port}`, changeOrigin: true, }, }, }, build: { rollupOptions: { output: { manualChunks: { 'vendor-markdown': ['marked', 'marked-highlight', 'highlight.js'], 'vendor-katex': ['katex'], }, }, }, }, })