Skip to content

Commit a3a97de

Browse files
committed
refactor(pwa): use generateSW strategy
1 parent e52f5f7 commit a3a97de

File tree

4 files changed

+26
-56
lines changed

4 files changed

+26
-56
lines changed

package.json

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
"vite": "^7.3.1",
3232
"vite-plugin-pwa": "^1.2.0",
3333
"vue": "^3.5.29",
34-
"vue-dompurify-html": "^5.3.0"
34+
"vue-dompurify-html": "^5.3.0",
35+
"workbox-window": "^7.4.0"
3536
},
3637
"devDependencies": {
3738
"@antfu/eslint-config": "7.4.3",
@@ -55,13 +56,7 @@
5556
"type-fest": "^5.4.4",
5657
"typescript": "^5.9.3",
5758
"vue-router": "^5.0.3",
58-
"vue-tsc": "^3.2.5",
59-
"workbox-build": "^7.4.0",
60-
"workbox-core": "^7.4.0",
61-
"workbox-precaching": "^7.4.0",
62-
"workbox-routing": "^7.4.0",
63-
"workbox-strategies": "^7.4.0",
64-
"workbox-window": "^7.4.0"
59+
"vue-tsc": "^3.2.5"
6560
},
6661
"pnpm": {
6762
"overrides": {

pnpm-lock.yaml

Lines changed: 3 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/constants/pwa-options.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,28 @@ const manifest: Partial<ManifestOptions> = {
1818

1919
const pwaOptions: Partial<VitePWAOptions> = {
2020
base: "/",
21-
strategies: "injectManifest",
22-
srcDir: "src",
23-
filename: "sw.ts",
21+
strategies: "generateSW",
22+
registerType: "autoUpdate",
2423
includeAssets: ["favicon.ico", "robots.txt", "apple-touch-icon.png"],
2524
manifest,
26-
workbox: { sourcemap: true }
25+
workbox: {
26+
sourcemap: true,
27+
cleanupOutdatedCaches: true,
28+
navigateFallback: "/index.html",
29+
runtimeCaching: [
30+
{
31+
urlPattern: /\.(?:png|jpe?g|svg|webp|woff2)$/,
32+
handler: "CacheFirst",
33+
options: {
34+
cacheName: "asset-cache",
35+
expiration: {
36+
maxEntries: 60,
37+
maxAgeSeconds: 30 * 24 * 60 * 60 // 30 days
38+
}
39+
}
40+
}
41+
]
42+
}
2743
};
2844

2945
export default pwaOptions;

src/sw.ts

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)