cm_whatsapp_bot_v1/apps/web/package.json
yiekheng 272fbcfa8a feat(web): PWA via @serwist/next + manifest + icons (P3/T22)
The web app is now installable on a phone home screen with offline
fallback for static assets and the navigation shell.

Pieces
------
- `src/app/manifest.webmanifest/route.ts` — dynamic manifest route.
  Standalone display mode, portrait orientation, dark theme matching
  the app, "any maskable" icons so the same PNG works for both
  regular launchers and Android adaptive icons.

- `src/pwa/sw.ts` — service worker entry. Uses serwist's stock
  recipe: skipWaiting + clientsClaim so a new worker takes over on
  the next navigation, navigationPreload to race the network with
  the worker boot, and `defaultCache` for HTML-network-first /
  static-cache-first / image+font cache TTLs.

- `next.config.ts` — wraps the existing config with `withSerwistInit`.
  Disabled in development (`NODE_ENV !== "production"`) because a
  service worker on every dev reload makes hot-reload extremely
  flaky.

- `package.json` build script switched to `next build --webpack`.
  `@serwist/next` doesn't yet support Turbopack (it logs a warning
  and silently skips emitting `sw.js`), and Next 16 defaults the
  build to Turbopack. The dev server still uses Turbopack — only
  production builds switch to webpack.

- `src/app/layout.tsx` metadata gains `manifest`, `icons.icon` (192
  + 512 PNG), and `icons.apple` (180 PNG). The existing
  `appleWebApp.capable` already opts iOS into standalone mode.

Icons
-----
Generated by a tiny one-shot script (`scripts/gen-pwa-icons.ts`)
that uses the workspace's already-installed sharp to render an SVG
wordmark at 512 / 192 / 180 px. Placeholder branding (dark square
with "cm" wordmark) — swap in real artwork later by editing the SVG
in the script and re-running `pnpm --filter @cmbot/web run gen:icons`.

Build artefacts
---------------
- `apps/web/public/icon-512.png`, `icon-192.png`,
  `apple-touch-icon.png` ARE committed (stable input).
- `apps/web/public/sw.js` and `swe-worker-*.js` are NOT — they're
  regenerated on every production build. Added to `.gitignore`.

Verification
------------
- Production build emits `[serwist] Bundling the service worker
  script with the URL '/sw.js' and the scope '/'...` and `sw.js`
  shows up in `public/`.
- `/manifest.webmanifest` is in the build's static-route table.
- 249 web tests still passing.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-10 13:20:45 +08:00

60 lines
1.5 KiB
JSON

{
"name": "@cmbot/web",
"version": "0.1.0",
"private": true,
"type": "module",
"scripts": {
"dev": "next dev --hostname 0.0.0.0",
"build": "next build --webpack",
"start": "next start --hostname 0.0.0.0",
"lint": "next lint",
"typecheck": "tsc --noEmit",
"test": "vitest run",
"gen:icons": "tsx scripts/gen-pwa-icons.ts"
},
"dependencies": {
"@cmbot/db": "workspace:*",
"@cmbot/shared": "workspace:*",
"@hookform/resolvers": "^5.2.2",
"@serwist/next": "^9.5.11",
"@types/luxon": "^3.4.2",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"drizzle-orm": "^0.36.0",
"geist": "^1.7.0",
"lucide-react": "^1.14.0",
"luxon": "^3.5.0",
"next": "^16.0.0",
"next-themes": "^0.4.6",
"pg": "^8.13.0",
"pino": "^9.5.0",
"pino-pretty": "^11.3.0",
"qrcode": "^1.5.4",
"radix-ui": "^1.4.3",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"react-hook-form": "^7.75.0",
"server-only": "^0.0.1",
"serwist": "^9.5.11",
"shadcn": "^4.7.0",
"sonner": "^2.0.7",
"tailwind-merge": "^3.5.0",
"tw-animate-css": "^1.4.0",
"zod": "^3.23.8"
},
"devDependencies": {
"@tailwindcss/postcss": "^4.0.0",
"@types/node": "^22.7.0",
"@types/pg": "^8.11.10",
"@types/qrcode": "^1.5.5",
"@types/react": "^19.0.0",
"@types/react-dom": "^19.0.0",
"@vitest/ui": "^2.1.9",
"sharp": "^0.34.5",
"tailwindcss": "^4.0.0",
"tsx": "^4.19.0",
"typescript": "^5.5.0",
"vitest": "^2.1.9"
}
}