Skip to content

feat: ✨ add PWA support #98

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .knip.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://unpkg.com/knip@5/schema.json",
"ignore": ["src/route-tree.gen.ts"],
"ignore": ["src/route-tree.gen.ts", "pwa-assets.config.ts"],
"ignoreDependencies": ["gitzy", "@iconify-json/*"],
"eslint": {
"entry": ["eslint.config.ts"]
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- 🍞 [bun][bun] for a fast runtime and package manager.
- ⚡️ [vite][vite] for instant server start and lighting fast HMR.
- ✨ [Vite PWA](https://vite-pwa-org.netlify.app) for PWAs with very little configuration.
- 🏷️ [TypeScript][TypeScript] for a less frustrating & consistent experience.
- 🏝️ [TanStack Router][TanStack Router] for a fully type-safe React router.
- 🏝️ [TanStack Query][TanStack Query] for asynchronous state management.
Expand Down
1 change: 0 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta
name="description"
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"@types/bun": "1.1.13",
"@types/react": "18.3.12",
"@types/react-dom": "18.3.1",
"@vite-pwa/assets-generator": "0.2.6",
"@vitejs/plugin-react-swc": "3.7.1",
"@vitest/coverage-v8": "2.1.4",
"@vitest/ui": "2.1.4",
Expand All @@ -79,6 +80,7 @@
"turbo": "2.2.3",
"typescript": "5.6.3",
"vite": "5.4.10",
"vite-plugin-pwa": "0.20.5",
"vite-tsconfig-paths": "5.1.2",
"vitest": "2.1.4"
},
Expand Down
Binary file removed public/favicon.ico
Binary file not shown.
34 changes: 34 additions & 0 deletions public/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions pwa-assets.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import {
defineConfig,
minimal2023Preset as preset,
} from "@vite-pwa/assets-generator/config";

export default defineConfig({
headLinkOptions: {
preset: "2023",
},
images: ["public/logo.svg"],
preset,
});
6 changes: 5 additions & 1 deletion src/pages/home.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { ExtLink } from "@/components/ext-link";

// eslint-disable-next-line import-x/no-absolute-path -- https://vite.dev/guide/assets#the-public-directory
import logo from "/logo.svg";

export const Home = () => {
return (
<div className="grid min-h-screen place-content-center">
Expand All @@ -17,7 +20,8 @@ export const Home = () => {
React Starter
</h1>
<p className="prose dsy-prose py-6">
🍱 Another <ExtLink to="React">React</ExtLink> Starter using{" "}
<img alt="logo" className="not-prose inline max-h-6" src={logo} />{" "}
Another <ExtLink to="React">React</ExtLink> Starter using{" "}
<ExtLink to="Bun">Bun</ExtLink>, <ExtLink to="Vite">Vite</ExtLink>
, <ExtLink to="TypeScript">TypeScript</ExtLink>,{" "}
<ExtLink to="tailwindcss">tailwindcss</ExtLink> and{" "}
Expand Down
41 changes: 41 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { TanStackRouterVite as tanStackRouterVite } from "@tanstack/router-vite-plugin";
import react from "@vitejs/plugin-react-swc";
import { defineConfig, loadEnv } from "vite";
import { VitePWA } from "vite-plugin-pwa";
import tsconfigPaths from "vite-tsconfig-paths";
import { configDefaults } from "vitest/config";

Expand All @@ -18,6 +19,46 @@ export default defineConfig(({ mode }) => {
semicolons: true,
}),
tsconfigPaths(),
VitePWA({
devOptions: {
type: "module",
},
manifest: {
icons: [
{
sizes: "64x64",
src: "pwa-64x64.png",
type: "image/png",
},
{
sizes: "192x192",
src: "pwa-192x192.png",
type: "image/png",
},
{
purpose: "any",
sizes: "512x512",
src: "pwa-512x512.png",
type: "image/png",
},
{
purpose: "maskable",
sizes: "512x512",
src: "maskable-icon-512x512.png",
type: "image/png",
},
],
name: "React Starter",
short_name: "React Starter",
theme_color: "#ffffff",
},
pwaAssets: {
config: true,
disabled: false,
overrideManifestIcons: true,
},
registerType: "autoUpdate",
}),
],
server: {
port: Number(PORT),
Expand Down
Loading