import tailwindcss from '@tailwindcss/vite'; import react from '@vitejs/plugin-react'; import { defineConfig, loadEnv } from 'vite'; import { fileURLToPath } from 'url'; import { dirname, resolve } from 'path'; // 手动定义 __dirname 以确保在 Windows 下的兼容性 const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); export default defineConfig(({ mode }) => { const env = loadEnv(mode, '.', ''); return { base: './', plugins: [react(), tailwindcss()], define: { 'process.env.GEMINI_API_KEY': JSON.stringify(env.GEMINI_API_KEY), }, resolve: { alias: { // 使用 resolve 确保路径在 Windows/Linux 下都能正确解析 '@': resolve(__dirname, './src'), }, }, server: { port: 3000, host: '0.0.0.0', }, }; });