Skip to content

Commit 31417b8

Browse files
authored
Merge pull request #43 from TheIronDev/tystark.documentation_from_eric
docs(WebFrameworks) README updates from egilmore
2 parents e058bbb + 30700a5 commit 31417b8

File tree

1 file changed

+43
-59
lines changed

1 file changed

+43
-59
lines changed

README.md

Lines changed: 43 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
## Overview
2727

28-
Firebase Hosting integrates with popular modern Web frameworks including Angular and Next.js. Using Firebase Hosting and
28+
Firebase Hosting integrates with popular modern web frameworks including Angular and Next.js. Using Firebase Hosting and
2929
Cloud Functions for Firebase with these frameworks, you can develop apps and microservices in your preferred framework
3030
environment, and then deploy them in a managed, secure server environment. Support during this early preview includes
3131
the following functionality:
@@ -34,20 +34,20 @@ the following functionality:
3434
* Deploy Web apps that use pre-rendering / Static Site Generation (SSG)
3535
* Deploy Web apps that use server-side Rendering (SSR)—full server rendering on demand
3636

37-
Firebase provides this functionality through the Firebase CLI. While initializing Hosting on the command line, you
37+
Firebase provides this functionality through the Firebase CLI. When initializing Hosting on the command line, you
3838
provide information about your new or existing Web project, and the CLI sets up the right resources for your chosen Web
3939
framework.
4040

4141
## Status
4242

4343
![Status: Experimental](https://img.shields.io/badge/Status-Experimental-blue)
4444

45-
This repository is maintained by Googlers but is not a supported Firebase product. Issues here are answered by
45+
This repository is maintained by Google but is not a supported Firebase product. Issues here are answered by
4646
maintainers and other community members on GitHub on a best-effort basis.
4747

4848
## Enable framework-awareness
4949

50-
This is an experimental addon to the Firebase CLI to add web framework support, to enable it call the following:
50+
An experimental add-on to the Firebase CLI provides web framework support. To enable it, call the following:
5151

5252
```shell
5353
firebase experiments:enable webframeworks
@@ -61,17 +61,17 @@ firebase experiments:enable webframeworks
6161

6262
You can test your integration locally by following these steps:
6363

64-
1. Run `firebase serve` from the terminal. This should build your Angular app and serve it using the Firebase CLI.
65-
2. Open your web app at the local URL returned by the CLI (usually http://localhost:5000)
64+
1. Run `firebase serve` from the terminal. This should build your app and serve it using the Firebase CLI.
65+
2. Open your web app at the local URL returned by the CLI (usually http://localhost:5000).
6666

6767
## Deploy your app to Firebase Hosting
6868

69-
When you're ready to share your changes with the world, deploy your Angular app to your live site:
69+
When you're ready to share your changes with the world, deploy your app to your live site:
7070

7171
1. Run `firebase deploy` from the terminal.
72-
2. Check your website on: `SITE_ID.web.app` or `PROJECT_ID.web.app` (or your custom domain, if you did setup one)
72+
2. Check your website on: `SITE_ID.web.app` or `PROJECT_ID.web.app` (or your custom domain, if you set one up)
7373

74-
## "Integrate Angular"
74+
## Integrate Angular
7575

7676
Easily deploy your Angular application to Firebase and serve dynamic content to your users.
7777

@@ -88,14 +88,14 @@ or modify `firebase.json` for an existing project.
8888

8989
#### Initialize a new project
9090

91-
1. Run the initialization command from the CLI: ``
91+
1. Run the initialization command from the CLI:
9292

9393
```shell
9494
firebase init hosting
9595
```
9696

97-
1. Choose your hosting source directory; this could be an existing Angular App
98-
1. Choose "Dynamic web hosting with web framework"
97+
1. Choose your hosting source directory; this could be an existing Angular app.
98+
1. Choose "Dynamic web hosting with web framework."
9999
1. Choose Angular.
100100

101101
#### Initialize an existing project
@@ -118,7 +118,7 @@ After initializing Firebase, you can serve static content with the standard depl
118118
firebase deploy
119119
```
120120

121-
## Pre-render dynamic content
121+
### Pre-render dynamic content
122122

123123
To prerender dynamic content in Angular, you need to set up Angular Universal. The Firebase CLI expects Express Engine:
124124

@@ -128,10 +128,10 @@ ng add @nguniversal/express-engine
128128

129129
[See the Angular Universal guide for more information.](https://angular.io/guide/universal)
130130

131-
### Add prerender URLs
131+
#### Add prerender URLs
132132

133-
By default, only the root directory will be prerendered, you can add additional routes by locating the prerender step in
134-
your angular.json and adding more routes:
133+
By default, only the root directory will be prerendered. You can add additional routes by locating the prerender step in
134+
`angular.json` and adding more routes:
135135

136136
```json
137137
{
@@ -152,12 +152,12 @@ your angular.json and adding more routes:
152152
}
153153
```
154154

155-
Firebase will also respect guessRoutes or a routes.txt file in the hosting root, if you need to customize further.
155+
Firebase also respects `guessRoutes` or a `routes.txt` file in the hosting root, if you need to customize further.
156156
See [Angular’s prerendering guide](https://angular.io/guide/prerendering) for more information on those options.
157157

158-
### Optional: add a server module
158+
#### Optional: add a server module
159159

160-
### Deploy
160+
#### Deploy
161161

162162
When you deploy with `firebase deploy`, Firebase builds your browser bundle, your server bundle, and prerenders the
163163
application. These elements are deployed to Hosting and Cloud Functions.
@@ -167,8 +167,8 @@ application. These elements are deployed to Hosting and Cloud Functions.
167167
The Firebase CLI assumes that you have server, build, and prerender steps in your schematics with a production
168168
configuration.
169169

170-
If you want to tailor the CLI's assumptions, configure ng deploy and alter the configuration in your angular.json. For
171-
example, you could disable SSR and serve pre-rendered content exclusively by removing serverTarget:
170+
If you want to tailor the CLI's assumptions, configure ng deploy and alter the configuration in `angular.json`. For
171+
example, you could disable SSR and serve pre-rendered content exclusively by removing `serverTarget`:
172172

173173
```json
174174
{
@@ -185,7 +185,7 @@ example, you could disable SSR and serve pre-rendered content exclusively by rem
185185

186186
### Optional: integrate with the Firebase JS SDK
187187

188-
When including Firebase JS SDK methods in both server and client bundles, guard against runtime errors by checking isSupported() before using the product. [Not all products are supported in all environments.](https://firebase.google.com/docs/web/environments-js-sdk#other_environments)
188+
When including Firebase JS SDK methods in both server and client bundles, guard against runtime errors by checking `isSupported()` before using the product. [Not all products are supported in all environments.](https://firebase.google.com/docs/web/environments-js-sdk#other_environments)
189189

190190
Hint: consider using AngularFire, which does this for you automatically.
191191

@@ -226,22 +226,22 @@ export const FIREBASE_ADMIN = new InjectionToken<app.App>('firebase-admin');
226226

227227
```
228228

229-
## Serve fully dynamic content with SSR—Server Side Rendering
229+
### Serve fully dynamic content with SSR
230230

231-
### Optional: integrate with Firebase Authentication
231+
#### Optional: integrate with Firebase Authentication
232232

233233
The web framework-aware Firebase deployment tooling automatically keeps client and server state in sync using cookies. The Express `res.locals` object will optionally contain an authenticated Firebase App instance (`firebaseApp`) and the currently signed in user (`currentUser`). This can be injected into your module via the REQUEST token (exported from @nguniversal/express-engine/tokens).
234234

235235

236236
## Integrate Next.js
237237

238-
Using the Firebase CLI, you can deploy your next.js Web apps to Firebase and serve them with Firebase Hosting. The CLI respects your next.js settings and translates them to Firebase settings with zero or minimal extra configuration on your part. If your app includes dynamic server-side logic, the CLI deploys that logic to Cloud Functions for Firebase.
238+
Using the Firebase CLI, you can deploy your Next.js Web apps to Firebase and serve them with Firebase Hosting. The CLI respects your Next.js settings and translates them to Firebase settings with zero or minimal extra configuration on your part. If your app includes dynamic server-side logic, the CLI deploys that logic to Cloud Functions for Firebase.
239239

240240
Note: Apps with dynamic server-side logic must provide a billing instrument during Cloud Functions setup. Also note that all frameworks-based functionality provided by the Firebase CLI is currently has experimental status, and may change in backward-incompatible ways.
241241

242242
### Before you begin
243243

244-
Before you get started deploying your next.js app to Firebase, first review the following requirements and options:
244+
Before you get started deploying your Next.js app to Firebase, first review the following requirements and options:
245245

246246
- All projects must use firebase-tools 10.8 or higher
247247
- If your project requires SSR, you must provide a billing instrument
@@ -273,9 +273,9 @@ You can [view your deployed app](https://firebase.google.com/docs/hosting/test-p
273273

274274
The Firebase CLI will detect usage of [getStaticProps](https://nextjs.org/docs/basic-features/data-fetching/get-static-props) and [getStaticPaths](https://nextjs.org/docs/basic-features/data-fetching/get-static-paths).
275275

276-
#### Optional: integrate with Firebase JS SD
276+
#### Optional: integrate with Firebase JS SDK
277277

278-
When including Firebase JS SDK methods in both server and client bundles, guard against runtime errors by checking isSupported() before using the product. [Not all products are supported in all environments.](https://firebase.google.com/docs/web/environments-js-sdk#other_environments)
278+
When including Firebase JS SDK methods in both server and client bundles, guard against runtime errors by checking `isSupported()` before using the product. [Not all products are supported in all environments.](https://firebase.google.com/docs/web/environments-js-sdk#other_environments)
279279

280280
Tip: consider using ReactFire, which does this for you automatically.
281281

@@ -287,7 +287,7 @@ Admin SDK bundles will fail if included in your browser build; refer to them on
287287

288288
The Firebase CLI will detect usage of [getServerSideProps](https://nextjs.org/docs/basic-features/data-fetching/get-server-side-props).
289289

290-
### Configure Hosting behavior with next.config.js
290+
### Configure Hosting behavior with `next.config.js`
291291

292292
#### Image Optimization
293293

@@ -297,7 +297,7 @@ Note: Because of this, Image Optimization and Hosting Preview Channels don’t i
297297

298298
#### Redirects, Rewrites, and Headers
299299

300-
Firebase CLI will respect [redirects](https://nextjs.org/docs/api-reference/next.config.js/redirects), [rewrites](https://nextjs.org/docs/api-reference/next.config.js/rewrites), and [headers](https://nextjs.org/docs/api-reference/next.config.js/headers) in your next.config.js, converting them to their respective equivalent Firebase Hosting configuration at deploy time.
300+
Firebase CLI respects [redirects](https://nextjs.org/docs/api-reference/next.config.js/redirects), [rewrites](https://nextjs.org/docs/api-reference/next.config.js/rewrites), and [headers](https://nextjs.org/docs/api-reference/next.config.js/headers) in `next.config.js`, converting them to their respective equivalent Firebase Hosting configuration at deploy time.
301301

302302
If a Next.js redirect, rewrite, or header cannot be converted to an equivalent Firebase Hosting header, it falls back and builds a Cloud Function—even if you aren’t using Image Optimization or SSR.
303303

@@ -306,7 +306,7 @@ If a Next.js redirect, rewrite, or header cannot be converted to an equivalent F
306306
The web framework-aware Firebase deployment tooling will automatically keep client and server state in sync using cookies. There are some methods provided for accessing the authentication context in SSR:
307307

308308
* The Express `res.locals` object will optionally contain an authenticated Firebase App instance (`firebaseApp`) and the currently signed in user (`currentUser`). This can be accessed in `getServerSideProps`.
309-
* The authenticated Firebase App name is provided on the route query (__firebaseAppName), this allows for manual integration while in context:
309+
* The authenticated Firebase App name is provided on the route query (`__firebaseAppName`). This allows for manual integration while in context:
310310

311311
```typescript
312312
// get the authenticated Firebase App
@@ -315,7 +315,7 @@ The web framework-aware Firebase deployment tooling will automatically keep clie
315315

316316
## Integrate other frameworks with Express.js
317317

318-
With some additional configuration, you can build on the basic CLI functionality to extend integration support to Frameworks other than Angular and next.js.
318+
With some additional configuration, you can build on the basic CLI functionality to extend integration support to Frameworks other than Angular and Next.js.
319319

320320
### What you’ll need before you begin
321321

@@ -331,10 +331,6 @@ or modify `firebase.json` for an existing project.
331331

332332
#### Initialize a new project
333333

334-
Run the initialization command from the CLI:
335-
```shell firebase init hosting
336-
```
337-
338334
1. Run the initialization command from the CLI:
339335
```shell
340336
firebase init hosting
@@ -360,7 +356,7 @@ Change your hosting config in firebase.json to have a `source` option, rather th
360356

361357
#### Configure
362358

363-
In order to know how to deploy your application,The Firebase CLI needs to be able to both build your app and known where your tooling places the assets destined for Hosting. This is accomplished with the NPM build script and CJS directories directive in your package.json.
359+
In order to know how to deploy your application, the Firebase CLI needs to be able to both build your app and know where your tooling places the assets destined for Hosting. This is accomplished with the NPM build script and CJS directories directive in `package.json`.
364360

365361
Given the following package.json:
366362

@@ -377,7 +373,7 @@ Given the following package.json:
377373
}
378374
```
379375

380-
Firebase CLI only calls your build script, so you’ll need to ensure that your build script is exhaustive.
376+
The Firebase CLI only calls your build script, so you’ll need to ensure that your build script is exhaustive.
381377

382378
Hint: you can add additional steps using &&. If you have a lot of steps consider a shell script or tooling like [npm-run-all](https://www.npmjs.com/package/npm-run-all) or [wireit](https://www.npmjs.com/package/wireit).
383379

@@ -394,9 +390,9 @@ Hint: you can add additional steps using &&. If you have a lot of steps consider
394390
}
395391
```
396392

397-
If your framework doesn’t support pre-rendering out-of-box, consider using a tool like [Rendertron](https://github.com/GoogleChrome/rendertron). Rendertron will allow you to make headless Chrome requests against a local instance of your app, so you can save the resulting HTML to be served on Hosting.
393+
If your framework doesn’t support pre-rendering out of the box, consider using a tool like [Rendertron](https://github.com/GoogleChrome/rendertron). Rendertron will allow you to make headless Chrome requests against a local instance of your app, so you can save the resulting HTML to be served on Hosting.
398394

399-
Finally, different frameworks and build tools store their artifacts in different places. Use directories.serve to tell the CLI where your build script is outputting the resulting artifacts:
395+
Finally, different frameworks and build tools store their artifacts in different places. Use `directories.serve` to tell the CLI where your build script is outputting the resulting artifacts:
400396

401397
```json
402398
{
@@ -422,11 +418,11 @@ firebase deploy
422418

423419
Your application should now be configured as an SPA and deployed to Firebase Hosting.
424420

425-
#### Serve Dynamic Content
421+
### Serve Dynamic Content
426422

427-
To serve up your Express app on Cloud Functions, ensure that your Express app (or express-style url handler) is exported in such a way that Firebase can find it after your library has been NPM packed.
423+
To serve up your Express app on Cloud Functions, ensure that your Express app (or express-style URL handler) is exported in such a way that Firebase can find it after your library has been NPM packed.
428424

429-
To accomplish this, ensure that your files directive includes everything needed for the server and your main entry-point is setup correctly in your package.json:
425+
To accomplish this, ensure that your files directive includes everything needed for the server and your main entry point is set up correctly in `package.json`:
430426

431427
```json
432428
{
@@ -446,7 +442,7 @@ To accomplish this, ensure that your files directive includes everything needed
446442
}
447443
```
448444

449-
Export your express app from a function named app:
445+
Export your express app from a function named `app`:
450446

451447
```js
452448
// server.js
@@ -457,7 +453,7 @@ export function app() {
457453
}
458454
```
459455

460-
Or if you’d rather export an express-style URL handler, name it handle:
456+
Or if you’d rather export an express-style URL handler, name it `handle`:
461457

462458
```js
463459
export function handle(req, res) {
@@ -472,22 +468,10 @@ firebase deploy
472468
```
473469

474470
Your application should now deploy your static content to Firebase Hosting and fall back to your Express app hosted on Cloud Functions.
475-
Optional: integrate with Firebase Authentication
476-
The web framework aware Firebase deploy tooling will automatically keep client & server state in sync using cookies. To access the authentication context, the Express `res.locals` object optionally contains an authenticated Firebase App instance (`firebaseApp`) and the currently signed in User (`currentUser`).
477-
478-
### Serve locally
479471

480-
You can test your integration locally by following these steps:
481-
482-
1. Run `firebase serve` from the terminal. This should build your Next.js app and serve it using the Firebase CLI.
483-
2. Open your web app at the local URL returned by the CLI (usually http://localhost:5000)
484-
485-
### Deploy your app to Firebase Hosting
486-
487-
When you're ready to share your changes with the world, deploy your Next.js app to your live site:
472+
### Optional: integrate with Firebase Authentication
488473

489-
1. Run `firebase deploy` from the terminal.
490-
2. Check your website on: `SITE_ID.web.app` or `PROJECT_ID.web.app` (or your custom domain, if you did setup one)
474+
The web framework-aware Firebase deploy tooling will automatically keep client and server state in sync using cookies. To access the authentication context, the Express `res.locals` object optionally contains an authenticated Firebase App instance (`firebaseApp`) and the currently signed in User (`currentUser`).
491475

492476
### Common Configurations
493477

0 commit comments

Comments
 (0)