From 94f4c664729cd73d5d127b13ebf8616840112004 Mon Sep 17 00:00:00 2001 From: MaheshtheDev Date: Thu, 8 Aug 2024 12:07:37 -0700 Subject: [PATCH] Add PWA Support for Web App --- apps/web/.gitignore | 11 +++++++++++ apps/web/app/layout.tsx | 1 + apps/web/next.config.mjs | 15 +++++++++++---- apps/web/package.json | 1 + apps/web/public/manifest.webmanifest | 21 +++++++++++++++++++++ 5 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 apps/web/public/manifest.webmanifest diff --git a/apps/web/.gitignore b/apps/web/.gitignore index 7d7c7a5f..4d28f221 100644 --- a/apps/web/.gitignore +++ b/apps/web/.gitignore @@ -1,3 +1,14 @@ # Sentry Config File .env.sentry-build-plugin + +# next-pwa +/public/sw.js +/public/workbox-*.js +/public/worker-*.js +/public/fallback-*.js +/public/precache.*.*.js.map +/public/sw.js.map +/public/workbox-*.js.map +/public/worker-*.js.map +/public/fallback-*.js \ No newline at end of file diff --git a/apps/web/app/layout.tsx b/apps/web/app/layout.tsx index 49805c16..f74ee232 100644 --- a/apps/web/app/layout.tsx +++ b/apps/web/app/layout.tsx @@ -59,6 +59,7 @@ export const metadata: Metadata = { }, ], }, + manifest: "/manifest.webmanifest", }; export default function RootLayout({ diff --git a/apps/web/next.config.mjs b/apps/web/next.config.mjs index 307d5bdc..ef57aecc 100644 --- a/apps/web/next.config.mjs +++ b/apps/web/next.config.mjs @@ -1,6 +1,6 @@ import MillionLint from "@million/lint"; import { setupDevPlatform } from "@cloudflare/next-on-pages/next-dev"; - +import pwa from "next-pwa"; /** @type {import('next').NextConfig} */ const baseNextConfig = { transpilePackages: ["@repo/ui"], @@ -13,15 +13,22 @@ const baseNextConfig = { }, }; -let selectedCofig = baseNextConfig; +const withPWA = pwa({ + dest: "public", + disable: process.env.NODE_ENV === "development", + register: true, + skipWaiting: true, +}); + +let selectedConfig = baseNextConfig; if (process.env.NODE_ENV === "development") { - selectedCofig = MillionLint.next({ + selectedConfig = MillionLint.next({ rsc: true, })(baseNextConfig); } -export default selectedCofig; +export default withPWA(selectedConfig); // we only need to use the utility during development so we can check NODE_ENV // (note: this check is recommended but completely optional) diff --git a/apps/web/package.json b/apps/web/package.json index 4c0d57cd..109d7907 100644 --- a/apps/web/package.json +++ b/apps/web/package.json @@ -28,6 +28,7 @@ "lowlight": "^3.1.0", "million": "^3.1.6", "next": "^14.1.1", + "next-pwa": "^5.6.0", "novel": "^0.4.2", "nuqs": "^1.17.4", "posthog-js": "^1.154.5", diff --git a/apps/web/public/manifest.webmanifest b/apps/web/public/manifest.webmanifest new file mode 100644 index 00000000..5d4c0bd7 --- /dev/null +++ b/apps/web/public/manifest.webmanifest @@ -0,0 +1,21 @@ +{ + "name": "Supermemory - your second brain.", + "short_name": "Supermemory", + "icons": [ + { + "src": "/icons/android-chrome-192x192.png", + "sizes": "192x192", + "type": "image/png" + }, + { + "src": "/icons/android-chrome-512x512.png", + "sizes": "512x512", + "type": "image/png" + } + ], + "theme_color": "#ffffff", + "background_color": "#ffffff", + "scope": "/", + "start_url": "/", + "display": "standalone" +}