1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00
next.js/examples/with-firebase-hosting
Saro Vindigni d3518242a6 FIX deploy with-firebase-hosting (#3946)
* FIX deploy with-firebase-hosting

* add npm run command in place of yarn in firebase.json predeploy hooks

* Change yarn with npm

* firebase-hosting example: Add warning in examples README

* firebase-hosting example: clarify warning language

* firebase-hosting example: remove the warning and upgrade to canary

* firebase-hosting example: actually upgrade pkg.json
2018-03-08 13:54:32 +01:00
..
src with-firebase-hosting improvements & fixes (#3886) 2018-02-28 11:54:48 +01:00
.firebaserc With Firebase Hosting Example (#2642) 2017-07-26 07:52:49 +02:00
.gitignore with-firebase-hosting improvements & fixes (#3886) 2018-02-28 11:54:48 +01:00
firebase.json FIX deploy with-firebase-hosting (#3946) 2018-03-08 13:54:32 +01:00
package.json FIX deploy with-firebase-hosting (#3946) 2018-03-08 13:54:32 +01:00
README.md with-firebase-hosting improvements & fixes (#3886) 2018-02-28 11:54:48 +01:00

With Firebase Hosting example

How to use

Using create-next-app

Download create-next-app to bootstrap the example:

npm i -g create-next-app
create-next-app --example with-firebase-hosting with-firebase-hosting-app

Download manually

Download the example or clone the repo:

curl https://codeload.github.com/zeit/next.js/tar.gz/canary | tar -xz --strip=2 next.js-canary/examples/with-firebase-hosting
cd with-firebase-hosting

Set up firebase:

Install project:

npm install

Run Next.js development:

npm run dev

Run Firebase locally for testing:

Unfortunately I have been unable to get any combination of

firebase serve --only functions,hosting

to locally host the built Next.js app as expected. This issue is where solutions are being explored and they will be shared here and on the Next.js repo's similar issue when discovered.

Deploy it to the cloud with Firebase:

npm run deploy

Clean dist folder

npm run clean

The idea behind the example

The goal is to host the Next.js app on Firebase Cloud Functions with Firebase Hosting rewrite rules so our app is served from our Firebase Hosting URL. Each individual page bundle is served in a new call to the Cloud Function which performs the initial server render.

This is based off of the work at https://github.com/geovanisouza92/serverless-firebase & https://github.com/jthegedus/firebase-functions-next-example as described here.

Important

  • The empty placeholder.html file is so Firebase Hosting does not error on an empty public/ folder and still hosts at the Firebase project URL.
  • firebase.json outlines the catchall rewrite rule for our Cloud Function.
  • The Firebase predeploy hooks run most of the npm scripts when npm run deploy runs firebase deploy. The only scripts you should need are dev, clean and deploy.