vite.config.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. import adapter from '@sveltejs/adapter-auto';
  2. import { sveltekit } from '@sveltejs/kit/vite';
  3. import { SvelteKitPWA } from '@vite-pwa/sveltekit';
  4. import { defineConfig } from 'vite';
  5. export default defineConfig({
  6. plugins: [
  7. sveltekit({
  8. compilerOptions: {
  9. // Force runes mode for the project, except for libraries. Can be removed in svelte 6.
  10. runes: ({ filename }) =>
  11. filename.split(/[/\\]/).includes('node_modules') ? undefined : true
  12. },
  13. // adapter-auto only supports some environments, see https://svelte.dev/docs/kit/adapter-auto for a list.
  14. // If your environment is not supported, or you settled on a specific environment, switch out the adapter.
  15. // See https://svelte.dev/docs/kit/adapters for more information about adapters.
  16. adapter: adapter(),
  17. // Registration is handled by vite-plugin-pwa virtual modules.
  18. serviceWorker: {
  19. register: false
  20. }
  21. }),
  22. SvelteKitPWA({
  23. registerType: 'autoUpdate',
  24. injectRegister: null,
  25. strategies: 'generateSW',
  26. scope: '/',
  27. base: '/',
  28. manifest: {
  29. id: '/',
  30. name: 'Recipes',
  31. short_name: 'Recipes',
  32. description: 'Save, browse, and cook your recipes on any device.',
  33. lang: 'en',
  34. dir: 'ltr',
  35. start_url: '/',
  36. scope: '/',
  37. display: 'standalone',
  38. display_override: ['window-controls-overlay', 'standalone', 'minimal-ui', 'browser'],
  39. orientation: 'any',
  40. background_color: '#121212',
  41. theme_color: '#121212',
  42. categories: ['food', 'lifestyle', 'utilities'],
  43. prefer_related_applications: false,
  44. // Lets Chromium/Brave report an existing install via getInstalledRelatedApps().
  45. related_applications: [
  46. {
  47. platform: 'webapp',
  48. url: '/manifest.webmanifest'
  49. }
  50. ],
  51. icons: [
  52. {
  53. src: '/icon-72x72.png',
  54. sizes: '72x72',
  55. type: 'image/png',
  56. purpose: 'any'
  57. },
  58. {
  59. src: '/icon-96x96.png',
  60. sizes: '96x96',
  61. type: 'image/png',
  62. purpose: 'any'
  63. },
  64. {
  65. src: '/icon-128x128.png',
  66. sizes: '128x128',
  67. type: 'image/png',
  68. purpose: 'any'
  69. },
  70. {
  71. src: '/icon-144x144.png',
  72. sizes: '144x144',
  73. type: 'image/png',
  74. purpose: 'any'
  75. },
  76. {
  77. src: '/icon-152x152.png',
  78. sizes: '152x152',
  79. type: 'image/png',
  80. purpose: 'any'
  81. },
  82. {
  83. src: '/icon-192x192.png',
  84. sizes: '192x192',
  85. type: 'image/png',
  86. purpose: 'any'
  87. },
  88. {
  89. src: '/icon-384x384.png',
  90. sizes: '384x384',
  91. type: 'image/png',
  92. purpose: 'any'
  93. },
  94. {
  95. src: '/icon-512x512.png',
  96. sizes: '512x512',
  97. type: 'image/png',
  98. purpose: 'any'
  99. },
  100. {
  101. src: '/maskable-icon-192x192.png',
  102. sizes: '192x192',
  103. type: 'image/png',
  104. purpose: 'maskable'
  105. },
  106. {
  107. src: '/maskable-icon-512x512.png',
  108. sizes: '512x512',
  109. type: 'image/png',
  110. purpose: 'maskable'
  111. }
  112. ],
  113. shortcuts: [
  114. {
  115. name: 'Dashboard',
  116. short_name: 'Dashboard',
  117. description: 'View your recipes',
  118. url: '/dashboard',
  119. icons: [{ src: '/icon-192x192.png', sizes: '192x192', type: 'image/png' }]
  120. },
  121. {
  122. name: 'New recipe',
  123. short_name: 'New',
  124. description: 'Create a new recipe',
  125. url: '/recipe/new',
  126. icons: [{ src: '/icon-192x192.png', sizes: '192x192', type: 'image/png' }]
  127. }
  128. ]
  129. },
  130. workbox: {
  131. navigateFallback: null,
  132. globPatterns: ['client/**/*.{js,css,ico,png,svg,webp,webmanifest,woff,woff2}'],
  133. cleanupOutdatedCaches: true,
  134. clientsClaim: true,
  135. skipWaiting: false,
  136. runtimeCaching: [
  137. {
  138. urlPattern: ({ request }) => request.mode === 'navigate',
  139. handler: 'NetworkFirst',
  140. options: {
  141. cacheName: 'pages',
  142. networkTimeoutSeconds: 3,
  143. expiration: {
  144. maxEntries: 64,
  145. maxAgeSeconds: 60 * 60 * 24
  146. },
  147. cacheableResponse: {
  148. statuses: [0, 200]
  149. }
  150. }
  151. },
  152. {
  153. urlPattern: ({ request }) =>
  154. request.destination === 'image' ||
  155. request.destination === 'font' ||
  156. request.destination === 'style' ||
  157. request.destination === 'script',
  158. handler: 'StaleWhileRevalidate',
  159. options: {
  160. cacheName: 'assets',
  161. expiration: {
  162. maxEntries: 128,
  163. maxAgeSeconds: 60 * 60 * 24 * 30
  164. },
  165. cacheableResponse: {
  166. statuses: [0, 200]
  167. }
  168. }
  169. }
  170. ]
  171. },
  172. devOptions: {
  173. // Keep SW available in `vite dev` so install prompts can appear while developing.
  174. enabled: true,
  175. suppressWarnings: true,
  176. type: 'module',
  177. navigateFallback: '/'
  178. },
  179. kit: {
  180. includeVersionFile: true
  181. }
  182. })
  183. ]
  184. });