forked from wpcfan/taskmgr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prerender.js
22 lines (21 loc) · 963 Bytes
/
prerender.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// Load zone.js for the server.
require('zone.js/dist/zone-node');
require('reflect-metadata');
const fs = require('fs');
const { renderModuleFactory } = require('@angular/platform-server');
// Import module map for lazy loading
const { provideModuleMap } = require('@nguniversal/module-map-ngfactory-loader');
// Import the AOT compiled factory for your AppServerModule.
// This import will change with the hash of your built server bundle.
const { AppServerModuleNgFactory, LAZY_MODULE_MAP } = require(`./dist-server/main.bundle`);
// Load the index.html file containing referances to your application bundle
const index = fs.readFileSync('./dist/index.html', 'utf8');
// Writes rendered HTML to ./dist/index.html, replacing the file if it already exists.
renderModuleFactory(AppServerModuleNgFactory, {
document: index,
url: '/',
extraProviders: [
provideModuleMap(LAZY_MODULE_MAP)
]
})
.then(html => fs.writeFileSync('./dist/index.html', html));