mirror of
https://github.com/revoltchat/revite.git
synced 2024-11-25 16:40:58 -05:00
Use custom service worker.
This commit is contained in:
parent
c52f1f5bca
commit
d74bc1d8e8
5 changed files with 24 additions and 11 deletions
|
@ -83,6 +83,7 @@
|
||||||
"ulid": "^2.3.0",
|
"ulid": "^2.3.0",
|
||||||
"use-resize-observer": "^7.0.0",
|
"use-resize-observer": "^7.0.0",
|
||||||
"vite": "^2.3.7",
|
"vite": "^2.3.7",
|
||||||
"vite-plugin-pwa": "^0.8.1"
|
"vite-plugin-pwa": "^0.8.1",
|
||||||
|
"workbox-precaching": "^6.1.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,4 @@
|
||||||
import { render } from "preact";
|
|
||||||
import "./styles/index.scss";
|
|
||||||
import { App } from "./pages/app";
|
|
||||||
|
|
||||||
import { registerSW } from 'virtual:pwa-register'
|
import { registerSW } from 'virtual:pwa-register'
|
||||||
|
|
||||||
const updateSW = registerSW({
|
const updateSW = registerSW({
|
||||||
onNeedRefresh() {
|
onNeedRefresh() {
|
||||||
// ! FIXME: temp
|
// ! FIXME: temp
|
||||||
|
@ -16,5 +11,9 @@ const updateSW = registerSW({
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
import { render } from "preact";
|
||||||
|
import "./styles/index.scss";
|
||||||
|
import { App } from "./pages/app";
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||||
render(<App />, document.getElementById("app")!);
|
render(<App />, document.getElementById("app")!);
|
||||||
|
|
11
src/sw.ts
Normal file
11
src/sw.ts
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
/// <reference lib="webworker" />
|
||||||
|
import { precacheAndRoute } from 'workbox-precaching'
|
||||||
|
|
||||||
|
declare let self: ServiceWorkerGlobalScope
|
||||||
|
|
||||||
|
self.addEventListener('message', (event) => {
|
||||||
|
if (event.data && event.data.type === 'SKIP_WAITING')
|
||||||
|
self.skipWaiting()
|
||||||
|
})
|
||||||
|
|
||||||
|
precacheAndRoute(self.__WB_MANIFEST)
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "ESNext",
|
"target": "ESNext",
|
||||||
"lib": ["DOM", "DOM.Iterable", "ESNext"],
|
"lib": ["DOM", "DOM.Iterable", "ESNext", "WebWorker"],
|
||||||
"allowJs": false,
|
"allowJs": false,
|
||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
"esModuleInterop": false,
|
"esModuleInterop": false,
|
||||||
|
|
|
@ -23,9 +23,12 @@ export default defineConfig({
|
||||||
plugins: [
|
plugins: [
|
||||||
preact(),
|
preact(),
|
||||||
VitePWA({
|
VitePWA({
|
||||||
|
srcDir: 'src',
|
||||||
|
filename: 'sw.ts',
|
||||||
|
strategies: 'injectManifest',
|
||||||
manifest: {
|
manifest: {
|
||||||
name: "Revolt",
|
name: "REVOLT",
|
||||||
short_name: "Revolt",
|
short_name: "REVOLT",
|
||||||
description: "User-first, privacy-focused chat platform.",
|
description: "User-first, privacy-focused chat platform.",
|
||||||
categories: ["messaging"],
|
categories: ["messaging"],
|
||||||
start_url: "/",
|
start_url: "/",
|
||||||
|
@ -44,8 +47,7 @@ export default defineConfig({
|
||||||
"sizes": "512x512"
|
"sizes": "512x512"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
}
|
||||||
workbox: { }
|
|
||||||
}),
|
}),
|
||||||
replace({
|
replace({
|
||||||
__GIT_REVISION__: getGitRevision(),
|
__GIT_REVISION__: getGitRevision(),
|
||||||
|
|
Loading…
Reference in a new issue