summaryrefslogtreecommitdiff
path: root/examples/with-vite-plugin-pwa/src
diff options
context:
space:
mode:
Diffstat (limited to 'examples/with-vite-plugin-pwa/src')
-rw-r--r--examples/with-vite-plugin-pwa/src/index.ts10
-rw-r--r--examples/with-vite-plugin-pwa/src/pages/index.astro18
-rw-r--r--examples/with-vite-plugin-pwa/src/vite-env.d.ts11
3 files changed, 39 insertions, 0 deletions
diff --git a/examples/with-vite-plugin-pwa/src/index.ts b/examples/with-vite-plugin-pwa/src/index.ts
new file mode 100644
index 000000000..af679697f
--- /dev/null
+++ b/examples/with-vite-plugin-pwa/src/index.ts
@@ -0,0 +1,10 @@
+import { registerSW } from 'virtual:pwa-register'
+
+const updateSW = registerSW({
+ onNeedRefresh() {},
+ onOfflineReady() {
+ console.log("Offline ready");
+ }
+})
+
+updateSW();
diff --git a/examples/with-vite-plugin-pwa/src/pages/index.astro b/examples/with-vite-plugin-pwa/src/pages/index.astro
new file mode 100644
index 000000000..008442824
--- /dev/null
+++ b/examples/with-vite-plugin-pwa/src/pages/index.astro
@@ -0,0 +1,18 @@
+---
+---
+
+<html lang="en">
+
+<head>
+ <meta charset="utf-8" />
+ <link rel="icon" type="image/x-icon" href="/favicon.ico" />
+ <meta name="viewport" content="width=device-width" />
+ <title>Welcome to Astro</title>
+</head>
+
+<body>
+ <h1>Welcome to <a href="https://astro.build/">Astro</a></h1>
+ <script src={Astro.resolve('../index.ts')} type="module" hoist />
+</body>
+
+</html>
diff --git a/examples/with-vite-plugin-pwa/src/vite-env.d.ts b/examples/with-vite-plugin-pwa/src/vite-env.d.ts
new file mode 100644
index 000000000..6b2c10cd8
--- /dev/null
+++ b/examples/with-vite-plugin-pwa/src/vite-env.d.ts
@@ -0,0 +1,11 @@
+declare module 'virtual:pwa-register' {
+ export type RegisterSWOptions = {
+ immediate?: boolean
+ onNeedRefresh?: () => void
+ onOfflineReady?: () => void
+ onRegistered?: (registration: ServiceWorkerRegistration | undefined) => void
+ onRegisterError?: (error: any) => void
+ }
+
+ export function registerSW(options?: RegisterSWOptions): (reloadPage?: boolean) => Promise<void>
+}