Skip to content
This repository has been archived by the owner on Oct 14, 2024. It is now read-only.

Commit

Permalink
fix: add optional section to make appshell work with lazy-loading and…
Browse files Browse the repository at this point in the history
… ssr (#646)

At the moment, there is no clear explaination how to make an app-shell work togather with SSR and lazy loading.

See for more context angular/angular-cli#9202
  • Loading branch information
alan-agius4 authored and CaerusKaru committed Oct 18, 2018
1 parent dc64b0a commit a8f8cdf
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions server.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import 'zone.js/dist/zone-node';
import 'reflect-metadata';
import {enableProdMode} from '@angular/core';
import { enableProdMode } from '@angular/core';

// Express Engine
import {ngExpressEngine} from '@nguniversal/express-engine';
import { ngExpressEngine } from '@nguniversal/express-engine';
// Import module map for lazy loading
import {provideModuleMap} from '@nguniversal/module-map-ngfactory-loader';
import { provideModuleMap } from '@nguniversal/module-map-ngfactory-loader';

import * as express from 'express';
import {join} from 'path';
import { join } from 'path';

// Faster server renders w/ Prod mode (dev mode never needed)
enableProdMode();
Expand All @@ -19,13 +20,23 @@ const PORT = process.env.PORT || 4000;
const DIST_FOLDER = join(process.cwd(), 'dist');

// * NOTE :: leave this as require() since this file is built Dynamically from webpack
const {AppServerModuleNgFactory, LAZY_MODULE_MAP} = require('./server/main');
const { AppServerModuleNgFactory, LAZY_MODULE_MAP } = require('./server/main');

// Our Universal express-engine (found @ https://github.com/angular/universal/tree/master/modules/express-engine)
app.engine('html', ngExpressEngine({
bootstrap: AppServerModuleNgFactory,
providers: [
provideModuleMap(LAZY_MODULE_MAP)
provideModuleMap(LAZY_MODULE_MAP),
// In case you want to use an AppShell with SSR and Lazy loading
// you'd need to uncomment the below. (see: https://github.com/angular/angular-cli/issues/9202)
// {
// provide: NgModuleFactoryLoader,
// useClass: ModuleMapNgFactoryLoader,
// deps: [
// Compiler,
// MODULE_MAP
// ],
// },
]
}));

Expand Down

0 comments on commit a8f8cdf

Please sign in to comment.