| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- import { mkdir, writeFile } from 'node:fs/promises';
- import { resolve } from 'node:path';
- import { sveltekit } from '@sveltejs/kit/vite';
- import { SvelteKitPWA } from '@vite-pwa/sveltekit';
- import { defineConfig } from 'vite';
- function ensurePrerenderedGlob() {
- return {
- name: 'ensure-prerendered-glob',
- apply: 'build',
- async writeBundle() {
- const dir = resolve('.svelte-kit/output/prerendered');
- await mkdir(dir, { recursive: true });
- await writeFile(resolve(dir, '.keep.json'), '{}\n');
- }
- };
- }
- export default defineConfig({
- plugins: [
- sveltekit(),
- ensurePrerenderedGlob(),
- SvelteKitPWA({
- registerType: 'autoUpdate',
- injectRegister: null,
- strategies: 'generateSW',
- scope: '/',
- base: '/',
- manifest: {
- id: '/',
- name: 'Recipes',
- short_name: 'Recipes',
- description: 'Save, browse, and cook your recipes on any device.',
- lang: 'en',
- dir: 'ltr',
- start_url: '/',
- scope: '/',
- display: 'standalone',
- display_override: ['window-controls-overlay', 'standalone', 'minimal-ui', 'browser'],
- orientation: 'any',
- background_color: '#121212',
- theme_color: '#121212',
- categories: ['food', 'lifestyle', 'utilities'],
- prefer_related_applications: false,
- // Lets Chromium/Brave report an existing install via getInstalledRelatedApps().
- related_applications: [
- {
- platform: 'webapp',
- url: '/manifest.webmanifest'
- }
- ],
- icons: [
- {
- src: '/icon-72x72.png',
- sizes: '72x72',
- type: 'image/png',
- purpose: 'any'
- },
- {
- src: '/icon-96x96.png',
- sizes: '96x96',
- type: 'image/png',
- purpose: 'any'
- },
- {
- src: '/icon-128x128.png',
- sizes: '128x128',
- type: 'image/png',
- purpose: 'any'
- },
- {
- src: '/icon-144x144.png',
- sizes: '144x144',
- type: 'image/png',
- purpose: 'any'
- },
- {
- src: '/icon-152x152.png',
- sizes: '152x152',
- type: 'image/png',
- purpose: 'any'
- },
- {
- src: '/icon-192x192.png',
- sizes: '192x192',
- type: 'image/png',
- purpose: 'any'
- },
- {
- src: '/icon-384x384.png',
- sizes: '384x384',
- type: 'image/png',
- purpose: 'any'
- },
- {
- src: '/icon-512x512.png',
- sizes: '512x512',
- type: 'image/png',
- purpose: 'any'
- },
- {
- src: '/maskable-icon-192x192.png',
- sizes: '192x192',
- type: 'image/png',
- purpose: 'maskable'
- },
- {
- src: '/maskable-icon-512x512.png',
- sizes: '512x512',
- type: 'image/png',
- purpose: 'maskable'
- }
- ],
- shortcuts: [
- {
- name: 'Dashboard',
- short_name: 'Dashboard',
- description: 'View your recipes',
- url: '/dashboard',
- icons: [{ src: '/icon-192x192.png', sizes: '192x192', type: 'image/png' }]
- },
- {
- name: 'New recipe',
- short_name: 'New',
- description: 'Create a new recipe',
- url: '/recipe/new',
- icons: [{ src: '/icon-192x192.png', sizes: '192x192', type: 'image/png' }]
- }
- ]
- },
- workbox: {
- navigateFallback: null,
- globPatterns: [
- 'client/**/*.{js,css,ico,png,svg,webp,webmanifest,woff,woff2}',
- 'prerendered/.keep.json'
- ],
- cleanupOutdatedCaches: true,
- clientsClaim: true,
- skipWaiting: false,
- runtimeCaching: [
- {
- urlPattern: ({ request }) => request.mode === 'navigate',
- handler: 'NetworkFirst',
- options: {
- cacheName: 'pages',
- networkTimeoutSeconds: 3,
- expiration: {
- maxEntries: 64,
- maxAgeSeconds: 60 * 60 * 24
- },
- cacheableResponse: {
- statuses: [0, 200]
- }
- }
- },
- {
- urlPattern: ({ request }) =>
- request.destination === 'image' ||
- request.destination === 'font' ||
- request.destination === 'style' ||
- request.destination === 'script',
- handler: 'StaleWhileRevalidate',
- options: {
- cacheName: 'assets',
- expiration: {
- maxEntries: 128,
- maxAgeSeconds: 60 * 60 * 24 * 30
- },
- cacheableResponse: {
- statuses: [0, 200]
- }
- }
- }
- ]
- },
- devOptions: {
- enabled: false,
- suppressWarnings: true,
- type: 'module'
- },
- kit: {
- includeVersionFile: true
- }
- })
- ]
- });
|