@ssv/aspnet-prerendering
TypeScript icon, indicating that this package has built-in type declarations

1.0.1-dev.12 • Public • Published

@ssv/aspnet-prerendering

CI npm version

Port of aspnet-prerendering which supports ESM.

This allows using vite/esbuild angular (was tested only with angular - @angular-devkit/build-angular:application)

Quick links

Change logs | Project Repository

Installation

Get library via npm

npm install @ssv/aspnet-prerendering

Usage

import { renderModule } from "@angular/platform-server";
import { APP_BASE_HREF } from "@angular/common";
// import { createServerRenderer } from "aspnet-prerendering";
import { createServerRenderer } from "@ssv/aspnet-prerendering";

import { AppServerModule } from "./app/app.server.module";

interface TransferData {
  originalHtml: string;
  startupContext: StartupContext; // custom
  request: any;
}

export default createServerRenderer(params => {
  const { startupContext, originalHtml } = params.data as TransferData;
  const extraProviders = [
    { provide: APP_BASE_HREF, useValue: startupContext.virtualPath },
    { provide: "BASE_URL", useValue: params.origin + params.baseUrl },
  ];

  const options = {
    document: originalHtml,
    url: params.url,
    extraProviders
  };

  const renderPromise = renderModule(AppServerModule, options);

  return renderPromise.then(html => ({ html }));
});

Contributions

Check out the development guide.

Package Sidebar

Install

npm i @ssv/aspnet-prerendering

Weekly Downloads

39

Version

1.0.1-dev.12

License

MIT

Unpacked Size

17.8 kB

Total Files

12

Last publish

Collaborators

  • ssv