Files
ai-app-skg/vite.config.ts
2025-12-24 00:52:40 +08:00

40 lines
928 B
TypeScript

import { defineConfig, loadEnv } from 'vite'
import react from '@vitejs/plugin-react'
import { cwd } from 'node:process'
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
// Use cwd() from node:process to avoid type resolution issues with the global process object
const env = { ...process.env, ...loadEnv(mode, cwd(), '') };
return {
plugins: [react()],
define: {
// 确保 API Key 在构建时注入
'process.env.API_KEY': JSON.stringify(env.API_KEY || '')
},
build: {
outDir: 'dist',
emptyOutDir: true,
sourcemap: false,
// 优化构建产物
rollupOptions: {
output: {
manualChunks: {
'vendor': ['react', 'react-dom', '@google/genai']
}
}
}
},
server: {
port: 8080,
host: '0.0.0.0'
},
preview: {
port: 8080,
host: '0.0.0.0'
}
}
})