Skip to content

Commit

Permalink
Vite PWA manifest and runtime cache
Browse files Browse the repository at this point in the history
  • Loading branch information
yuugou727 committed May 10, 2023
1 parent 1a02873 commit 555908c
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 45 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
# dependencies
/node_modules

#dev
dev-dist

# testing
/coverage

Expand Down
5 changes: 0 additions & 5 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="theme-color" content="#000">
<!--
manifest.json provides metadata used when your web app is added to the
homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/
-->
<link rel="manifest" href="/manifest.webmanifest">
<link rel="shortcut icon" href="/icons8-clock-192.png">
<title>台灣天氣時鐘</title>
<meta name="description" content="簡易的台灣天氣時鐘 Progressive Web App,舊手機變身實用桌鐘">
Expand Down
8 changes: 5 additions & 3 deletions public/manifest.webmanifest → manifestOption.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
{
import { ManifestOptions } from 'vite-plugin-pwa';

export const manifestOption: Partial<ManifestOptions> = {
"name": "台灣天氣時鐘",
"short_name": "TW天氣時鐘",
"icons": [
{
"src": "icons8-clock-192.png",
"type": "image/png",
"sizes": "192x192 128x128 64x64 32x32 24x24 16x16"
"sizes": "192x192"
},
{
"src": "icons8-clock-512.png",
Expand All @@ -20,4 +22,4 @@
"description": "簡易的時鐘網頁附加台灣天氣資訊,舊手機變身實用桌鐘",
"dir": "ltr",
"lang": "zh-TW"
}
};
52 changes: 33 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 2 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "weather-clock",
"version": "1.4.0",
"version": "1.4.1",
"private": true,
"dependencies": {
"@types/node": "^18.11.18",
Expand All @@ -15,19 +15,7 @@
"react-toastify": "^9.1.1",
"typescript": "^4.9.4",
"web-vitals": "^3.1.1",
"whatwg-fetch": "^3.6.2",
"workbox-background-sync": "^6.5.4",
"workbox-broadcast-update": "^6.5.4",
"workbox-cacheable-response": "^6.5.4",
"workbox-core": "^6.5.4",
"workbox-expiration": "^6.5.4",
"workbox-google-analytics": "^6.5.4",
"workbox-navigation-preload": "^6.5.4",
"workbox-precaching": "^6.5.4",
"workbox-range-requests": "^6.5.4",
"workbox-routing": "^6.5.4",
"workbox-strategies": "^6.5.4",
"workbox-streams": "^6.5.4"
"whatwg-fetch": "^3.6.2"
},
"scripts": {
"start": "vite",
Expand Down
1 change: 0 additions & 1 deletion src/react-app-env.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/vite-env.d.ts

This file was deleted.

3 changes: 3 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
"dom.iterable",
"esnext"
],
"types": [
"vite/client",
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
Expand Down
26 changes: 24 additions & 2 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,36 @@ import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import viteTsconfigPaths from "vite-tsconfig-paths";
import { VitePWA } from 'vite-plugin-pwa';
import { manifestOption } from './manifestOption';

/// <reference types="vitest" />
export default defineConfig({
plugins: [
react(),
viteTsconfigPaths(),
VitePWA({
injectRegister: 'auto'
registerType: 'autoUpdate',
devOptions: {
enabled: true,
},
manifest: manifestOption,
workbox: {
runtimeCaching: [
{
urlPattern: /^https:\/\/openweathermap\.org\/img\/wn\/.*\.png$/i,
handler: 'CacheFirst',
options: {
cacheName: 'openweathermap-icons',
expiration: {
maxEntries: 10,
maxAgeSeconds: 60 * 60 * 24 * 30 // 30 days
},
cacheableResponse: {
statuses: [0, 200]
}
}
}
]
}
}),
],
build: {
Expand Down

0 comments on commit 555908c

Please sign in to comment.