diff --git a/packages/angular/ssr/schematics/ng-add/index.ts b/packages/angular/ssr/schematics/ng-add/index.ts index d103b84bffc0..7acdee356b71 100644 --- a/packages/angular/ssr/schematics/ng-add/index.ts +++ b/packages/angular/ssr/schematics/ng-add/index.ts @@ -85,87 +85,78 @@ function updateApplicationBuilderWorkspaceConfigRule( projectRoot: string, options: AddServerOptions, ): Rule { - return () => { - return updateWorkspace((workspace) => { - const buildTarget = workspace.projects.get(options.project)?.targets.get('build'); - if (!buildTarget) { - return; - } - - // eslint-disable-next-line @typescript-eslint/no-explicit-any - const prodConfig = buildTarget.configurations?.production as Record; - if (!prodConfig) { - throw new SchematicsException( - `A "production" configuration is not defined for the "build" builder.`, - ); - } + return updateWorkspace((workspace) => { + const buildTarget = workspace.projects.get(options.project)?.targets.get('build'); + if (!buildTarget) { + return; + } - prodConfig.prerender = true; - prodConfig.ssr = join(normalize(projectRoot), 'server.ts'); - }); - }; + buildTarget.options = { + ...buildTarget.options, + prerender: true, + ssr: join(normalize(projectRoot), 'server.ts'), + }; + }); } function updateWebpackBuilderWorkspaceConfigRule(options: AddServerOptions): Rule { - return () => { - return updateWorkspace((workspace) => { - const projectName = options.project; - const project = workspace.projects.get(projectName); - if (!project) { - return; - } + return updateWorkspace((workspace) => { + const projectName = options.project; + const project = workspace.projects.get(projectName); + if (!project) { + return; + } - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - const serverTarget = project.targets.get('server')!; - (serverTarget.options ??= {}).main = join(normalize(project.root), 'server.ts'); + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + const serverTarget = project.targets.get('server')!; + (serverTarget.options ??= {}).main = join(normalize(project.root), 'server.ts'); - const serveSSRTarget = project.targets.get(SERVE_SSR_TARGET_NAME); - if (serveSSRTarget) { - return; - } + const serveSSRTarget = project.targets.get(SERVE_SSR_TARGET_NAME); + if (serveSSRTarget) { + return; + } - project.targets.add({ - name: SERVE_SSR_TARGET_NAME, - builder: '@angular-devkit/build-angular:ssr-dev-server', - defaultConfiguration: 'development', - options: {}, - configurations: { - development: { - browserTarget: `${projectName}:build:development`, - serverTarget: `${projectName}:server:development`, - }, - production: { - browserTarget: `${projectName}:build:production`, - serverTarget: `${projectName}:server:production`, - }, + project.targets.add({ + name: SERVE_SSR_TARGET_NAME, + builder: '@angular-devkit/build-angular:ssr-dev-server', + defaultConfiguration: 'development', + options: {}, + configurations: { + development: { + browserTarget: `${projectName}:build:development`, + serverTarget: `${projectName}:server:development`, }, - }); + production: { + browserTarget: `${projectName}:build:production`, + serverTarget: `${projectName}:server:production`, + }, + }, + }); - const prerenderTarget = project.targets.get(PRERENDER_TARGET_NAME); - if (prerenderTarget) { - return; - } + const prerenderTarget = project.targets.get(PRERENDER_TARGET_NAME); + if (prerenderTarget) { + return; + } - project.targets.add({ - name: PRERENDER_TARGET_NAME, - builder: '@angular-devkit/build-angular:prerender', - defaultConfiguration: 'production', - options: { - routes: ['/'], + project.targets.add({ + name: PRERENDER_TARGET_NAME, + builder: '@angular-devkit/build-angular:prerender', + defaultConfiguration: 'production', + options: { + routes: ['/'], + }, + configurations: { + production: { + browserTarget: `${projectName}:build:production`, + serverTarget: `${projectName}:server:production`, }, - configurations: { - production: { - browserTarget: `${projectName}:build:production`, - serverTarget: `${projectName}:server:production`, - }, - development: { - browserTarget: `${projectName}:build:development`, - serverTarget: `${projectName}:server:development`, - }, + development: { + browserTarget: `${projectName}:build:development`, + serverTarget: `${projectName}:server:development`, }, - }); + }, }); - }; + }); } function updateWebpackBuilderServerTsConfigRule(options: AddServerOptions): Rule {