Spaces:
Running
Running
| import { defineConfig } from 'vite'; | |
| import react from '@vitejs/plugin-react'; | |
| import { VitePWA } from 'vite-plugin-pwa'; | |
| // https://vitejs.dev/config/ | |
| export default defineConfig({ | |
| plugins: [ | |
| react(), | |
| VitePWA({ | |
| registerType: 'autoUpdate', // 核心设置:检测到新内容自动更新 Service Worker | |
| includeAssets: ['favicon.ico', 'apple-touch-icon.png', 'masked-icon.svg'], | |
| manifest: { | |
| id: '/', // 关键:定义应用的唯一标识,避免不同版本被识别为不同应用 | |
| scope: '/', // 关键:定义 PWA 的作用域 | |
| start_url: '/', // 关键:定义启动 URL | |
| name: '智慧校园管理系统', | |
| short_name: '智慧校园', | |
| description: '一个综合性的学生管理系统仪表板,具有基于角色的访问控制、学生档案、课程管理和绩效分析功能。', | |
| theme_color: '#2563eb', // 对应 bg-blue-600 | |
| background_color: '#f9fafb', | |
| display: 'standalone', // 关键设置:像原生 App 一样全屏显示,无浏览器地址栏 | |
| orientation: 'portrait', | |
| icons: [ | |
| { | |
| src: 'https://cdn-icons-png.flaticon.com/512/3135/3135810.png', | |
| sizes: '192x192', | |
| type: 'image/png', | |
| purpose: 'any' // 允许图标用于任何用途 | |
| }, | |
| { | |
| src: 'https://cdn-icons-png.flaticon.com/512/3135/3135810.png', | |
| sizes: '512x512', | |
| type: 'image/png', | |
| purpose: 'any' | |
| }, | |
| { | |
| src: 'https://cdn-icons-png.flaticon.com/512/3135/3135810.png', | |
| sizes: '512x512', | |
| type: 'image/png', | |
| purpose: 'maskable' // 关键:适应 Android 自适应图标 | |
| } | |
| ] | |
| }, | |
| workbox: { | |
| cleanupOutdatedCaches: true, // 关键:自动清理过期的缓存文件 | |
| // 缓存策略配置,确保 API 请求不被过度缓存,但静态资源被缓存 | |
| globPatterns: ['**/*.{js,css,html,ico,png,svg}'], | |
| runtimeCaching: [ | |
| { | |
| urlPattern: /^https:\/\/api\.dicebear\.com\/.*/i, | |
| handler: 'CacheFirst', | |
| options: { | |
| cacheName: 'avatar-cache', | |
| expiration: { | |
| maxEntries: 100, | |
| maxAgeSeconds: 60 * 60 * 24 * 30 // 30 Days | |
| }, | |
| cacheableResponse: { | |
| statuses: [0, 200] | |
| } | |
| } | |
| } | |
| ] | |
| } | |
| }) | |
| ], | |
| build: { | |
| outDir: 'dist', | |
| emptyOutDir: true, | |
| chunkSizeWarningLimit: 1000, | |
| rollupOptions: { | |
| external: ['mammoth', 'pdfjs-dist', 'docx'], // Added docx to external | |
| output: { | |
| manualChunks: { | |
| vendor: ['react', 'react-dom'], | |
| charts: ['recharts'], | |
| utils: ['lucide-react'] | |
| } | |
| } | |
| } | |
| } | |
| }); | |