import 'reflect-metadata' ; import 'zone.js/dist/zone-node' ; import { APP_BASE_HREF } from '@angular/common' ; import { enableProdMode } from '@angular/core' ; import { renderModuleFactory } from '@angular/platform-server' ; import { provideModuleMap } from '@nguniversal/module-map-ngfactory-loader' ; import { existsSync , mkdirSync , readFileSync , writeFileSync } from 'fs' ; import { join } from 'path' ; import { PRERENDERED_ROUTES } from './static.paths' ; enableProdMode ( ) ; const { AppServerModuleNgFactory , LAZY_MODULE_MAP } = require ( '../server/main' ) ; const DEMO_FOLDER = join ( process . cwd ( ) , 'dist' , 'demo' , 'browser' ) ; const index = readFileSync ( join ( process . cwd ( ) , 'dist' , 'demo' , 'browser' , 'index.html' ) , 'utf8' ) ; const localFallback = 'http://localhost:4200/' ; let previousRender = Promise . resolve ( ) ; PRERENDERED_ROUTES . forEach ( route => { const fullPath = join ( DEMO_FOLDER , route ) ; if ( ! existsSync ( fullPath ) ) { mkdirSync ( fullPath ) ; } previousRender = previousRender . then ( ( ) => renderModuleFactory ( AppServerModuleNgFactory , { document : index , url : route , extraProviders : [ provideModuleMap ( LAZY_MODULE_MAP ) , { provide : APP_BASE_HREF , useValue : process . env . ORIGIN || localFallback , } , ] , } ) ) . then ( html => writeFileSync ( join ( fullPath , 'index.html' ) , html ) ) ; } ) ;