Skip to content

Commit b5ec679

Browse files
committed
refactor(@angular/build): add NG_BUILD_PARTIAL_SSR environment variable to disable prerendering and manifest generation
This change allows for forced disabling of prerendering and route extraction when using Vite with Angular CLI. In certain scenarios, such as when the application builder is invoked directly and not in watch mode (e.g. ADEV), an external configuration may be necessary.
1 parent 17a232b commit b5ec679

File tree

5 files changed

+15
-13
lines changed

5 files changed

+15
-13
lines changed

packages/angular/build/src/builders/application/execute-post-bundle.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export async function executePostBundleSteps(
7070
prerenderOptions,
7171
appShellOptions,
7272
workspaceRoot,
73-
disableFullServerManifestGeneration,
73+
partialSSRBuild,
7474
} = options;
7575

7676
// Index HTML content without CSS inlining to be used for server rendering (AppShell, SSG and SSR).
@@ -125,7 +125,7 @@ export async function executePostBundleSteps(
125125
// Pre-render (SSG) and App-shell
126126
// If localization is enabled, prerendering is handled in the inlining process.
127127
if (
128-
!disableFullServerManifestGeneration &&
128+
!partialSSRBuild &&
129129
(prerenderOptions || appShellOptions || (outputMode && serverEntryPoint)) &&
130130
!allErrors.length
131131
) {

packages/angular/build/src/builders/application/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,15 @@ export async function* buildApplicationInternal(
8888

8989
yield* runEsBuildBuildAction(
9090
async (rebuildState) => {
91-
const { serverEntryPoint, jsonLogs, disableFullServerManifestGeneration } = normalizedOptions;
91+
const { serverEntryPoint, jsonLogs, partialSSRBuild } = normalizedOptions;
9292

9393
const startTime = process.hrtime.bigint();
9494
const result = await executeBuild(normalizedOptions, context, rebuildState);
9595

9696
if (jsonLogs) {
9797
result.addLog(await createJsonBuildManifest(result, normalizedOptions));
9898
} else {
99-
if (serverEntryPoint && !disableFullServerManifestGeneration) {
99+
if (serverEntryPoint && !partialSSRBuild) {
100100
const prerenderedRoutesLength = Object.keys(result.prerenderedRoutes).length;
101101
let prerenderMsg = `Prerendered ${prerenderedRoutesLength} static route`;
102102
prerenderMsg += prerenderedRoutesLength !== 1 ? 's.' : '.';

packages/angular/build/src/builders/application/options.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { createRequire } from 'node:module';
1414
import path from 'node:path';
1515
import { normalizeAssetPatterns, normalizeOptimization, normalizeSourceMaps } from '../../utils';
1616
import { supportColor } from '../../utils/color';
17-
import { useJSONBuildLogs } from '../../utils/environment-options';
17+
import { useJSONBuildLogs, usePartialSsrBuild } from '../../utils/environment-options';
1818
import { I18nOptions, createI18nOptions } from '../../utils/i18n-options';
1919
import { IndexHtmlTransform } from '../../utils/index-file/index-html-generator';
2020
import { normalizeCacheOptions } from '../../utils/normalize-cache';
@@ -82,14 +82,12 @@ interface InternalOptions {
8282
forceI18nFlatOutput?: boolean;
8383

8484
/**
85-
* When set to `true`, disables the generation of a full manifest with routes.
86-
*
87-
* This option is primarily used during development to improve performance,
88-
* as the full manifest is generated at runtime when using the development server.
85+
* When set to `true`, enables fast SSR in development mode by disabling the full manifest generation and prerendering.
8986
*
87+
* This option is intended to optimize performance during development by skipping prerendering and route extraction when not required.
9088
* @default false
9189
*/
92-
disableFullServerManifestGeneration?: boolean;
90+
partialSSRBuild?: boolean;
9391

9492
/**
9593
* Enables the use of AOT compiler emitted external runtime styles.
@@ -382,7 +380,7 @@ export async function normalizeOptions(
382380
deployUrl,
383381
clearScreen,
384382
define,
385-
disableFullServerManifestGeneration = false,
383+
partialSSRBuild = false,
386384
externalRuntimeStyles,
387385
} = options;
388386

@@ -444,7 +442,7 @@ export async function normalizeOptions(
444442
colors: supportColor(),
445443
clearScreen,
446444
define,
447-
disableFullServerManifestGeneration,
445+
partialSSRBuild: usePartialSsrBuild || partialSSRBuild,
448446
externalRuntimeStyles,
449447
};
450448
}

packages/angular/build/src/builders/dev-server/vite-server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export async function* serveWithVite(
110110

111111
// Disable generating a full manifest with routes.
112112
// This is done during runtime when using the dev-server.
113-
browserOptions.disableFullServerManifestGeneration = true;
113+
browserOptions.partialSSRBuild = true;
114114

115115
// The development server currently only supports a single locale when localizing.
116116
// This matches the behavior of the Webpack-based development server but could be expanded in the future.

packages/angular/build/src/utils/environment-options.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,7 @@ export const shouldOptimizeChunks =
104104
const hmrComponentStylesVariable = process.env['NG_HMR_CSTYLES'];
105105
export const useComponentStyleHmr =
106106
isPresent(hmrComponentStylesVariable) && isEnabled(hmrComponentStylesVariable);
107+
108+
const partialSsrBuildVariable = process.env['NG_BUILD_PARTIAL_SSR'];
109+
export const usePartialSsrBuild =
110+
isPresent(partialSsrBuildVariable) && isEnabled(partialSsrBuildVariable);

0 commit comments

Comments
 (0)