@@ -85,87 +85,78 @@ function updateApplicationBuilderWorkspaceConfigRule(
8585 projectRoot : string ,
8686 options : AddServerOptions ,
8787) : Rule {
88- return ( ) => {
89- return updateWorkspace ( ( workspace ) => {
90- const buildTarget = workspace . projects . get ( options . project ) ?. targets . get ( 'build' ) ;
91- if ( ! buildTarget ) {
92- return ;
93- }
94-
95- // eslint-disable-next-line @typescript-eslint/no-explicit-any
96- const prodConfig = buildTarget . configurations ?. production as Record < string , any > ;
97- if ( ! prodConfig ) {
98- throw new SchematicsException (
99- `A "production" configuration is not defined for the "build" builder.` ,
100- ) ;
101- }
88+ return updateWorkspace ( ( workspace ) => {
89+ const buildTarget = workspace . projects . get ( options . project ) ?. targets . get ( 'build' ) ;
90+ if ( ! buildTarget ) {
91+ return ;
92+ }
10293
103- prodConfig . prerender = true ;
104- prodConfig . ssr = join ( normalize ( projectRoot ) , 'server.ts' ) ;
105- } ) ;
106- } ;
94+ buildTarget . options = {
95+ ...buildTarget . options ,
96+ prerender : true ,
97+ ssr : join ( normalize ( projectRoot ) , 'server.ts' ) ,
98+ } ;
99+ } ) ;
107100}
108101
109102function updateWebpackBuilderWorkspaceConfigRule ( options : AddServerOptions ) : Rule {
110- return ( ) => {
111- return updateWorkspace ( ( workspace ) => {
112- const projectName = options . project ;
113- const project = workspace . projects . get ( projectName ) ;
114- if ( ! project ) {
115- return ;
116- }
103+ return updateWorkspace ( ( workspace ) => {
104+ const projectName = options . project ;
105+ const project = workspace . projects . get ( projectName ) ;
106+ if ( ! project ) {
107+ return ;
108+ }
117109
118- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
119- const serverTarget = project . targets . get ( 'server' ) ! ;
120- ( serverTarget . options ??= { } ) . main = join ( normalize ( project . root ) , 'server.ts' ) ;
110+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
111+ const serverTarget = project . targets . get ( 'server' ) ! ;
112+ ( serverTarget . options ??= { } ) . main = join ( normalize ( project . root ) , 'server.ts' ) ;
121113
122- const serveSSRTarget = project . targets . get ( SERVE_SSR_TARGET_NAME ) ;
123- if ( serveSSRTarget ) {
124- return ;
125- }
114+ const serveSSRTarget = project . targets . get ( SERVE_SSR_TARGET_NAME ) ;
115+ if ( serveSSRTarget ) {
116+ return ;
117+ }
126118
127- project . targets . add ( {
128- name : SERVE_SSR_TARGET_NAME ,
129- builder : '@angular-devkit/build-angular:ssr-dev-server' ,
130- defaultConfiguration : 'development' ,
131- options : { } ,
132- configurations : {
133- development : {
134- browserTarget : `${ projectName } :build:development` ,
135- serverTarget : `${ projectName } :server:development` ,
136- } ,
137- production : {
138- browserTarget : `${ projectName } :build:production` ,
139- serverTarget : `${ projectName } :server:production` ,
140- } ,
119+ project . targets . add ( {
120+ name : SERVE_SSR_TARGET_NAME ,
121+ builder : '@angular-devkit/build-angular:ssr-dev-server' ,
122+ defaultConfiguration : 'development' ,
123+ options : { } ,
124+ configurations : {
125+ development : {
126+ browserTarget : `${ projectName } :build:development` ,
127+ serverTarget : `${ projectName } :server:development` ,
141128 } ,
142- } ) ;
129+ production : {
130+ browserTarget : `${ projectName } :build:production` ,
131+ serverTarget : `${ projectName } :server:production` ,
132+ } ,
133+ } ,
134+ } ) ;
143135
144- const prerenderTarget = project . targets . get ( PRERENDER_TARGET_NAME ) ;
145- if ( prerenderTarget ) {
146- return ;
147- }
136+ const prerenderTarget = project . targets . get ( PRERENDER_TARGET_NAME ) ;
137+ if ( prerenderTarget ) {
138+ return ;
139+ }
148140
149- project . targets . add ( {
150- name : PRERENDER_TARGET_NAME ,
151- builder : '@angular-devkit/build-angular:prerender' ,
152- defaultConfiguration : 'production' ,
153- options : {
154- routes : [ '/' ] ,
141+ project . targets . add ( {
142+ name : PRERENDER_TARGET_NAME ,
143+ builder : '@angular-devkit/build-angular:prerender' ,
144+ defaultConfiguration : 'production' ,
145+ options : {
146+ routes : [ '/' ] ,
147+ } ,
148+ configurations : {
149+ production : {
150+ browserTarget : `${ projectName } :build:production` ,
151+ serverTarget : `${ projectName } :server:production` ,
155152 } ,
156- configurations : {
157- production : {
158- browserTarget : `${ projectName } :build:production` ,
159- serverTarget : `${ projectName } :server:production` ,
160- } ,
161- development : {
162- browserTarget : `${ projectName } :build:development` ,
163- serverTarget : `${ projectName } :server:development` ,
164- } ,
153+ development : {
154+ browserTarget : `${ projectName } :build:development` ,
155+ serverTarget : `${ projectName } :server:development` ,
165156 } ,
166- } ) ;
157+ } ,
167158 } ) ;
168- } ;
159+ } ) ;
169160}
170161
171162function updateWebpackBuilderServerTsConfigRule ( options : AddServerOptions ) : Rule {
0 commit comments