index.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { VitePWA } from 'vite-plugin-pwa'
  2. export const createPwa = (nodeEnv: string, pwaDev: boolean) => {
  3. return VitePWA({
  4. base: nodeEnv === 'development' && pwaDev ? '/' : './', // ./ 或 /
  5. registerType: 'autoUpdate', // promp弹窗提示手动更新、autoUpdate自动更新,建议使用自动更新
  6. workbox: {
  7. cleanupOutdatedCaches: true,
  8. },
  9. devOptions: {
  10. enabled: pwaDev,
  11. },
  12. manifest: {
  13. lang: 'zh',
  14. name: 'Vue Shop Vite',
  15. short_name: 'Vue Shop Vite',
  16. description: 'Vue Shop Vite官网、文档、演示地址',
  17. background_color: '#ffffff',
  18. theme_color: '#ffffff',
  19. icons: [
  20. {
  21. src: 'pwa-64x64.png',
  22. sizes: '64x64',
  23. type: 'image/png',
  24. },
  25. {
  26. src: 'pwa-192x192.png',
  27. sizes: '192x192',
  28. type: 'image/png',
  29. },
  30. {
  31. src: 'pwa-512x512.png',
  32. sizes: '512x512',
  33. type: 'image/png',
  34. purpose: 'any',
  35. },
  36. {
  37. src: 'maskable-icon-512x512.png',
  38. sizes: '512x512',
  39. type: 'image/png',
  40. purpose: 'maskable',
  41. },
  42. ],
  43. },
  44. }) as any
  45. }