Files
cozsweet-frontend-nextjs/package.json
T
admin 67dcf97edc refactor(pwa): migrate from @ducanh2912/next-pwa to @serwist/turbopack
Next.js 16 ships Turbopack as the default bundler, but
@ducanh2912/next-pwa is webpack-only — the previous PWA setup
required `--webpack` on dev/build/"dev:proxy" scripts, accepting
a perf regression in exchange for working PWA install.

@serwist/turbopack (paired with the official 'serwist' package
and 'esbuild') is the Turbopack-native successor: it works with
the default bundler, no opt-out flag, and gives us a real TS
service worker source file we can read and edit.

What this commit does:

1. Swap deps in package.json:
   - Remove @ducanh2912/next-pwa
   - Add @serwist/turbopack, serwist, esbuild (all devDeps)
   - Drop --webpack flag from dev / dev:proxy / build scripts
     (Turbopack is restored as the bundler)

2. next.config.ts:
   - Replace withPWAInit wrapping with withSerwist named import
   - Update comment block to describe new architecture

3. New src/app/sw.ts: Serwist service worker source.
   skipWaiting + clientsClaim + navigationPreload + defaultCache.
   This file is compiled to a real SW at build time by Serwist.

4. New src/app/serwist/[[...slug]]/route.ts: catch-all Route
   Handler that serves the compiled SW at /serwist/sw.js plus
   Serwist's chunked runtime assets. Catch-all is required
   because Serwist serves multiple files under /serwist/.

5. src/app/layout.tsx: replace <SwRegister /> with
   <SerwistProvider swUrl="/serwist/sw.js"> from
   @serwist/turbopack/react. The provider handles registration
   + lifecycle internally.

6. Delete src/app/_components/core/sw-register.tsx: replaced
   by SerwistProvider.

7. .gitignore: add public/sw.js and public/workbox-*.js
   (defensive — these are build artifacts that change hash
   every build and shouldn't be committed).

8. Untrack public/workbox-3c9d0171.js: stale workbox runtime
   from the previous next-pwa build, hash is build-specific
   so it can never be regenerated correctly.

Not modified (intentionally):
- src/utils/pwa.ts: pure beforeinstallprompt browser-API wrapper,
  library-agnostic, stays as-is.
- pwa-install-overlay / pwa-install-dialog: install UI flow
  unchanged.
- public/manifest.json: still works; layout's metadata.manifest
  points at it.

Verification:
- pnpm install resolved cleanly (added 24 pkgs, removed 209)
- npx tsc --noEmit passes (EXIT=0)
- Serwist provides named exports, not default — withSerwist and
  createSerwistRoute are both named imports
2026-06-17 11:09:36 +08:00

61 lines
1.5 KiB
JSON

{
"name": "cozsweet-frontend-nextjs",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"dev:proxy": "HTTPS_PROXY=http://127.0.0.1:7891 next dev",
"build": "next build",
"start": "next start -p 9135",
"build:start": "npm run build && npm run start",
"lint": "eslint",
"lint:fix": "eslint --fix",
"test": "vitest run",
"test:watch": "vitest",
"test:ui": "vitest --ui",
"generate-barrels": "barrelsby --delete -c barrelsby.json"
},
"dependencies": {
"@fingerprintjs/fingerprintjs": "^5.2.0",
"@stripe/stripe-js": "^9.8.0",
"@xstate/react": "^5",
"classnames": "^2.5.1",
"dexie": "^4.4.3",
"lottie-react": "^2.4.1",
"lucide-react": "^1.18.0",
"next": "16.2.7",
"next-auth": "^4.24.14",
"ofetch": "^1.5.1",
"pino": "^10.3.1",
"react": "19.2.4",
"react-dom": "19.2.4",
"stripe": "^22.2.1",
"unstorage": "^1.17.5",
"xstate": "^5",
"zod": "^4.4.3"
},
"devDependencies": {
"@serwist/turbopack": "^9.0.0",
"esbuild": "^0.25.0",
"serwist": "^9.0.0",
"@tailwindcss/postcss": "^4",
"@types/node": "^20",
"@types/react": "^19",
"@types/react-dom": "^19",
"@vitest/coverage-v8": "^4.1.8",
"@vitest/ui": "^4.1.8",
"barrelsby": "^2.8.1",
"eslint": "^9",
"eslint-config-next": "16.2.7",
"jsdom": "^29.1.1",
"tailwindcss": "^4",
"typescript": "^5",
"vitest": "^4.1.8"
},
"pnpm": {
"onlyBuiltDependencies": [
"*"
]
}
}