Skip to content

Commit

Permalink
chore: use pwa plugin latest release
Browse files Browse the repository at this point in the history
chore: add pwa plugin as peer dep
cleanup: remove local pwa plugin tgz
  • Loading branch information
userquin committed Sep 21, 2022
1 parent 653dee7 commit 526a000
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 55 deletions.
1 change: 0 additions & 1 deletion examples/sveltekit-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"lint-fix": "nr lint --fix"
},
"devDependencies": {
"@rollup/plugin-replace": "^4.0.0",
"@sveltejs/adapter-static": "next",
"@sveltejs/kit": "next",
"@types/cookie": "^0.5.1",
Expand Down
6 changes: 6 additions & 0 deletions examples/sveltekit-ts/src/app.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
/// <reference types="vite-plugin-pwa/client" />
/// <reference types="vite-plugin-pwa/info" />

declare const __DATE__: string
declare const __RELOAD_SW__: boolean

// See https://kit.svelte.dev/docs/types#app
// for information about these interfaces
// and what to do when importing types
declare namespace App {
interface Locals {
userid: string;
buildDate: string;
periodicUpdates: boolean
}

// interface PageData {}
Expand Down
3 changes: 2 additions & 1 deletion examples/sveltekit-ts/src/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%sveltekit.assets%/favicon.svg" />
<link rel="icon" href="%sveltekit.assets%/favicon.svg" type="image/svg+xml" />
<link rel="alternate icon" href="%sveltekit.assets%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" href="/favicon.svg" type="image/svg+xml">
<link rel="apple-touch-icon" href="/pwa-192x192.png">
Expand Down
17 changes: 10 additions & 7 deletions examples/sveltekit-ts/src/lib/ReloadPrompt.svelte
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<script lang="ts">
import { useRegisterSW } from 'virtual:pwa-register/svelte'
import { useRegisterSW } from 'virtual:pwa-register/svelte';
// replaced dynamically
const buildDate = '__DATE__'
// replaced dynamically: we need to use `JSON.parse` to allow compare to reloadSW==='true'
// if used with literal it will be removed, since it is evaluated at build time by sveltekit
const reloadSW = JSON.parse('__RELOAD_SW__')
let buildDate = __DATE__
let reloadSW = __RELOAD_SW__
const {
offlineReady,
needRefresh,
updateServiceWorker
} = useRegisterSW({
onRegistered(r) {
if (reloadSW === 'true') {
if (reloadSW) {
r && setInterval(() => {
console.log('Checking for sw update')
r.update()
Expand All @@ -28,6 +28,7 @@
offlineReady.set(false)
needRefresh.set(false)
}
$: toast = $offlineReady || $needRefresh
</script>

Expand Down Expand Up @@ -55,7 +56,9 @@
</div>
{/if}

<div class='pwa-date'>{buildDate}</div>
<div class='pwa-date'>
{ buildDate }
</div>

<style>
.pwa-date {
Expand Down
4 changes: 2 additions & 2 deletions examples/sveltekit-ts/src/lib/header/Header.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import logo from './svelte-logo.svg';
// replaced dynamically
const date = '__DATE__';
const buildDate = __DATE__
</script>

<header>
Expand Down Expand Up @@ -31,7 +31,7 @@
</nav>

<div class="corner">
{ date }
{ buildDate }
</div>
</header>

Expand Down
6 changes: 3 additions & 3 deletions examples/sveltekit-ts/src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
loadRPC && (ReloadPrompt = (await import('$lib/ReloadPrompt.svelte')).default)
})
$: webManifest = pwaInfo ? pwaInfo.webManifest.linkTag : ''
</script>

<svelte:head>
{#if pwaInfo}
{@html pwaInfo.webManifest.linkTag }
{/if}
{@html webManifest }
</svelte:head>

<Header />
Expand Down
Binary file added examples/sveltekit-ts/static/favicon.ico
Binary file not shown.
7 changes: 4 additions & 3 deletions examples/sveltekit-ts/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { sveltekit } from '@sveltejs/kit/vite';
import type { UserConfig } from 'vite';
import { SvelteKitPWA } from '@vite-pwa/sveltekit';
import replace from '@rollup/plugin-replace';

const config: UserConfig = {
logLevel: 'info',
build: {
minify: false,
},
define: {
__DATE__: `'${new Date().toISOString()}'`,
__RELOAD_SW__: false,
},
plugins: [
// @ts-expect-error not ready for Vite 3
replace({ __DATE__: new Date().toISOString(), __RELOAD_SW__: 'false' }),
sveltekit(),
SvelteKitPWA({
srcDir: './src',
Expand Down
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@vite-pwa/sveltekit",
"type": "module",
"version": "0.12.7",
"version": "0.13.0",
"packageManager": "[email protected]",
"description": "Zero-config PWA for SvelteKit",
"author": "antfu <[email protected]>",
Expand Down Expand Up @@ -49,6 +49,10 @@
"release": "npx bumpp --push --tag --commit && npm publish",
"examples": "esno scripts/run-examples.ts"
},
"peerDependencies": {
"vite-plugin-pwa": "^0.13.0",
"@types/workbox-build": "^5.0.1"
},
"devDependencies": {
"@antfu/eslint-config": "^0.26.3",
"@antfu/ni": "^0.18.0",
Expand All @@ -64,7 +68,6 @@
"typescript": "^4.8.3",
"unbuild": "^0.8.11",
"vite": "^3.1.3",
"vite-plugin-pwa": "file:vite-plugin-pwa-0.12.8.tgz",
"workbox-window": "^6.5.4"
"vite-plugin-pwa": "^0.13.0"
}
}
61 changes: 27 additions & 34 deletions pnpm-lock.yaml

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

5 changes: 4 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
"strict": true,
"moduleResolution": "node",
"noUnusedLocals": true,
"noUnusedParameters": true
"noUnusedParameters": true,
"types": [
"vite-plugin-pwa"
]
},
"exclude": [
"dist",
Expand Down
Binary file removed vite-plugin-pwa-0.12.8.tgz
Binary file not shown.

0 comments on commit 526a000

Please sign in to comment.