-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
112 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,74 @@ | ||
import { join } from 'node:path' | ||
import { VitePWA } from 'vite-plugin-pwa' | ||
import type { PluginOption } from 'vite' | ||
import fg from 'fast-glob' | ||
|
||
export function setupVitePWA(viteEnv: ViteEnv): PluginOption | PluginOption[] { | ||
const { VITE_APP_TITLE } = viteEnv | ||
const { VITE_APP_TITLE: NAME } = viteEnv | ||
return VitePWA({ | ||
strategies: 'injectManifest', | ||
srcDir: 'public', | ||
filename: 'sw.js', | ||
registerType: 'autoUpdate', | ||
manifest: { | ||
name: VITE_APP_TITLE, | ||
short_name: VITE_APP_TITLE, | ||
theme_color: '#ffffff', | ||
name: NAME, | ||
short_name: NAME, | ||
theme_color: '#ecf5ff', | ||
icons: [ | ||
{ | ||
src: '/logo.png', | ||
src: '/logos/logo_512.png', | ||
types: 'img/png', | ||
sizes: '512x512', | ||
purpose: 'any', | ||
}, | ||
{ | ||
src: '/logos/logo_256.png', | ||
types: 'img/png', | ||
sizes: '256x256', | ||
purpose: 'maskable', | ||
}, | ||
{ | ||
src: '/logos/logo_192.png', | ||
types: 'img/png', | ||
sizes: '192x192', | ||
type: 'image/png', | ||
purpose: 'maskable', | ||
}, | ||
{ | ||
src: '/logo.png', | ||
sizes: '512x512', | ||
type: 'image/png', | ||
src: '/logos/logo_144.png', | ||
types: 'img/png', | ||
sizes: '144x144', | ||
purpose: 'maskable', | ||
}, | ||
{ | ||
src: '/logo.png', | ||
sizes: '512x512', | ||
type: 'image/png', | ||
purpose: 'any maskable', | ||
src: '/logos/logo_128.png', | ||
types: 'img/png', | ||
sizes: '128x128', | ||
purpose: 'maskable', | ||
}, | ||
{ | ||
src: '/logos/logo_72.png', | ||
types: 'img/png', | ||
sizes: '72x72', | ||
purpose: 'maskable', | ||
}, | ||
{ | ||
src: '/logos/logo_48.png', | ||
types: 'img/png', | ||
sizes: '48x48', | ||
purpose: 'maskable', | ||
}, | ||
], | ||
}, | ||
integration: { | ||
configureOptions(viteConfig, options) { | ||
if (viteConfig.command === 'build') | ||
options.includeAssets = fg.sync('**/*.*', { cwd: join(process.cwd(), 'public'), onlyFiles: true }) | ||
}, | ||
}, | ||
devOptions: { | ||
enabled: process.env.PWA_DEV === 'true', | ||
type: 'module', | ||
navigateFallback: 'index.html', | ||
}, | ||
}) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
importScripts('https://cdn.jsdelivr.net/npm/workbox-cdn/workbox/workbox-sw.js') | ||
|
||
self.addEventListener('install', () => { | ||
self.skipWaiting() | ||
}) | ||
|
||
self.addEventListener('activate', () => { | ||
self.clients.claim() | ||
}) | ||
|
||
// Navigation route are handled by network first strategy | ||
workbox.routing.registerRoute( | ||
({ request }) => request.mode === 'navigate', | ||
new workbox.strategies.NetworkFirst({ cacheName: 'navigation' }) | ||
) | ||
|
||
// CSS are handled by a Stale While Revalidate strategy | ||
workbox.routing.registerRoute( | ||
({ request }) => request.destination === 'style', | ||
new workbox.strategies.StaleWhileRevalidate({ | ||
cacheName: 'assets', | ||
plugins: [ | ||
// Ensure that only requests that result in a 200 status are cached | ||
new workbox.cacheableResponse.CacheableResponse({ | ||
statuses: [200] | ||
}) | ||
] | ||
}) | ||
) | ||
|
||
// Images are handled with a Cache First strategy | ||
workbox.routing.registerRoute( | ||
({ request }) => request.destination === 'image', | ||
new workbox.strategies.CacheFirst({ | ||
cacheName: 'images', | ||
plugins: [ | ||
// Ensure that only requests that result in a 200 status are cached | ||
new workbox.cacheableResponse.CacheableResponse({ | ||
statuses: [200] | ||
}), | ||
// Don't cache more than 50 items, and expire them after 30 days | ||
new workbox.expiration.CacheExpiration('images', { | ||
maxEntries: 50, | ||
maxAgeSeconds: 60 * 60 * 24 * 30 // 30 Days | ||
}) | ||
] | ||
}) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,6 @@ | |
"build/**/*.ts", | ||
"build/**/*.d.ts", | ||
"vite.config.ts" | ||
], | ||
], | ||
"exclude": ["node_modules", "dist", "**/*.js"] | ||
} |