Skip to content

universal: dump out the prerendered file so we can examine it #8483

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 20, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/universal-app/prerender.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import 'reflect-metadata';
import 'zone.js';

import {enableProdMode} from '@angular/core';
import {renderModuleFactory} from '@angular/platform-server';
import {join} from 'path';
import {readFileSync} from 'fs-extra';
import {readFileSync, writeFileSync} from 'fs-extra';
import {log} from 'gulp-util';
import {join} from 'path';
import 'reflect-metadata';
import 'zone.js';
import {KitchenSinkServerModuleNgFactory} from './kitchen-sink/kitchen-sink.ngfactory';

enableProdMode();
Expand All @@ -15,7 +14,10 @@ const result = renderModuleFactory(KitchenSinkServerModuleNgFactory, {
});

result
.then(() => log('Prerender done.'))
.then(content => {
writeFileSync(join(__dirname, 'index-prerendered.html'), content, 'utf-8');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we output that file in the dist/ folder?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, should be under dist/. I thought I added this when I originally wrote this...

Copy link
Member

@crisbeto crisbeto Nov 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initially it just printed out the file in the console, but that made it hard to see any exceptions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's too much. We should just write it to dist/index-prerendered.html and also not under dist/packages/demo-app since it's actually the universal app.

Idea: If we fully use CircleCI at some point, there is the option to upload the index file as an artifact. Meaning that we can download and inspect the output file easily.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not under dist/packages/universal-app? That's actually what I meant to do, just copy/paste-failed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that works too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently I can't import {buildConfig} from 'material2-build-tools' in this file and __dirname seems to point to the correct directory anyways, since we're running the version of the prerender script from dist/packages/universal-app, so... just gonna switch this back to how it was originally

log('Prerender done.');
})
// If rendering the module factory fails, exit the process with an error code because otherwise
// the CI task will not recognize the failure and will show as "success". The error message
// will be printed automatically by the `renderModuleFactory` method.
Expand Down