import { defineConfig } from "vite"; import vue from "@vitejs/plugin-vue"; import { VitePWA } from 'vite-plugin-pwa'; import { fileURLToPath, URL } from "node:url"; // https://vite.dev/config/ export default defineConfig({ plugins: [ vue(), VitePWA({ registerType: 'autoUpdate', includeAssets: ['favicon.ico', 'apple-touch-icon.png', 'icons/*.png'], manifest: { name: 'Junma Show', short_name: 'Junma', description: '在线视频播放平台', theme_color: '#10b981', background_color: '#0f172a', display: 'standalone', icons: [ { src: '/vite.svg', sizes: 'any', type: 'image/svg+xml', purpose: 'any maskable' } ] }, workbox: { globPatterns: ['**/*.{js,css,html,ico,png,svg,woff2}'], runtimeCaching: [ { urlPattern: /^https:\/\/api\./i, handler: 'NetworkFirst', options: { cacheName: 'api-cache', expiration: { maxEntries: 50, maxAgeSeconds: 60 * 60 * 24 // 24 hours }, cacheableResponse: { statuses: [0, 200] } } }, { urlPattern: /^https:\/\/.*\.(jpg|jpeg|png|gif|webp)$/i, handler: 'CacheFirst', options: { cacheName: 'images-cache', expiration: { maxEntries: 100, maxAgeSeconds: 60 * 60 * 24 * 30 // 30 days } } }, { urlPattern: /^https:\/\/.*\.m3u8$/i, handler: 'NetworkOnly', options: { cacheName: 'video-cache' } } ], cleanupOutdatedCaches: true, skipWaiting: true, clientsClaim: true }, devOptions: { enabled: true, type: 'module' } }) ], resolve: { alias: { "@": fileURLToPath(new URL("./src", import.meta.url)), }, }, server: { port: 5100, host: "0.0.0.0", open: true, cors: true, proxy: { '/api/proxy/external-vod': { target: 'https://slapibf.com', changeOrigin: true, rewrite: (path) => path.replace(/^\/api\/proxy\/external-vod/, '/api.php/provide/vod'), configure: (proxy, _options) => { proxy.on('error', (err, _req, _res) => { console.log('proxy error', err); }); proxy.on('proxyReq', (proxyReq, req, _res) => { console.log('Sending Request to the Target:', req.method, req.url); }); proxy.on('proxyRes', (proxyRes, req, _res) => { console.log('Received Response from the Target:', proxyRes.statusCode, req.url); }); }, }, }, }, build: { rollupOptions: { output: { manualChunks: { // 将 Vue 相关库分离 "vue-vendor": ["vue", "vue-router"], // 将大型页面组件分离 "video-player": ["./src/views/VideoPlayer.vue"], account: ["./src/views/Account.vue"], purchased: ["./src/views/Purchased.vue"], favorite: ["./src/views/Favorite.vue"], // 将布局组件分离 layout: [ "./src/components/layout/MainLayout.vue", "./src/components/layout/VideoLayout.vue", ], }, }, }, // 提高警告阈值 chunkSizeWarningLimit: 1000, }, });