feat(web): add Progressive Web App (PWA) support (#25274)

This commit is contained in:
-LAN- 2025-09-06 16:04:24 +08:00 • committed by GitHub
commit 52b1ac5f54
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
21 changed files with 1643 additions and 502 deletions

View file

@ -1,4 +1,71 @@
const { codeInspectorPlugin } = require('code-inspector-plugin')
const withPWA = require('next-pwa')({
dest: 'public',
register: true,
skipWaiting: true,
disable: process.env.NODE_ENV === 'development',
fallbacks: {
document: '/_offline.html',
},
runtimeCaching: [
{
urlPattern: /^https:\/\/fonts\.googleapis\.com\/.*/i,
handler: 'CacheFirst',
options: {
cacheName: 'google-fonts',
expiration: {
maxEntries: 4,
maxAgeSeconds: 365 * 24 * 60 * 60 // 1 year
}
}
},
{
urlPattern: /^https:\/\/fonts\.gstatic\.com\/.*/i,
handler: 'CacheFirst',
options: {
cacheName: 'google-fonts-webfonts',
expiration: {
maxEntries: 4,
maxAgeSeconds: 365 * 24 * 60 * 60 // 1 year
}
}
},
{
urlPattern: /\.(?:png|jpg|jpeg|svg|gif|webp|avif)$/i,
handler: 'CacheFirst',
options: {
cacheName: 'images',
expiration: {
maxEntries: 64,
maxAgeSeconds: 30 * 24 * 60 * 60 // 30 days
}
}
},
{
urlPattern: /\.(?:js|css)$/i,
handler: 'StaleWhileRevalidate',
options: {
cacheName: 'static-resources',
expiration: {
maxEntries: 32,
maxAgeSeconds: 24 * 60 * 60 // 1 day
}
}
},
{
urlPattern: /^\/api\/.*/i,
handler: 'NetworkFirst',
options: {
cacheName: 'api-cache',
networkTimeoutSeconds: 10,
expiration: {
maxEntries: 16,
maxAgeSeconds: 60 * 60 // 1 hour
}
}
}
]
})
const withMDX = require('@next/mdx')({
extension: /\.mdx?$/,
options: {
@ -70,4 +137,4 @@ const nextConfig = {
output: 'standalone',
}
module.exports = withBundleAnalyzer(withMDX(nextConfig))
module.exports = withPWA(withBundleAnalyzer(withMDX(nextConfig)))