vite.config.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import { defineConfig } from "vite";
  2. import vue from "@vitejs/plugin-vue";
  3. import { VitePWA } from 'vite-plugin-pwa';
  4. import { fileURLToPath, URL } from "node:url";
  5. // https://vite.dev/config/
  6. export default defineConfig({
  7. plugins: [
  8. vue(),
  9. VitePWA({
  10. registerType: 'autoUpdate',
  11. includeAssets: ['favicon.ico', 'apple-touch-icon.png', 'icons/*.png'],
  12. manifest: {
  13. name: 'Junma Show',
  14. short_name: 'Junma',
  15. description: '在线视频播放平台',
  16. theme_color: '#10b981',
  17. background_color: '#0f172a',
  18. display: 'standalone',
  19. icons: [
  20. {
  21. src: '/vite.svg',
  22. sizes: 'any',
  23. type: 'image/svg+xml',
  24. purpose: 'any maskable'
  25. }
  26. ]
  27. },
  28. workbox: {
  29. globPatterns: ['**/*.{js,css,html,ico,png,svg,woff2}'],
  30. runtimeCaching: [
  31. {
  32. urlPattern: /^https:\/\/api\./i,
  33. handler: 'NetworkFirst',
  34. options: {
  35. cacheName: 'api-cache',
  36. expiration: {
  37. maxEntries: 50,
  38. maxAgeSeconds: 60 * 60 * 24 // 24 hours
  39. },
  40. cacheableResponse: {
  41. statuses: [0, 200]
  42. }
  43. }
  44. },
  45. {
  46. urlPattern: /^https:\/\/.*\.(jpg|jpeg|png|gif|webp)$/i,
  47. handler: 'CacheFirst',
  48. options: {
  49. cacheName: 'images-cache',
  50. expiration: {
  51. maxEntries: 100,
  52. maxAgeSeconds: 60 * 60 * 24 * 30 // 30 days
  53. }
  54. }
  55. },
  56. {
  57. urlPattern: /^https:\/\/.*\.m3u8$/i,
  58. handler: 'NetworkOnly',
  59. options: {
  60. cacheName: 'video-cache'
  61. }
  62. }
  63. ],
  64. cleanupOutdatedCaches: true,
  65. skipWaiting: true,
  66. clientsClaim: true
  67. },
  68. devOptions: {
  69. enabled: true,
  70. type: 'module'
  71. }
  72. })
  73. ],
  74. resolve: {
  75. alias: {
  76. "@": fileURLToPath(new URL("./src", import.meta.url)),
  77. },
  78. },
  79. server: {
  80. port: 5100,
  81. host: "0.0.0.0",
  82. open: true,
  83. cors: true,
  84. },
  85. build: {
  86. rollupOptions: {
  87. output: {
  88. manualChunks: {
  89. // 将 Vue 相关库分离
  90. "vue-vendor": ["vue", "vue-router"],
  91. // 将大型页面组件分离
  92. "video-player": ["./src/views/VideoPlayer.vue"],
  93. account: ["./src/views/Account.vue"],
  94. purchased: ["./src/views/Purchased.vue"],
  95. favorite: ["./src/views/Favorite.vue"],
  96. // 将布局组件分离
  97. layout: [
  98. "./src/components/layout/MainLayout.vue",
  99. "./src/components/layout/VideoLayout.vue",
  100. ],
  101. },
  102. },
  103. },
  104. // 提高警告阈值
  105. chunkSizeWarningLimit: 1000,
  106. },
  107. });