Next.js serverless PWA template with just Firebase and React Hooks

栏目: IT技术 · 发布时间: 5年前

内容简介:This is a great template for a any project where you want

Next.js serverless PWA with Firebase

Next.js serverless PWA template with just Firebase and React Hooks

Note: this is my v4 boilerplate for React web apps. See also nextjs-pwa-graphql-sql-boilerplate , nextjs-sql-rest-api-boilerplate and nextjs-express-mongoose-crudify-boilerplate .

Why is this awesome?

This is a great template for a any project where you want React (with Hooks) (with server-side rendering, powered by Next.js ) as frontend and Firebase as backend. Lightning fast, all JavaScript.

  • Great starting point for a PWA (Progressive Web App) .
  • Can be deployed asserverless functions on Vercel/Zeit Now.
  • The new Firebase database, Cloud Firestore , as database.
  • React Hooks for business logic.
  • Free-form database model. No GraphQL or REST API, just add React Hooks and modify [page].getServerSideProps (for server-side rendering, SSR) when changing/adding database tables.
  • PWA features such as manifest.json and offline support ( next-offline , not yet included).
  • Easy to style the visual theme using CSS (e.g. using Design Profile Generator ).
  • sitemap.xml and robots.txt support.
  • Google Analytics and google-site-verification support (see config/config.js ).
  • Flexible configuration with config/config.js and .env.local file.
  • Code linting and formatting with StandardJS ( yarn lint / yarn fix ).
  • Unit testing with Jasmine ( yarn unit , not yet included).
  • Great page speed, see Lighthouse score:

Next.js serverless PWA template with just Firebase and React Hooks

Demo

See nextjs-pwa-firebase-boilerplate running on Vercel/Zeit Now here .

Next.js serverless PWA template with just Firebase and React Hooks

How to use

Clone this repository:

git clone https://github.com/tomsoderlund/nextjs-pwa-firebase-boilerplate.git [MY_APP]

Remove the .git folder since you want to create a new repository

rm -rf .git

Install dependencies:

cd [MY_APP]
yarn  # or npm install

Set up the database:

Configure the .env.local file.

Start it by doing the following:

yarn dev  # or 'yarn vercel' to run with Vercel/Zeit Now serverless

In production:

yarn build
yarn start

If you navigate to http://localhost:3004/ you will see a web page with a list of articles (or an empty list if you haven’t added one).

Deploying serverless (on Vercel/Zeit Now)

Configure database:

vercel env add NEXT_PUBLIC_FIREBASE_API_KEY

Run in development mode with:

yarn vercel

Deploy to Now with:

yarn deploy

Modifying the app to your needs

Change app name

Do search/replace for “nextjs-pwa-firebase-boilerplate” to something else.

Change name in public/manifest.json

Renaming “Article” to something else

The database item is called “Article”, but you probably want something else in your app.

Rename the files:

mv hooks/articles.js hooks/{newName}.js

mkdir -p components/{newName}s
mv components/articles/ArticleList.js components/{newName}s/{NewName}List.js
mv components/articles/ArticleListItem.js components/{newName}s/{NewName}ListItem.js
mv components/articles/ArticleDetails.js components/{newName}s/{NewName}Details.js
rm -r components/articles

mkdir pages/{newName}s
mv "pages/articles/[article].js" "pages/{newName}s/[{newName}].js"
rm -r pages/articles

Then, do search/replace inside the files for different casing: article , Article , ARTICLE .

Change port number

Do search/replace for “3004” to something else.

How to remove/replace database

Delete lib/firebase.js and modify hooks/articles.js .

Change visual theme (CSS)

public/manifest.json
public/app.css
PageHead.js

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

ACM国际大学生程序设计竞赛题解

ACM国际大学生程序设计竞赛题解

赵端阳//袁鹤 / 电子工业 / 2010-7 / 39.00元

随着各大专院校参加ACM/ICPC热情的高涨,迫切需要有关介绍ACM国际大学生程序设计竞赛题解的书籍。《ACM国际大学生程序设计竞赛题解(2)》根据浙江大学在线题库的部分题目,经过分类、筛选、汇编,并进行了解答(个别特别简单或者特别复杂的题目未选择),比较详细地分析和深入浅出地讲解了解题的方法和用到的算法。题目的类型包括基础编程、模拟、字符串处理、搜索、动态规划、回溯、图论、几何和数学题。 ......一起来看看 《ACM国际大学生程序设计竞赛题解》 这本书的介绍吧!

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

URL 编码/解码
URL 编码/解码

URL 编码/解码

MD5 加密
MD5 加密

MD5 加密工具