Skip to content

Commit 99d9037

Browse files
committed
perf(@angular-devkit/build-angular): only perform a server build when either prerendering, app-shell or ssr is enabled
Prior to this change, a server build was performed when all the "server" features were disabled but the `server` fields was specified.
1 parent 968ee34 commit 99d9037

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

packages/angular_devkit/build_angular/src/builders/application/execute-build.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ export async function executeBuild(
116116
}
117117

118118
// Server application code
119-
if (serverEntryPoint) {
119+
// Skip server build when non of the features are enabled.
120+
if (serverEntryPoint && (prerenderOptions || appShellOptions || ssrOptions)) {
120121
const nodeTargets = getSupportedNodeTargets();
121122
bundlerContexts.push(
122123
new BundlerContext(

packages/angular_devkit/build_angular/src/builders/application/tests/options/server_spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
2424
it('uses a provided TypeScript file', async () => {
2525
harness.useTarget('build', {
2626
...BASE_OPTIONS,
27+
ssr: true,
2728
server: 'src/main.server.ts',
2829
});
2930

@@ -36,6 +37,7 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
3637
it('does not write file to disk when "ssr" is "false"', async () => {
3738
harness.useTarget('build', {
3839
...BASE_OPTIONS,
40+
ssr: true,
3941
server: 'src/main.server.ts',
4042
});
4143

@@ -50,6 +52,7 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
5052

5153
harness.useTarget('build', {
5254
...BASE_OPTIONS,
55+
ssr: true,
5356
server: 'src/server.js',
5457
});
5558

@@ -60,6 +63,7 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
6063
it('fails and shows an error when file does not exist', async () => {
6164
harness.useTarget('build', {
6265
...BASE_OPTIONS,
66+
ssr: true,
6367
server: 'src/missing.ts',
6468
});
6569

@@ -91,6 +95,7 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
9195

9296
harness.useTarget('build', {
9397
...BASE_OPTIONS,
98+
ssr: true,
9499
server: '/file.mjs',
95100
});
96101

0 commit comments

Comments
 (0)