• Stars
    star
    210
  • Rank 187,585 (Top 4 %)
  • Language
    JavaScript
  • License
    Other
  • Created over 4 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Next.js serverless PWA with Firebase boilerplate

Next.js serverless PWA with Firebase and React Hooks

nextjs-pwa-firebase-boilerplate demo on phone

Note: this is my v4 boilerplate for React web apps. See also my GraphQL + Postgres SQL boilerplate, Redux + REST + Postgres SQL boilerplate and Redux + REST + MongoDB boilerplate. For a simple Next.js landing page, see nextjs-generic-landing-page.

Support this project

Did you or your company find nextjs-pwa-firebase-boilerplate useful? Please consider giving a small donation, it helps me spend more time on open-source projects:

Support Tom on Ko-Fi.com

Why is this awesome?

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

  • Great starting point for a PWA (Progressive Web App), which you can add to your Home Screen and use as a full-screen app.
  • PWA features such as manifest.json and offline support (next-offline).
  • Can be deployed as serverless functions on Vercel/Zeit Now.
  • Uses the new Firebase Firestore database, but easy to replace/remove database.
  • Login/Signup with Firebase Authentication.
  • Can use SSG getStaticProps or SSR getServerSideProps.
  • React Hooks and Context for state management and business logic.
  • Free-form database model. No GraphQL or REST API, just add React Hooks and modify getStaticProps/getServerSideProps when changing/adding database tables.
  • Easy to style the visual theme using CSS (e.g. using Design Profile Generator).
  • SEO support with sitemap.xml and robots.txt.
  • 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:

Lighthouse score

Demo

See nextjs-pwa-firebase-boilerplate running on Vercel here.

nextjs-pwa-firebase-boilerplate demo on phone

How to use

Clone this repository:

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

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

rm -rf .git

Install dependencies:

yarn  # or npm install

Start it by doing the following:

yarn dev

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).

Modifying the app to your needs

Change app name and description

  • Do search/replace for the name “nextjs-pwa-firebase-boilerplate” and description “Next.js serverless PWA with Firebase and React Hooks” to something else.
  • Change the name and short_name in public/manifest.json.
  • Change the version in package.json to 0.1.0 or similar.
  • Change the license in package.json to whatever suits your project.

Renaming “Article” to something else

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

Rename the files:

mv hooks/useArticles.js hooks/use{NewName}s.js

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

mkdir pages/{newName}s
mv "pages/articles/[slug].js" "pages/{newName}s/[slug].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.

Set up Firebase database (Firestore)

Set up the database (if you don’t need a database, see “How to remove/replace Firebase as database” below):

  1. Go to https://console.firebase.google.com/ and create a new project, a new web app, and a new Cloud Firestore database.
  2. Copy the firebaseConfig (from when setting up the Firebase web app) to lib/data/firebase.js
  3. Edit the .env.local file, setting the NEXT_PUBLIC_FIREBASE_API_KEY value.

How to remove the Firebase dependency

  • Run yarn remove firebase
  • Delete lib/data/firebase.js and modify hooks/useArticles.js.

Replace Firebase with Supabase (Postgres SQL)

  • Remove Firebase: yarn remove firebase
  • Add Supabase: yarn add @supabase/supabase-js
  • Add NEXT_PUBLIC_SUPABASE_API_KEY to .env.local
  • Create a lib/data/supabase.js:
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)
  • Update the JS files that reference lib/data/firebase

Change visual theme (CSS)

  1. Change included CSS files in pages/_app.js
  2. Change CSS in public/app.css
  3. Change font(s) in PageHead.js
  4. Change colors in public/manifest.json

Login/Signup with Firebase Authentication

You need to enable Email/Password authentication in https://console.firebase.google.com/project/YOURAPP/authentication/providers

Deploying on Vercel

Note: If you set up your project using the Deploy button, you need to clone your own repo instead of this repository.

Setup and deploy your own project using this template with Vercel. All you’ll need is your Firebase Public API Key.

Deploy with Vercel

Todo

  • Optional unique title/description/image for each page (via _app.js)

More Repositories

1

nextjs-multi-domain-locale

Hosting multiple domains on the same Next.js site (while maintaining multiple languages and SSG)
JavaScript
217
star
2

nextjs-express-mongoose-crudify-boilerplate

Next.js (React) + Redux + Express REST API + MongoDB + Mongoose-Crudify boilerplate
JavaScript
175
star
3

nextjs-pwa-graphql-sql-boilerplate

Next.js serverless PWA with GraphQL (Postgraphile, Apollo) + Postgres SQL boilerplate
TypeScript
137
star
4

reactnative-nextjs-template

Build native apps (iOS/Android/Windows/macOS) and an SEO-optimized web app from the same React codebase
TypeScript
43
star
5

nextjs-sql-rest-api-boilerplate

Next.js (React) + Redux + Express REST API + Postgres SQL boilerplate.
JavaScript
23
star
6

programmatic-animations

Make animations with canvas and JavaScript, and export as video
JavaScript
18
star
7

nextjs-generic-landing-page

A generic landing page template, built in Next.js (React) with static HTML export
JavaScript
12
star
8

one-click-survey

API service for creating simple one-click email surveys.
JavaScript
10
star
9

login-as-a-service

Simple plug-and-play login/signup/leads service (using email), compatible with Vercel serverless functions
JavaScript
9
star
10

toms-guidebooks

@tomsoderlund’s guidebooks to a wide collection of tools and services.
JavaScript
6
star
11

string-match-like-search-engines

Google/Bing search style string matching
JavaScript
4
star
12

react-zeroconfig-components

React UI components that require (almost) zero configuration
JavaScript
3
star
13

react-zeroconfig-payments

React Stripe payment components that require zero configuration
JavaScript
3
star
14

twatbot

The clever Twitter bot.
JavaScript
2
star
15

centered-css

A centered, auto-scaling CSS box
HTML
2
star
16

skyscraper-js

Skyscraper.JS - interactive web scraping bookmarklet.
JavaScript
2
star
17

MobileZero

Basic boilerplate for "Mobile First" projects: looks awesome on mobile, and alright on desktop.
JavaScript
2
star
18

sql-wizard

Library that helps generate SQL queries and Express CRUD routes.
JavaScript
2
star
19

CordovaRTC

WebRTC live streaming for Cordova (mobile apps) - to be used together with ProjectRTC
JavaScript
2
star
20

design-profile-generator

Quickly generate a graphic design profile (as CSS)
JavaScript
2
star
21

duckduckgo-images-api-vercel

Simple API based on duckduckgo-images-api running on Vercel
Python
1
star
22

listwizard

Manipulate text lists with subtraction, intersection, aggregation, etc.
Svelte
1
star
23

pdf-analyzer

Convert PDF’s to structured data with ML
Python
1
star
24

MathPlay

Simple multiplayer math game using Meteor.
JavaScript
1
star
25

simple-browser-session

Library to get/set session values from localStorage/cookie and/or URL query string
JavaScript
1
star
26

react-share-follow

React component for Share and Follow on social networks
JavaScript
1
star
27

mixpanel-analytics

Tools for exporting and analyzing Mixpanel data.
JavaScript
1
star
28

simple-scraper-chrome-extension

Simple Scraper - Chrome extension
JavaScript
1
star