import fs from 'node:fs' import path from 'node:path' import { fileURLToPath } from 'node:url' import { defineConfig } from 'vite' import vue from '@vitejs/plugin-vue' const __dirname = path.dirname(fileURLToPath(import.meta.url)) const webuiConfigPath = path.resolve(__dirname, '../config/webui.json') let webui = { api_base_url: 'http://127.0.0.1:18080', ws_url: '' } try { webui = { ...webui, ...JSON.parse(fs.readFileSync(webuiConfigPath, 'utf-8')) } } catch { console.warn('[vite] 未读取 config/webui.json,使用默认 API 地址') } // https://vite.dev/config/ export default defineConfig({ plugins: [vue()], define: { __WEBUI_API_BASE_URL__: JSON.stringify(String(webui.api_base_url || '').trim() || 'http://127.0.0.1:18080'), __WEBUI_WS_URL__: JSON.stringify(webui.ws_url != null ? String(webui.ws_url) : ''), }, server: { port: 18081, // 支持 Vue Router 的 history 模式 historyApiFallback: true, host: '127.0.0.1' }, preview: { port: 18081, historyApiFallback: true, host: '127.0.0.1' }, build: { rollupOptions: { output: { manualChunks(id) { if (id.includes('node_modules/echarts')) { return 'echarts' } if (id.includes('node_modules/element-plus')) { return 'element-plus' } if (id.includes('node_modules/vue') || id.includes('node_modules/vue-router') || id.includes('node_modules/pinia')) { return 'vue-vendor' } } } }, chunkSizeWarningLimit: 600 } })