All Projects → chrisguttandin → angular-prerender

chrisguttandin / angular-prerender

Licence: MIT license
A command line tool to prerender Angular Apps.

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects
shell
77523 projects

Projects that are alternatives of or similar to angular-prerender

ngx-metafrenzy
🏷️ Angular module for setting meta/link tags such as open graph, canonical, robots, and title
Stars: ✭ 19 (-84.55%)
Mutual labels:  server-side-rendering, ngx
reflect
Static site generator for WordPress.
Stars: ✭ 19 (-84.55%)
Mutual labels:  static-site-generator, server-side-rendering
Citation
Citation is a new generation CMS merging ideas of: Headless / GraphQL, static site generation and JavaScript component pre-rendering
Stars: ✭ 31 (-74.8%)
Mutual labels:  static-site-generator, server-side-rendering
ngext
Better routing for Angular
Stars: ✭ 78 (-36.59%)
Mutual labels:  server-side-rendering, ngx
awesome-astro
Curated resources on building sites with Astro, a brand new way to build static and server rendered sites, with cross-framework components, styling and reactive store support.
Stars: ✭ 210 (+70.73%)
Mutual labels:  static-site-generator, server-side-rendering
React Snap
👻 Zero-configuration framework-agnostic static prerendering for SPAs
Stars: ✭ 4,565 (+3611.38%)
Mutual labels:  static-site-generator, server-side-rendering
pokedex-nextjs
Get to know the different render methods that the Next.js framework provides by exploring Pokemons
Stars: ✭ 39 (-68.29%)
Mutual labels:  static-site-generator, server-side-rendering
nene
Nēnē: A no-frills static site generator
Stars: ✭ 22 (-82.11%)
Mutual labels:  static-site-generator
flourish
Yet another static site generator
Stars: ✭ 12 (-90.24%)
Mutual labels:  static-site-generator
webping
🚦 Python script to monitor web pages.
Stars: ✭ 20 (-83.74%)
Mutual labels:  static-site-generator
ngx-ui-switch
Angular UI Switch component
Stars: ✭ 109 (-11.38%)
Mutual labels:  ngx
go-slate
A CLI tool to generate API documentation using Slate layout by Robert Lord
Stars: ✭ 19 (-84.55%)
Mutual labels:  static-site-generator
acblog
An open source extensible static & dynamic blog system. (an alternative tool with same features at StardustDL/paperead)
Stars: ✭ 60 (-51.22%)
Mutual labels:  static-site-generator
laststaticsitegenerator
After learning how to use task runners like grunt, gulp, webpack and many static site generators i was in need for one workflow that makes setting up any tools unnecessary. Here it is!
Stars: ✭ 14 (-88.62%)
Mutual labels:  static-site-generator
bowman
A simple static site generator with an integrated toolchain for efficient development and delivery.
Stars: ✭ 17 (-86.18%)
Mutual labels:  static-site-generator
react-data-fetching-components
♻️ Asynchronously load data for your React components with SSR
Stars: ✭ 13 (-89.43%)
Mutual labels:  server-side-rendering
polyglot
Create websites using any mix of programming languages or workflows 💎
Stars: ✭ 79 (-35.77%)
Mutual labels:  static-site-generator
gpp
General PreProcessor
Stars: ✭ 25 (-79.67%)
Mutual labels:  static-site-generator
gridsome-starter-default
🐣 Default starter for Gridsome
Stars: ✭ 35 (-71.54%)
Mutual labels:  static-site-generator
API-Portal
API Portal lets you create and publish a customized site with API documentation, for free and without writing any code.
Stars: ✭ 162 (+31.71%)
Mutual labels:  static-site-generator

logo

angular-prerender

A command line tool to prerender Angular Apps.

version

This command line tool is meant to simplify the build process of static Angular apps. It works by analyzing the config file created by the Angular CLI. It looks for a client and server app target defined in the angular.json file. It does then render each route and merges the output with the static build for the client.

Usage

angular-prerender is available on npm. It will most likely be a dev dependency of your project. The command to install it will then look like this:

npm install angular-prerender --save-dev

In case you used all the default settings of the CLI angular-prerender will be able to pick up all the necessary information on its own. You can run it on the command line by only specifying the project name (assuming it's named "universe").

npx angular-prerender --browser-target universe:build

It is also possible to skip the explicit installation of angular-prerender.

The following is a complete example which will generate a very basic static Angular app called "universe".

npx @angular/cli new universe --routing
cd universe
ng generate universal --project universe
npm install angular-prerender --save-dev
ng build
ng run universe:server
npx angular-prerender --browser-target universe:build

Arguments

In some scenarios angular-prerender will not be able to grab all the information by analyzing the angular.json file alone. In that case you can help it by specifying some command line arguments.

--browser-target

This lets you specify the name of the target of your client app. The Angular CLI will normally call it "build" and this is also used as a default value. It is also possible to use a full target specifier which does also include the project and an optional configuration separated by colons. This works similar as the target parameter of the ng run command.

--config

The config option expects a path (including the filename) to the angular.json file of your project. By default it will look for it in the current working directory.

--exclude-routes

This option can be used to tell angular-prerender not to render specified routes. The given routes can't contain any parameters.

npx angular-prerender --exclude-routes /do-not-render-1 /do-not-render-2

Alternatively routes can also be excluded when setting the status code as described below.

--ignore-status-code

When set to false this flag will make sure that status codes set on the response will not be ignored. An example of a component which sets the status code looks as follows:

import { Component, Inject } from '@angular/core';
import { RESPONSE } from '@nguniversal/express-engine/tokens';
import { Response } from 'express';

@Component({
    // ...
})
class NotFoundComponent {
    constructor(@Inject(RESPONSE) response: Response) {
        response.status(404);
    }
}

If status codes are not ignored any route which sets the status code to 300 or above will be excluded.

--include-routes

This option can be used to tell angular-prerender to explicitly render the given routes even though they could not be detected automatically.

npx angular-prerender --include-routes /render-even-if-not-detected

--parameter-values

Some URLs of your app might accept parameters. This option can be used to tell angular-prerender about the possible values those parameters could have. It expects a stringified JSON value which can be described with this TypeScript interface:

interface IParameterValuesMap {
    [segment: string]: string | string[] | IParameterValuesMap | IParameterValuesMap[];
}

Lets imagine your app has a route with a :name parameter in it: /team/:name. A call to angular-prerender like this would render two routes by replacing the parameter with the given values:

npx angular-prerender --parameter-values '{":name":["amelia","oliver"]}'
/team/amelia
/team/oliver

By default all possible combinations of all given parameter values will be rendered. If there is a route like this /blog/:slug/comments/:id and we render it with two values for each parameter angular-prerender will render four routes.

npx angular-prerender --parameter-values '{":id":["comment-a","comment-b"],":slug":["story-a","story-b"]}'
/blog/story-a/comments/comment-a
/blog/story-a/comments/comment-b
/blog/story-b/comments/comment-a
/blog/story-b/comments/comment-b

If this is not intended and comment-a exclusively belongs to story-a and comment-b belongs to story-b respectively the parameter values can be grouped.

npx angular-prerender --parameter-values '[{":id":"comment-a",":slug":"story-a"},{":id":"comment-b",":slug":"story-b"}]'

In this case angular-prerender will only renderer two routes.

/blog/story-a/comments/comment-a
/blog/story-b/comments/comment-b

It's also possible to scope parameter values by routes. This comes in handy if the same name is used for different parameters in different routes. If your app has two routes (/shirts/:id/:size and /shoes/:id/:size) and they both use the same parameters (:id and :size) it is possible to nest the parameter values to specify a different set of values for each route.

npx angular-prerender --parameter-values '{"/shirts":[{":id":"polo-shirt",":size":"m"},{":id":"t-shirt",":size":"xl"}],"/shoes":{":id":"slipper",":size":["10","12"]}}'

It is not necessary to specify the full route as long as a part of the route is already enough to distinguish it from the other routes.

The command above will render two routes.

/shirts/polo-shirt/m
/shirts/t-shirt/xl
/shoes/slipper/10
/shoes/slipper/12

Please note that it might be necessary to escape the string differently dependending on the command-line interface you use.

In case there is a prerendered page which links to all possible parameter combinations it might be an alternative to use the --recursive flag instead.

--preserve-index-html

Setting this flag to true will preserve the index.html file generated by the browser build. It will be saved in the same directory as start.html. Additionally an existing ngsw.json file will be updated as well to reference the preserved start.html file instead of the prerendered index.html file.

--recursive

When enabling this flag every prerendered HTML document will be scanned to discover further routes. If some of the found routes were previously unknown they get appended to the list of routes to prerender.

In case any of the newly discovered routes is one of the routes defined with --exclude-routes it will not be prerendered.

--scully-config

⚠️ This is currently very experimental and might not work with every possible Scully config. Please feel free to open an issue if it doesn't accept your config.

This option allows you to specify a path to a Scully config file. @scullyio/scully and the respective plugins need to be installed for this to work. So far only the plugins specified as defaultPostRenderers and plugins of type routeProcess get applied.

--server-target

This lets you specify the name of the target of your server app. The Angular CLI will normally call it "server" and this is also used as a default value. It is also possible to use a full target specifier which does also include the project and an optional configuration separated by colons. This works similar as the target parameter of the ng run command.

--verbose (-v)

This flag enables more detailed log messages.

Acknowledgement

This command line tool is only possible by bringing together the great power of Angular Universal (which is now on its way into the main Angular repository) and Guess.js (which provides an excellent parser to retrieve the routes of an Angular app).

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].