Skip to content

Commit

Permalink
simplify pwa
Browse files Browse the repository at this point in the history
  • Loading branch information
fivaz committed Jun 22, 2024
1 parent 3706e95 commit 92a8420
Show file tree
Hide file tree
Showing 19 changed files with 1,453 additions and 227 deletions.
2 changes: 2 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ module.exports = {
'^\\$app/environment',
'^\\$env/static/public',
'^\\$service-worker',
'virtual:pwa-assets',
'virtual:pwa-info',
],
},
],
Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
"@types/eslint": "8.56.0",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"@vite-pwa/assets-generator": "^0.2.4",
"@vite-pwa/sveltekit": "^0.5.0",
"autoprefixer": "^10.4.17",
"clsx": "^2.1.0",
"date-fns": "^3.3.1",
Expand Down Expand Up @@ -65,8 +67,9 @@
"tslib": "^2.4.1",
"typescript": "^5.0.0",
"vite": "^5.0.3",
"vite-plugin-pwa": "^0.20.0",
"vitest": "^1.2.0",
"workbox-precaching": "^7.0.0",
"workbox-window": "^7.1.0",
"yup": "^1.3.3"
},
"name": "life",
Expand All @@ -81,7 +84,7 @@
"format": "prettier --write . && eslint . --fix",
"lint": "prettier --check . && eslint .",
"prepare": "husky",
"preview": "vite build && vite preview",
"preview": "vite preview",
"storybook": "storybook dev -p 6006",
"test": "npm run test:integration && npm run test:unit",
"test:integration": "playwright test",
Expand Down
1,524 changes: 1,376 additions & 148 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions pwa-assets.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineConfig, minimal2023Preset as preset } from '@vite-pwa/assets-generator/config';

export default defineConfig({
headLinkOptions: {
preset: '2023',
},
images: ['static/logo.svg'],
preset,
});
3 changes: 3 additions & 0 deletions src/app.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import 'vite-plugin-pwa/svelte';
import 'vite-plugin-pwa/info';
import 'vite-plugin-pwa/pwa-assets';
// See https://kit.svelte.dev/docs/types#app
// for information about these interfaces
declare global {
Expand Down
5 changes: 1 addition & 4 deletions src/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%sveltekit.assets%/favicon.png" />

<meta name="viewport" content="width=device-width, initial-scale=1" />
%sveltekit.head%
<link rel="manifest" href="%sveltekit.assets%/manifest.json" />
<title>Life</title>
<link rel="icon" href="%sveltekit.assets%/icon.svg" />
</head>
<body data-sveltekit-preload-data="hover">
<div style="display: contents">%sveltekit.body%</div>
Expand Down
15 changes: 15 additions & 0 deletions src/routes/+layout.svelte
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
<script lang="ts">
import { auth, db } from '$lib/firebase';
import { FirebaseApp } from 'sveltefire';
import { pwaAssetsHead } from 'virtual:pwa-assets/head';
import { pwaInfo } from 'virtual:pwa-info';
import '../app.css';
$: webManifest = pwaInfo ? pwaInfo.webManifest.linkTag : '';
</script>

<svelte:head>
{#if pwaAssetsHead.themeColor}
<meta content={pwaAssetsHead.themeColor.content} name="theme-color" />
{/if}
{#each pwaAssetsHead.links as link}
<link {...link} />
{/each}
<!-- eslint-disable-next-line svelte/no-at-html-tags -->
{@html webManifest}
</svelte:head>

<FirebaseApp {auth} firestore={db}>
<slot />
</FirebaseApp>
17 changes: 0 additions & 17 deletions src/service-worker.ts

This file was deleted.

Binary file removed static/favicon.png
Binary file not shown.
18 changes: 0 additions & 18 deletions static/icon.svg

This file was deleted.

Binary file removed static/icon256.png
Binary file not shown.
Binary file removed static/icon512.png
Binary file not shown.
4 changes: 4 additions & 0 deletions static/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 0 additions & 34 deletions static/manifest.json

This file was deleted.

Binary file removed static/screenshot1.png
Binary file not shown.
Binary file removed static/screenshot2.png
Binary file not shown.
Binary file removed static/task-placeholder-image.webp
Binary file not shown.
4 changes: 2 additions & 2 deletions svelte.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// import adapter from '@sveltejs/adapter-auto';
import adapter from '@sveltejs/adapter-auto';
// import adapter from '@sveltejs/adapter-static';
// import adapter from 'svelte-adapter-firebase';
import adapter from '@sveltejs/adapter-vercel';
// import adapter from '@sveltejs/adapter-vercel';
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';

/** @type {import('@sveltejs/kit').Config} */
Expand Down
38 changes: 36 additions & 2 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,45 @@
import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vitest/config';
import { SvelteKitPWA } from '@vite-pwa/sveltekit';
import { defineConfig } from 'vite';

export default defineConfig({
define: {
'process.env.NODE_ENV': '"production"',
},
plugins: [sveltekit()],
plugins: [
sveltekit(),
SvelteKitPWA({
devOptions: {
enabled: false,
navigateFallback: '/',
navigateFallbackAllowlist: [/^\/$/],
suppressWarnings: true,
type: 'module',
},
injectRegister: false,

manifest: {
description: 'life',
name: 'life',
short_name: 'life',
theme_color: '#ffffff',
},

pwaAssets: {
config: true,
disabled: false,
},

registerType: 'autoUpdate',

workbox: {
cleanupOutdatedCaches: true,

clientsClaim: true,
globPatterns: ['client/**/*.{js,css,ico,png,svg,webp,woff,woff2}'],
},
}),
],
test: {
include: ['src/**/*.{test,spec}.{js,ts}'],
},
Expand Down

0 comments on commit 92a8420

Please sign in to comment.