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-and-typescript
Juan Olvera 7e12997af6 Test updater script on examples folder (#5993)
I wrote a [script](https://github.com/j0lv3r4/dependency-version-updater) to update dependencies recursively in `package.json` files, e.g.:

```
$ node index.js --path="./examples" --dependencies="react=^16.7.0,react-dom=^16.7.0"
```

This PR contains the result against the examples folder.
2019-01-05 12:19:27 +01:00
..
src Update/fix "examples/with-firebase-hosting-and-typescript" (#5864) 2018-12-11 23:24:18 +01:00
.babelrc Update typescript examples to use 1.0.1 of next-typescript (#4472) 2018-05-25 11:28:35 +02:00
.firebaserc Create with-firebase-hosting-and-typescript example (#4443) 2018-05-21 10:25:45 +02:00
.gitignore Update/fix "examples/with-firebase-hosting-and-typescript" (#5864) 2018-12-11 23:24:18 +01:00
firebase.json Create with-firebase-hosting-and-typescript example (#4443) 2018-05-21 10:25:45 +02:00
package.json Test updater script on examples folder (#5993) 2019-01-05 12:19:27 +01:00
README.md Update/fix "examples/with-firebase-hosting-and-typescript" (#5864) 2018-12-11 23:24:18 +01:00

With Firebase Hosting and Typescript example

How to use

Using create-next-app

Execute create-next-app with Yarn or npx to bootstrap the example:

npx create-next-app --example with-firebase-hosting-and-typescript with-firebase-hosting-and-typescript-app
# or
yarn create next-app --example with-firebase-hosting-and-typescript with-firebase-hosting-and-typescript-app

Download manually

Download the example:

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

Set up firebase:

Install project:

npm install

Run Next.js development:

npm run dev

Run Firebase locally for testing:

npm run serve

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, with a complete Typescript stack for both the Next app and for the Firebase Functions. 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 of @jthegedus in the with-firebase-hosting example.

If you're having issues, feel free to tag @sampsonjoliver in the issue you create on the next.js repo

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 defined in firebase.json will handle linting and compiling of the next app and the functions sourceswhen firebase deploy is invoked. The only scripts you should need are dev, clean and deploy.
  • Specifying "engines": {"node": "8"} in the package.json is required for firebase functions to be deployed on Node 8 rather than Node 6 (Firebase Blog Announcement) . This is matched in by specifying target as es2017 in src/functions/tsconfig.json so that typescript output somewhat compacter and moderner code.