7
7
*/
8
8
9
9
import { BuilderContext , BuilderOutput , createBuilder , targetFromTargetString } from '@angular-devkit/architect' ;
10
+ import { BrowserBuilderOptions } from '@angular-devkit/build-angular' ;
10
11
import { fork } from 'child_process' ;
11
12
import * as fs from 'fs' ;
12
13
import * as path from 'path' ;
13
14
14
15
import { PrerenderBuilderOptions , PrerenderBuilderOutput } from './models' ;
15
- import { getRoutes , shardArray } from './utils' ;
16
+ import { getIndexOutputFile , getRoutes , shardArray } from './utils' ;
16
17
17
18
type BuildBuilderOutput = BuilderOutput & {
18
19
baseOutputPath : string ;
@@ -67,13 +68,15 @@ async function _parallelRenderRoutes(
67
68
context : BuilderContext ,
68
69
indexHtml : string ,
69
70
outputPath : string ,
71
+ indexFile : string ,
70
72
serverBundlePath : string ,
71
73
) : Promise < void > {
72
74
const workerFile = path . join ( __dirname , 'render.js' ) ;
73
75
const childProcesses = shardedRoutes . map ( routes =>
74
76
new Promise ( ( resolve , reject ) => {
75
77
fork ( workerFile , [
76
78
indexHtml ,
79
+ indexFile ,
77
80
serverBundlePath ,
78
81
outputPath ,
79
82
...routes ,
@@ -103,12 +106,15 @@ async function _renderUniversal(
103
106
context : BuilderContext ,
104
107
browserResult : BuildBuilderOutput ,
105
108
serverResult : BuildBuilderOutput ,
109
+ browserOptions : BrowserBuilderOptions ,
106
110
numProcesses ?: number ,
107
111
) : Promise < BuildBuilderOutput > {
112
+ // Users can specify a different base html file e.g. "src/home.html"
113
+ const indexFile = getIndexOutputFile ( browserOptions ) ;
108
114
// We need to render the routes for each locale from the browser output.
109
115
for ( const outputPath of browserResult . outputPaths ) {
110
- const browserIndexOutputPath = path . join ( outputPath , 'index.html' ) ;
111
- const indexHtml = fs . readFileSync ( browserIndexOutputPath , 'utf8' ) ;
116
+ const browserIndexInputPath = path . join ( outputPath , indexFile ) ;
117
+ const indexHtml = fs . readFileSync ( browserIndexInputPath , 'utf8' ) ;
112
118
113
119
const { baseOutputPath = '' } = serverResult ;
114
120
const localeDirectory = path . relative ( browserResult . baseOutputPath , outputPath ) ;
@@ -125,6 +131,7 @@ async function _renderUniversal(
125
131
context ,
126
132
indexHtml ,
127
133
outputPath ,
134
+ indexFile ,
128
135
serverBundlePath ,
129
136
) ;
130
137
}
@@ -152,7 +159,18 @@ export async function execute(
152
159
return { success, error } as BuilderOutput ;
153
160
}
154
161
155
- return _renderUniversal ( routes , context , browserResult , serverResult , options . numProcesses ) ;
162
+ const browserTarget = targetFromTargetString ( options . browserTarget ) ;
163
+ const browserOptions =
164
+ await context . getTargetOptions ( browserTarget ) as unknown as BrowserBuilderOptions ;
165
+
166
+ return _renderUniversal (
167
+ routes ,
168
+ context ,
169
+ browserResult ,
170
+ serverResult ,
171
+ browserOptions ,
172
+ options . numProcesses ,
173
+ ) ;
156
174
}
157
175
158
176
export default createBuilder ( execute ) ;
0 commit comments