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
Get library via npm
npm install @ssv/aspnet-prerendering
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 }));
});
Check out the development guide.