|
1 | 1 | import type { NextConfig } from "next"; |
| 2 | +import withPWA from "next-pwa"; |
2 | 3 |
|
3 | 4 | const nextConfig: NextConfig = { |
| 5 | + turbopack: {}, // Silence Turbopack warning for webpack-based next-pwa |
4 | 6 | experimental: { |
5 | 7 | serverActions: { |
6 | 8 | bodySizeLimit: '5mb', |
7 | 9 | }, |
8 | 10 | }, |
9 | 11 | }; |
10 | 12 |
|
11 | | -export default nextConfig; |
| 13 | +export default withPWA({ |
| 14 | + dest: 'public', |
| 15 | + register: true, |
| 16 | + skipWaiting: true, |
| 17 | + disable: false, // Enable in dev for testing |
| 18 | + fallbacks: { |
| 19 | + document: '/_offline.html', |
| 20 | + }, |
| 21 | + runtimeCaching: [ |
| 22 | + { |
| 23 | + urlPattern: /^https:\/\/fonts\.(?:gstatic|googleapis)\.com\/.*/i, |
| 24 | + handler: 'CacheFirst', |
| 25 | + options: { |
| 26 | + cacheName: 'google-fonts', |
| 27 | + expiration: { |
| 28 | + maxEntries: 4, |
| 29 | + maxAgeSeconds: 365 * 24 * 60 * 60, // 1 year |
| 30 | + }, |
| 31 | + }, |
| 32 | + }, |
| 33 | + { |
| 34 | + urlPattern: /^https:\/\/api\.github\.com\/.*/i, |
| 35 | + handler: 'NetworkFirst', |
| 36 | + options: { |
| 37 | + cacheName: 'github-api', |
| 38 | + networkTimeoutSeconds: 10, |
| 39 | + expiration: { |
| 40 | + maxEntries: 50, |
| 41 | + maxAgeSeconds: 5 * 60, // 5 minutes |
| 42 | + }, |
| 43 | + }, |
| 44 | + }, |
| 45 | + { |
| 46 | + urlPattern: /\.(?:png|jpg|jpeg|svg|gif|webp|ico)$/i, |
| 47 | + handler: 'CacheFirst', |
| 48 | + options: { |
| 49 | + cacheName: 'static-images', |
| 50 | + expiration: { |
| 51 | + maxEntries: 60, |
| 52 | + maxAgeSeconds: 30 * 24 * 60 * 60, // 30 days |
| 53 | + }, |
| 54 | + }, |
| 55 | + }, |
| 56 | + { |
| 57 | + urlPattern: /\.(?:js|css)$/i, |
| 58 | + handler: 'StaleWhileRevalidate', |
| 59 | + options: { |
| 60 | + cacheName: 'static-resources', |
| 61 | + expiration: { |
| 62 | + maxEntries: 100, |
| 63 | + maxAgeSeconds: 24 * 60 * 60, // 24 hours |
| 64 | + }, |
| 65 | + }, |
| 66 | + }, |
| 67 | + ], |
| 68 | +})(nextConfig); |
0 commit comments