vite.config.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. allowedHosts: [
  85. '.ngrok-free.app',
  86. '.ngrok-free.dev',
  87. '.ngrok.io',
  88. 'localhost'
  89. ],
  90. },
  91. build: {
  92. rollupOptions: {
  93. output: {
  94. manualChunks: {
  95. // 将 Vue 相关库分离
  96. "vue-vendor": ["vue", "vue-router"],
  97. // 将大型页面组件分离
  98. "video-player": ["./src/views/VideoPlayer.vue"],
  99. account: ["./src/views/Account.vue"],
  100. purchased: ["./src/views/Purchased.vue"],
  101. favorite: ["./src/views/Favorite.vue"],
  102. // 将布局组件分离
  103. layout: [
  104. "./src/components/layout/MainLayout.vue",
  105. "./src/components/layout/VideoLayout.vue",
  106. ],
  107. },
  108. },
  109. },
  110. // 提高警告阈值
  111. chunkSizeWarningLimit: 1000,
  112. },
  113. });