Skip to content

Commit 3ede1a2

Browse files
committed
feat(@angular-devkit/build-angular): allow forcing esbuild builder with dev-server
To allow lower overhead trial of the developer preview of the esbuild-based builder system, the development server now has an option to force the usage of the esbuild-based build system while still retaining the default Webpack-based build system for the `build` command. The `forceEsbuild`/`--force-esbuild` option can be added to the `angular.json` options for the `serve` target or used on the command line, respectively. The `browser-esbuild` builder will be used to build the application using the options specified by the server configuration's `browserTarget` option. Unsupported build options will be ignored. If using a third-party builder, a warning will be issued but the build will still be attempted. Third-party builder usage in this context is considered unsupported and may result in unexpected behavior or build failures.
1 parent 35d239e commit 3ede1a2

File tree

4 files changed

+19
-1
lines changed

4 files changed

+19
-1
lines changed

goldens/public-api/angular_devkit/build_angular/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ export interface DevServerBuilderOptions {
110110
allowedHosts?: string[];
111111
browserTarget: string;
112112
disableHostCheck?: boolean;
113+
forceEsbuild?: boolean;
113114
headers?: {
114115
[key: string]: string;
115116
};

packages/angular_devkit/build_angular/src/builders/dev-server/builder.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ export function execute(
4545
return defer(() => initialize(options, projectName, context)).pipe(
4646
switchMap(({ builderName, normalizedOptions }) => {
4747
// Use vite-based development server for esbuild-based builds
48-
if (builderName === '@angular-devkit/build-angular:browser-esbuild') {
48+
if (
49+
builderName === '@angular-devkit/build-angular:browser-esbuild' ||
50+
normalizedOptions.forceEsbuild
51+
) {
4952
return defer(() => import('./vite-server')).pipe(
5053
switchMap(({ serveWithVite }) => serveWithVite(normalizedOptions, builderName, context)),
5154
);
@@ -95,6 +98,13 @@ case.
9598
);
9699
}
97100

101+
if (normalizedOptions.forceEsbuild && !builderName.startsWith('@angular-devkit/build-angular:')) {
102+
context.logger.warn(
103+
'Warning: Forcing the use of the esbuild-based build system with third-party builders' +
104+
' may cause unexpected behavior and/or build failures.',
105+
);
106+
}
107+
98108
normalizedOptions.port = await checkPort(normalizedOptions.port, normalizedOptions.host);
99109

100110
return { builderName, normalizedOptions };

packages/angular_devkit/build_angular/src/builders/dev-server/options.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export async function normalizeOptions(
5555
ssl,
5656
sslCert,
5757
sslKey,
58+
forceEsbuild,
5859
} = options;
5960

6061
// Return all the normalized options
@@ -80,5 +81,6 @@ export async function normalizeOptions(
8081
ssl,
8182
sslCert,
8283
sslKey,
84+
forceEsbuild,
8385
};
8486
}

packages/angular_devkit/build_angular/src/builders/dev-server/schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@
9595
"poll": {
9696
"type": "number",
9797
"description": "Enable and define the file watching poll time period in milliseconds."
98+
},
99+
"forceEsbuild": {
100+
"type": "boolean",
101+
"description": "Force the development server to use the 'browser-esbuild' builder when building. This is a developer preview option for the esbuild-based build system.",
102+
"default": false
98103
}
99104
},
100105
"additionalProperties": false,

0 commit comments

Comments
 (0)