From d349ed24ac5a4bdc6fe4dc1bdf3b59210479f9bb Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Fri, 25 Oct 2024 06:38:48 +0000 Subject: [PATCH 1/2] fix(@angular/build): add warning when `--prerendering` or `--app-shell` are no-ops Both options are ineffective when used with `outputMode`, so a warning is now issued. --- .../build/src/builders/application/options.ts | 12 ++++++------ .../build/src/builders/application/schema.json | 4 +--- .../build/src/builders/dev-server/vite-server.ts | 2 +- .../builders/extract-i18n/application-extraction.ts | 5 +++-- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/packages/angular/build/src/builders/application/options.ts b/packages/angular/build/src/builders/application/options.ts index 79c0052af18e..df34c1cbe510 100644 --- a/packages/angular/build/src/builders/application/options.ts +++ b/packages/angular/build/src/builders/application/options.ts @@ -220,17 +220,17 @@ export async function normalizeOptions( options.ssr = false; } - if (options.prerender) { + if (options.prerender !== undefined) { context.logger.warn( - 'The "prerender" option is no longer needed when "outputMode" is specified.', + 'The "prerender" option is not considered when "outputMode" is specified.', ); - } else { - options.prerender = !!options.server; } - if (options.appShell) { + options.prerender = !!options.server; + + if (options.appShell !== undefined) { context.logger.warn( - 'The "appShell" option is no longer needed when "outputMode" is specified.', + 'The "appShell" option is not considered when "outputMode" is specified.', ); } } diff --git a/packages/angular/build/src/builders/application/schema.json b/packages/angular/build/src/builders/application/schema.json index d47875c6527e..17a48a7590ae 100644 --- a/packages/angular/build/src/builders/application/schema.json +++ b/packages/angular/build/src/builders/application/schema.json @@ -536,7 +536,6 @@ }, "prerender": { "description": "Prerender (SSG) pages of your application during build time.", - "default": false, "oneOf": [ { "type": "boolean", @@ -586,8 +585,7 @@ }, "appShell": { "type": "boolean", - "description": "Generates an application shell during build time.", - "default": false + "description": "Generates an application shell during build time." }, "outputMode": { "type": "string", diff --git a/packages/angular/build/src/builders/dev-server/vite-server.ts b/packages/angular/build/src/builders/dev-server/vite-server.ts index 7a4acb7a00d1..34b6f2745c6f 100644 --- a/packages/angular/build/src/builders/dev-server/vite-server.ts +++ b/packages/angular/build/src/builders/dev-server/vite-server.ts @@ -102,7 +102,7 @@ export async function* serveWithVite( if (browserOptions.prerender || (browserOptions.outputMode && browserOptions.server)) { // Disable prerendering if enabled and force SSR. // This is so instead of prerendering all the routes for every change, the page is "prerendered" when it is requested. - browserOptions.prerender = false; + browserOptions.prerender = undefined; browserOptions.ssr ||= true; } diff --git a/packages/angular_devkit/build_angular/src/builders/extract-i18n/application-extraction.ts b/packages/angular_devkit/build_angular/src/builders/extract-i18n/application-extraction.ts index 78c718eee28f..fb6e9138982e 100644 --- a/packages/angular_devkit/build_angular/src/builders/extract-i18n/application-extraction.ts +++ b/packages/angular_devkit/build_angular/src/builders/extract-i18n/application-extraction.ts @@ -53,8 +53,9 @@ export async function extractMessages( buildOptions.serviceWorker = false; buildOptions.server = undefined; buildOptions.ssr = false; - buildOptions.appShell = false; - buildOptions.prerender = false; + buildOptions.appShell = undefined; + buildOptions.prerender = undefined; + buildOptions.outputMode = undefined; const builderResult = await first(buildApplicationInternal(buildOptions, context)); From 94c9c7861c87ee52606a88edfcf1d11bf314ac3b Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Fri, 25 Oct 2024 06:42:25 +0000 Subject: [PATCH 2/2] fix(@angular/build): simplify disabling server features with `--no-server` via command line When `outputMode` is configured, `--prerender` and `--app-shell` become no-ops, making server feature disabling difficult without modifying the configuration. This commit introduces the `--no-server` option, which can be used with `--output-mode static` to fully disable all server features. ``` ng build --output-mode static --no-server ``` --- .../build/src/builders/application/schema.json | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/angular/build/src/builders/application/schema.json b/packages/angular/build/src/builders/application/schema.json index 17a48a7590ae..a8e8e13a8016 100644 --- a/packages/angular/build/src/builders/application/schema.json +++ b/packages/angular/build/src/builders/application/schema.json @@ -18,7 +18,18 @@ }, "server": { "type": "string", - "description": "The full path for the server entry point to the application, relative to the current workspace." + "description": "The full path for the server entry point to the application, relative to the current workspace.", + "oneOf": [ + { + "type": "string", + "description": "The full path for the server entry point to the application, relative to the current workspace." + }, + { + "const": false, + "type": "boolean", + "description": "Indicates that a server entry point is not provided." + } + ] }, "polyfills": { "description": "A list of polyfills to include in the build. Can be a full path for a file, relative to the current workspace or module specifier. Example: 'zone.js'.",