diff options
author | 2021-11-22 20:03:45 -0600 | |
---|---|---|
committer | 2021-11-22 20:03:45 -0600 | |
commit | f165004c10448d0f0f0d09093a44c8e01475ea68 (patch) | |
tree | a7827b0fdc3e7b3e82b7f8ff99b4db3375147135 /examples/with-vite-plugin-pwa/src | |
parent | df4671788c35e01c238a10b39df70c812828a19a (diff) | |
download | astro-f165004c10448d0f0f0d09093a44c8e01475ea68.tar.gz astro-f165004c10448d0f0f0d09093a44c8e01475ea68.tar.zst astro-f165004c10448d0f0f0d09093a44c8e01475ea68.zip |
Add `with-vite-plugin-pwa` example (#1829)
Diffstat (limited to 'examples/with-vite-plugin-pwa/src')
-rw-r--r-- | examples/with-vite-plugin-pwa/src/index.ts | 10 | ||||
-rw-r--r-- | examples/with-vite-plugin-pwa/src/pages/index.astro | 18 | ||||
-rw-r--r-- | examples/with-vite-plugin-pwa/src/vite-env.d.ts | 11 |
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> +} |