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

68 lines
1.7 KiB
TypeScript

import { defineConfig, loadEnv } from 'vite'
import react from '@vitejs/plugin-react'
import { cwd } from 'node:process'
import { VitePWA } from 'vite-plugin-pwa'
// 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(),
VitePWA({
registerType: 'autoUpdate',
includeAssets: ['favicon.ico', 'apple-touch-icon.png', 'mask-icon.svg'],
manifest: {
name: 'SocioPal - Social Learning Tool',
short_name: 'SocioPal',
description: 'A comprehensive AI-powered tool for sociology learning.',
theme_color: '#ffffff',
background_color: '#ffffff',
display: 'standalone',
orientation: 'portrait',
icons: [
{
src: 'pwa-192x192.png',
sizes: '192x192',
type: 'image/png'
},
{
src: 'pwa-512x512.png',
sizes: '512x512',
type: 'image/png'
}
]
}
})
],
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'
}
}
})