angular-universal-express-firebase
A packaged Cloud Function to serve Angular Universal apps.
Serving Angular Universal from Firebase Cloud Functions
This repo packages an Angular Universal app as a Firebase Cloud Function, walking through the server build and the dist cleanup that makes it work.
What gets packaged
The description on the tin is a packaged Cloud Function to serve Angular Universal apps. Read the pieces and it is Angular Universal for server rendering, Express as the web server, and Firebase Cloud Functions as the host. The README treats those as given and spends its space on the build steps rather than on what each library does.
Getting a server build
The server build is the first hurdle. The README notes that the current release candidate version of the Angular CLI covers it, then gives the steps to configure the CLI so you get a server build at all. This is the prerequisite for everything that follows, since the Cloud Function needs a server bundle to serve.
The build and the cleanup
After the CLI setup you build both the browser and the server Angular builds. The suggestion is to use the output hashing none flag with the universal build, so you do not have to update the hash in function.js on every build. Your angularcli.json should then have two app entries, browser and server, writing to dist and dist-server respectively. The final step is to delete dist/index.html, because Angular Universal generates the initial HTML from the assets in dist-server, so that leftover index file is not needed.
Editorial conclusion
The repository bundles Angular Universal, Express, and Firebase into a single Cloud Function, with the server build handled by the Angular CLI and the dist index file removed because the server bundle generates the initial HTML.
Community notes