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

@angularclass/universal-sitegen

v0.1.2

Published

An Angular Universal static site generator

Downloads

21

Readme

Universal Sitegen

An Angular Universal static site generator

What is this?

Ever wanted to make a static site from your Angular app? Now that we have finalized Angular Universal, you can! Universal Sitegen takes your angular app, builds it, then spits out static pages for each route. If you're building a website that you don't need a client side JS framework for, then this is pefect. Blogs, landing pages, sales pages, launch pages, company sites, you get the point.

Getting started

Installation

  • yarn add @angularclass/universal-sitegen

Building your static site

There are two ways to build your site:

No matter what approach you use, you need the following setup before you're ready to go.

First, make sure your AppModule is importing BrowserModule.withServerTransition() and your routes. As it should.

// app.module.ts

// .....imports

@NgModule({
  imports: [
    BrowserModule.withServerTransition({ appId: 'my-site' }),
    ROUTES
  ],
  // declarations
  // providers
  // bootstrap
})

export class AppModule {}

Next, create a ServerModule for Universal, and import your AppModule

// server.module.ts
import { NgModule } from '@angular/core'
import { ServerModule } from '@angular/platform-server'
import { App } from './app.component'
import { AppModule } from './app.module'

@NgModule({
  imports: [ServerModule, AppModule],
  bootstrap: [App]
})

export class AppServerModule {}

There is a Demo App that has the basics. Great place to start to getting your app ready.

CLI

Make sure you followed the steps above first. To build your site with the CLI (preffered), you only need to do a few things.

Because your app is never going to be ran in the browser and only node, you might have to adjust your webpack config. Look at the demo webpack config for what it should look like.

Next, build your app. After you build it, you need to create a universal.json file with options on the root of your app.

{
  // routes for your angular app. mirros your routes file
  "routes": [
    "/",
    "/about"
  ],
  // output folder for your site
  "outputPath": "site", 
  // path to the compiled Server NgModule or NgModuleFactory with the #ExportName of the module
  "serverModuleOrFactoryPath": "./dist/bundle#AppServerModule",
  // path to the root html page all pages will be injected into
  "indexHTMLPath": "./src/index.html"
}

After that is all done, add a script in your package.json to build the static site using the cli:

{
  "scripts": {
    "universal": "universal build"
  }
}

The universal build command will build your app as a static site, and output the html files to the outpath you specified in universal.json.

Programmatically

Follow the common steps above first. You need to create an entry file for the site generator:

// static.ts
import { generateSite } from '@angularclass/universal-sitegen'
import { AppServerModule } from './server.module'

generateSite(
  // NgModule or NgModuleFactory for the ServerModule you created
  AppServerModule,
  // index html file for all routes
  require('./index.html'),
  // options object
  {
    // routes for your app
    routes: [
      '/',
      '/about'
    ],
    // path to output the site
    outputPath: 'universal-site'
  }
)
.then(() => console.log('site built'))

Once that is done, build your app like you normally would. Because your static app will over ever be ran in Node, you can change your webpack config. Check out the demo webpack config

After you build it, all you have to do is execute the bundled file.

node dist/bundle.js

This will generate your static site.


enjoy — AngularClass

AngularClass

AngularClass

Learn AngularJS, Angular, and Modern Web Development from the best. Looking for corporate Angular training, want to host us, or Angular consulting? [email protected]