
next.js無服務器的PWA帶有firebase和React鉤子

注意1:此樣板正在轉換為打字稿。有關純JavaScript,請參閱分支old-javascript
注2:這是我用於React Web應用程序的V4樣板。另請參見我的GraphQl + Postgres SQL樣板,Redux + REST + Postgres SQL樣板和Redux + REST + REST + MONGODB樣板。有關簡單的下一步。 JS著陸頁,請參見NextJs-Generic-generic-landing頁面。
您或您的公司是否發現nextjs-pwa-firebase-boilerplate有用?請考慮提供少量捐款,它可以幫助我花更多的時間在開源項目上:
這是您想要反應(帶有掛鉤) (靜態站點生成(SSG)或服務器端渲染(SSR)(由Next.js供電)作為前端和Firebase作為後端的任何項目(帶有靜態站點(SSG)或服務器端渲染(SSR)(SSR))的絕佳模板。快速閃電,所有JavaScript。
manifest.json和離線支持( next-offline )之類的功能。getStaticProps或SSR getServerSideProps 。getStaticProps / getServerSideProps 。sitemap.xml和robots.txt 。google-site-verification Support(請參閱config/config.ts )。config/config.ts和.env.local文件的靈活配置。yarn lint / yarn fix )進行代碼覆蓋和格式化。yarn unit ,尚未包括)進行單位測試。
請參閱Nextjs-pwa-firebase-boilerplate在此處的Vercel上運行。

克隆這個存儲庫:
git clone https://github.com/tomsoderlund/nextjs-pwa-firebase-boilerplate.git [MY_APP]
cd [MY_APP]
刪除.git文件夾,因為您要創建一個新的存儲庫
rm -rf .git
安裝依賴項:
yarn # or npm install
此時,您需要設置Firebase Firestore,請參見下文。
設置Firebase時,請啟動Web應用程序:
yarn dev
在生產中:
yarn build
yarn start
如果您導航到http://localhost:3004/您將看到一個帶有文章列表的網頁(或者尚未添加的網頁)。
name的“ next.js firebase pwa”,“ nextjs-pwa-firebase-boilerplate”和description “ Next.js無用PWA,帶有firebase and react鉤子”。package.json中的version更改為0.1.0或類似。package.json中的license 。主數據庫項目稱為Article ,但您可能需要應用程序中的其他內容。
重命名文件:
git mv hooks/useArticles.tsx hooks/use{NewName}s.tsx
mkdir -p components/{newName}s
git mv components/articles/CreateArticleForm.tsx components/{newName}s/Create{NewName}Form.tsx
git mv components/articles/ArticleDetails.tsx components/{newName}s/{NewName}Details.tsx
git mv components/articles/ArticleList.tsx components/{newName}s/{NewName}List.tsx
git mv components/articles/ArticleListItem.tsx components/{newName}s/{NewName}ListItem.tsx
rm -r components/articles
mkdir pages/{newName}s
git mv "pages/articles/[slug].tsx" "pages/{newName}s/[slug].tsx"
rm -r pages/articles
然後,請在文件中搜索/替換不同的外殼: article , Article , ARTICLE 。
搜索/更換3004的東西。
設置數據庫(如果您不需要數據庫,請參見下面的“如何刪除/替換為數據庫”):
firebaseConfig (從設置Firebase Web應用程序)複製到lib/data/firebase.ts.env.local文件,設置NEXT_PUBLIC_FIREBASE_API_KEY值。yarn remove firebaselib/data/firebase.ts和修改hooks/useArticles.tsx 。sql-wizard中使用createSqlRestRoutesServerless來設置自己的API路由。yarn remove firebaseyarn add @supabase/supabase-jsNEXT_PUBLIC_SUPABASE_API_KEY到.env.locallib/data/supabase.ts : import { createClient } from '@supabase/supabase-js'
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL
const supabaseKey = process.env.NEXT_PUBLIC_SUPABASE_API_KEY
export const supabase = createClient(supabaseUrl, supabaseKey)
lib/data/firebase JS文件pages/_app.tsx中的CSS文件public/app.css中更改CSSPageHead.tsx中的字體public/manifest.json中更改顏色。您需要在https://console.firebase.google.com/project/yourapp/yourapp/authentication/providers中啟用電子郵件/密碼身份驗證
注意:如果您使用部署按鈕設置項目,則需要克隆自己的存儲庫而不是此存儲庫。
使用此模板與Vercel進行設置並部署自己的項目。您需要的只是您的Firebase公共API密鑰。