From 242be73c7894c318b3b0e42db0453229efa1e8a0 Mon Sep 17 00:00:00 2001 From: Spythere Date: Tue, 3 Jan 2023 01:29:15 +0100 Subject: [PATCH] pwa: automatyczny reload --- package.json | 2 +- src/App.vue | 4 +++- src/main.ts | 14 +++++++++++--- tsconfig.json | 5 ++++- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 5bbed2c..fec7cd6 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "scripts": { "dev": "vite", "build": "vue-tsc --noEmit && vite build", - "preview": "vite preview" + "preview": "yarn build && vite preview --port 4174" }, "dependencies": { "pinia": "^2.0.17", diff --git a/src/App.vue b/src/App.vue index 87ce1d1..a706c30 100644 --- a/src/App.vue +++ b/src/App.vue @@ -69,7 +69,9 @@ export default defineComponent({ }), async created() { - const stockData = await (await fetch(`https://spythere.github.io/api/stockDataNew.json?t=${Math.floor(Date.now() / 60000)}`)).json(); + const stockData = await ( + await fetch(`https://spythere.github.io/api/stockDataNew.json?t=${Math.floor(Date.now() / 60000)}`) + ).json(); this.store.stockData = stockData; }, diff --git a/src/main.ts b/src/main.ts index 00c5b47..ec0a36f 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,10 +1,18 @@ import { createApp } from 'vue'; import { createPinia } from 'pinia'; +import { registerSW } from 'virtual:pwa-register'; + import App from './App.vue'; const pinia = createPinia(); -createApp(App) - .use(pinia) - .mount('#app'); +const updateSW = registerSW({ + onOfflineReady() {}, + + onNeedRefresh() { + console.log('Need refresh!'); + }, +}); + +createApp(App).use(pinia).mount('#app'); diff --git a/tsconfig.json b/tsconfig.json index d4aefa2..3d125f6 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,7 +11,10 @@ "isolatedModules": true, "esModuleInterop": true, "lib": ["ESNext", "DOM"], - "skipLibCheck": true + "skipLibCheck": true, + "types": [ + "vite-plugin-pwa/client" + ] }, "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"], "references": [{ "path": "./tsconfig.node.json" }]