|
| 1 | +import withPWAInit from "next-pwa"; |
| 2 | + |
| 3 | +const withPWA = withPWAInit({ |
| 4 | + dest: "public", |
| 5 | + disable: process.env.NODE_ENV === "development", |
| 6 | + register: true, |
| 7 | + reloadOnOnline: false, |
| 8 | + skipWaiting: true, |
| 9 | + fallbacks: { |
| 10 | + document: "/offline.html", |
| 11 | + }, |
| 12 | + runtimeCaching: [ |
| 13 | + { |
| 14 | + urlPattern: /^https:\/\/api\.github\.com\/.*$/, |
| 15 | + handler: "NetworkFirst", |
| 16 | + options: { |
| 17 | + cacheName: "github-api-cache", |
| 18 | + expiration: { |
| 19 | + maxEntries: 100, |
| 20 | + maxAgeSeconds: 24 * 60 * 60, // 24 hours |
| 21 | + }, |
| 22 | + }, |
| 23 | + }, |
| 24 | + { |
| 25 | + urlPattern: ({ url }) => { |
| 26 | + if (url.origin !== self.location.origin) return false; |
| 27 | + return ( |
| 28 | + url.pathname === "/api/dashboard" || |
| 29 | + url.pathname === "/api/goals" || |
| 30 | + url.pathname.startsWith("/api/metrics/") || |
| 31 | + url.pathname.startsWith("/api/streak/") |
| 32 | + ); |
| 33 | + }, |
| 34 | + handler: "NetworkFirst", |
| 35 | + method: "GET", |
| 36 | + options: { |
| 37 | + cacheName: "dashboard-api-cache", |
| 38 | + networkTimeoutSeconds: 5, |
| 39 | + cacheableResponse: { |
| 40 | + statuses: [200], |
| 41 | + }, |
| 42 | + expiration: { |
| 43 | + maxEntries: 80, |
| 44 | + maxAgeSeconds: 24 * 60 * 60, // 24 hours |
| 45 | + }, |
| 46 | + }, |
| 47 | + }, |
| 48 | + { |
| 49 | + urlPattern: ({ url }) => { |
| 50 | + return ( |
| 51 | + url.origin === self.location.origin && |
| 52 | + url.pathname === "/api/goals/sync" |
| 53 | + ); |
| 54 | + }, |
| 55 | + handler: "NetworkOnly", |
| 56 | + method: "POST", |
| 57 | + options: { |
| 58 | + backgroundSync: { |
| 59 | + name: "devtrack-goal-sync-queue", |
| 60 | + options: { |
| 61 | + maxRetentionTime: 24 * 60, // 24 hours |
| 62 | + }, |
| 63 | + }, |
| 64 | + }, |
| 65 | + }, |
| 66 | + { |
| 67 | + urlPattern: ({ url }) => { |
| 68 | + if (url.origin !== self.location.origin) return false; |
| 69 | + if (url.pathname.startsWith("/api/auth/")) return false; |
| 70 | + if (url.pathname.startsWith("/api/webhooks/")) return false; |
| 71 | + return url.pathname.startsWith("/api/"); |
| 72 | + }, |
| 73 | + handler: "NetworkFirst", |
| 74 | + method: "GET", |
| 75 | + options: { |
| 76 | + cacheName: "api-cache", |
| 77 | + networkTimeoutSeconds: 5, |
| 78 | + cacheableResponse: { |
| 79 | + statuses: [200], |
| 80 | + }, |
| 81 | + expiration: { |
| 82 | + maxEntries: 80, |
| 83 | + maxAgeSeconds: 24 * 60 * 60, // 24 hours |
| 84 | + }, |
| 85 | + }, |
| 86 | + }, |
| 87 | + { |
| 88 | + urlPattern: /^https:\/\/fonts\.(?:gstatic|googleapis)\.com\/.*$/i, |
| 89 | + handler: "CacheFirst", |
| 90 | + options: { |
| 91 | + cacheName: "font-assets-cache", |
| 92 | + cacheableResponse: { |
| 93 | + statuses: [0, 200], |
| 94 | + }, |
| 95 | + expiration: { |
| 96 | + maxEntries: 16, |
| 97 | + maxAgeSeconds: 24 * 60 * 60, // 24 hours |
| 98 | + }, |
| 99 | + }, |
| 100 | + }, |
| 101 | + { |
| 102 | + urlPattern: ({ url }) => { |
| 103 | + if (url.origin !== self.location.origin) return false; |
| 104 | + return ( |
| 105 | + url.pathname.startsWith("/_next/static/") || |
| 106 | + /\.(?:js|css|woff2?|png|jpg|jpeg|gif|svg|ico|webp|json)$/.test( |
| 107 | + url.pathname, |
| 108 | + ) |
| 109 | + ); |
| 110 | + }, |
| 111 | + handler: "CacheFirst", |
| 112 | + options: { |
| 113 | + cacheName: "static-assets-cache", |
| 114 | + cacheableResponse: { |
| 115 | + statuses: [200], |
| 116 | + }, |
| 117 | + expiration: { |
| 118 | + maxEntries: 160, |
| 119 | + maxAgeSeconds: 24 * 60 * 60, // 24 hours |
| 120 | + }, |
| 121 | + }, |
| 122 | + }, |
| 123 | + ], |
| 124 | +}); |
| 125 | + |
1 | 126 | /** @type {import("next").NextConfig} */ |
2 | 127 | const nextConfig = { |
3 | 128 | typescript: { |
@@ -30,4 +155,4 @@ const nextConfig = { |
30 | 155 | }, |
31 | 156 | }; |
32 | 157 |
|
33 | | -export default nextConfig; |
| 158 | +export default withPWA(nextConfig); |
0 commit comments