examples/with-firebase-hosting/README.md
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.
If you are having issues, feel free to tag @jthegedus in the issue you create on the next.js repo
<details> <summary><b>Make sure that firebase is set up and you have the projectID</b></summary>npm i -g firebase-toolsfirebase loginfirebase projects:list or the web consoles URL: https://console.firebase.google.com/project/<projectID>
</details>
Execute create-next-app with npm, Yarn, or pnpm to bootstrap the example:
npx create-next-app --example with-firebase-hosting with-firebase-hosting-app
yarn create next-app --example with-firebase-hosting with-firebase-hosting-app
pnpm create next-app --example with-firebase-hosting with-firebase-hosting-app
Important: Update .firebaserc and add your firebase project ID.
To run Firebase locally for testing:
npm run serve
# or
yarn serve
To deploy it to the cloud with Firebase:
npm run deploy
# or
yarn deploy
To use TypeScript, simply follow TypeScript setup as normal (package.json scripts are already set).
i.e: npm install --save-dev typescript @types/react @types/node
Then you can create components and pages in .tsx or .ts
Only src/next.config.js and firebaseFunctions.js must remain in *.js format.
firebase.json outlines the catchall rewrite rule for our Cloud Function.public/.gitignore file is to ensure public/ dir exists as it is required for Firebase Hosting. It is configured (by default) that dotfiles (public/.*) are ignored from being publicly served.nextjsFunc (changeable in firebaseFunctions.js and firebase.json).public/* files are statically served through Firebase hosting, not through NextJs server.Next App is in src/ directory.
The crucial files for the setup:
.firebasercfirebase.jsonfirebaseFunctions.jssrc/next.config.jspackage.json: firebase-* packages, main property defining the entry point as firebaseFunctions.js