@@ -15,6 +15,7 @@ import { JsonObject, experimental, join, normalize, resolve, schema } from '@ang
15
15
import { NodeJsSyncHost } from '@angular-devkit/core/node' ;
16
16
import * as fs from 'fs' ;
17
17
import * as path from 'path' ;
18
+ import { readTsconfig } from '../angular-cli-files/utilities/read-tsconfig' ;
18
19
import { augmentAppWithServiceWorker } from '../angular-cli-files/utilities/service-worker' ;
19
20
import { BrowserBuilderOutput } from '../browser' ;
20
21
import { Schema as BrowserBuilderSchema } from '../browser/schema' ;
@@ -31,40 +32,47 @@ async function _renderUniversal(
31
32
const browserIndexOutputPath = path . join ( browserResult . outputPath || '' , 'index.html' ) ;
32
33
const indexHtml = fs . readFileSync ( browserIndexOutputPath , 'utf8' ) ;
33
34
const serverBundlePath = await _getServerModuleBundlePath ( options , context , serverResult ) ;
34
-
35
35
const root = context . workspaceRoot ;
36
36
37
+ // Get browser target options.
38
+ const browserTarget = targetFromTargetString ( options . browserTarget ) ;
39
+ const rawBrowserOptions = await context . getTargetOptions ( browserTarget ) ;
40
+ const browserBuilderName = await context . getBuilderNameForTarget ( browserTarget ) ;
41
+ const browserOptions = await context . validateOptions < JsonObject & BrowserBuilderSchema > (
42
+ rawBrowserOptions ,
43
+ browserBuilderName ,
44
+ ) ;
45
+
46
+ // Determine if browser app was compiled using Ivy.
47
+ const { options : compilerOptions } = readTsconfig ( browserOptions . tsConfig , context . workspaceRoot ) ;
48
+ const ivy = compilerOptions . enableIvy ;
49
+
37
50
// Initialize zone.js
38
51
const zonePackage = require . resolve ( 'zone.js' , { paths : [ root ] } ) ;
39
52
await import ( zonePackage ) ;
40
53
41
54
// Load platform server module renderer
42
55
const platformServerPackage = require . resolve ( '@angular/platform-server' , { paths : [ root ] } ) ;
43
- const renderModuleFactory = await import ( platformServerPackage )
56
+ const renderOpts = {
57
+ document : indexHtml ,
58
+ url : options . route ,
59
+ } ;
60
+
61
+ // Render app using Ivy or VE
62
+ const renderCall = await import ( platformServerPackage )
44
63
// tslint:disable-next-line:no-implicit-dependencies
45
- . then ( ( m : typeof import ( '@angular/platform-server' ) ) => m . renderModuleFactory ) ;
64
+ . then ( ( m : typeof import ( '@angular/platform-server' ) ) => ivy
65
+ ? m . renderModule ( require ( serverBundlePath ) . AppServerModule , renderOpts )
66
+ : m . renderModuleFactory ( require ( serverBundlePath ) . AppServerModuleNgFactory , renderOpts ) ) ;
46
67
47
- const AppServerModuleNgFactory = require ( serverBundlePath ) . AppServerModuleNgFactory ;
68
+ // Render to HTML and overwrite the client index file.
69
+ const html = await renderCall ;
48
70
const outputIndexPath = options . outputIndexPath
49
71
? path . join ( root , options . outputIndexPath )
50
72
: browserIndexOutputPath ;
51
73
52
- // Render to HTML and overwrite the client index file.
53
- const html = await renderModuleFactory ( AppServerModuleNgFactory , {
54
- document : indexHtml ,
55
- url : options . route ,
56
- } ) ;
57
-
58
74
fs . writeFileSync ( outputIndexPath , html ) ;
59
75
60
- const browserTarget = targetFromTargetString ( options . browserTarget ) ;
61
- const rawBrowserOptions = await context . getTargetOptions ( browserTarget ) ;
62
- const browserBuilderName = await context . getBuilderNameForTarget ( browserTarget ) ;
63
- const browserOptions = await context . validateOptions < JsonObject & BrowserBuilderSchema > (
64
- rawBrowserOptions ,
65
- browserBuilderName ,
66
- ) ;
67
-
68
76
if ( browserOptions . serviceWorker ) {
69
77
const host = new NodeJsSyncHost ( ) ;
70
78
// Create workspace.
0 commit comments