npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

angular-universal-express-firebase

v0.0.4

Published

Run Angular Universal on Cloud Functions and Firebase Hosting

Downloads

7

Readme

Install

npm i angular-universal-express-firebase

NB: Run this command afer initialzing functions and from within the functions folder

Basic Usage

const angularUniversal = require('angular-universal-express-firebase');
exports.trigger = angularUniversal.trigger({
  index: 'path/to/index.html',
  main: 'path/to/bundle.longhash',
  enableProdMode: true,
  cdnCacheExpiry: 600,
  browserCacheExpiry: 300,
  staleWhileRevalidate: 120
});

TypeScript usage

import * as angularUniversal from 'angular-universal-express-firebase';
export let trigger = angularUniversal.trigger({
  index: 'path/to/index.html',
  main: 'path/to/bundle.longhash',
  enableProdMode: true,
  cdnCacheExpiry: 600,
  browserCacheExpiry: 300,
  staleWhileRevalidate: 120  
});

Setup

There are two parts to an Angular Universal app: the server build and the server.

Server Build

The current RC version of the Angular CLI covers the server build. Follow these steps to setup the CLI to get a server build.

Cloud Functions as the server

Build both browser and server Angular builds

You may want to use the --output-hashing none flag with your universal build to avoid needing to change the hash with each build in your function.js. At this point you should have two app entries in your angularcli.json file: browser and server. The browser build writes to the dist folder and the server build writes to the dist-server folder.

Delete dist/index.html.

This index file is uneeded because Angular Universal uses the assets in dist-server to generate the initial HTML.

Install the Firebase CLI.

# npm
npm i firebase-tools -g
# yarn
yarn add firebase-tools --global

Initialize Firebase Hosting and Cloud Functions.

firebase init hosting
# specify the public directory to dist
firebase init functions
# this will create a functions folder 
# with and index.js, package.json, and set
# of node_modules

Open functions/index.js and add the following code.

const angularUniversal = require('angular-universal-express-firebase');
exports.trigger = angularUniversal.trigger({
  index: __dirname + 'dist-server/index.html',
  // make sure this points at the correct hash, or use the --output-hashing none flag on your ng build.
  main: __dirname + '/bundle.<generated-hash>',
  enableProdMode: true,
  cdnCacheExpiry: 600, // cache in the CDN for 10 minutes
  browserCacheExpiry: 300, // cache in the browser for 5 minutes
  staleWhileRevalidate: 120 // serve a stale version for 2 minutes after cdnCacheExpiry, but refresh CDN in background
});

Setup the rewrite in firebase.json

Firebase Hosting needs to know which Cloud Function to call.

{
  "hosting": {
    "rewrites": [
      {
        "source": "**",
        "function": "trigger"
      }
    ]
  }
}

Serve locally to test

The Firebase CLI allows you to serve locally and emulate the production environment.

firebase serve --only functions,hosting
# visit locahost:5000

Deploy

Now that it looks great locally, deploy to production.

firebase deploy
firebase open hosting:site 
# automatically opens default browser to the prod site