forked from angular/components
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprerender.ts
More file actions
36 lines (29 loc) · 1.19 KB
/
Copy pathprerender.ts
File metadata and controls
36 lines (29 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import 'reflect-metadata';
import 'zone.js';
import {renderModule} from '@angular/platform-server';
import {readFileSync, writeFileSync} from 'fs';
import {join} from 'path';
import {runfiles} from '@bazel/runfiles';
import {KitchenSinkRootServerModule} from './kitchen-sink-root';
// Do not enable production mode, because otherwise the `MatCommonModule` won't execute
// the browser related checks that could cause NodeJS issues.
// Resolve the path to the "index.html" through Bazel runfile resolution.
const indexHtmlPath = runfiles.resolvePackageRelative('./index.html');
const result = renderModule(KitchenSinkRootServerModule, {
document: readFileSync(indexHtmlPath, 'utf-8'),
});
const outDir = process.env.TEST_UNDECLARED_OUTPUTS_DIR as string;
result
.then(content => {
const filename = join(outDir, 'index-prerendered.html');
console.log('Inspect pre-rendered page here:');
console.log(`file://${filename}`);
writeFileSync(filename, content, 'utf-8');
console.log('Prerender done.');
})
// If rendering the module factory fails, print the error and exit the process
// with a non-zero exit code.
.catch(error => {
console.error(error);
process.exit(1);
});