@@ -18,8 +18,10 @@ import path, { posix } from 'node:path';
18
18
import type { Connect , InlineConfig , ViteDevServer } from 'vite' ;
19
19
import { BuildOutputFile , BuildOutputFileType } from '../../tools/esbuild/bundler-context' ;
20
20
import { JavaScriptTransformer } from '../../tools/esbuild/javascript-transformer' ;
21
+ import { getFeatureSupport , transformSupportedBrowsersToTargets } from '../../tools/esbuild/utils' ;
21
22
import { createAngularLocaleDataPlugin } from '../../tools/vite/i18n-locale-plugin' ;
22
23
import { RenderOptions , renderPage } from '../../utils/server-rendering/render-page' ;
24
+ import { getSupportedBrowsers } from '../../utils/supported-browsers' ;
23
25
import { getIndexOutputFile } from '../../utils/webpack-browser-config' ;
24
26
import { buildEsbuildBrowser } from '../browser-esbuild' ;
25
27
import { Schema as BrowserBuilderOptions } from '../browser-esbuild/schema' ;
@@ -131,6 +133,16 @@ export async function* serveWithVite(
131
133
if ( server ) {
132
134
handleUpdate ( generatedFiles , server , serverOptions , context . logger ) ;
133
135
} else {
136
+ const projectName = context . target ?. project ;
137
+ if ( ! projectName ) {
138
+ throw new Error ( 'The builder requires a target.' ) ;
139
+ }
140
+
141
+ const { root = '' } = await context . getProjectMetadata ( projectName ) ;
142
+ const projectRoot = path . join ( context . workspaceRoot , root as string ) ;
143
+ const browsers = getSupportedBrowsers ( projectRoot , context . logger ) ;
144
+ const target = transformSupportedBrowsersToTargets ( browsers ) ;
145
+
134
146
// Setup server and start listening
135
147
const serverConfiguration = await setupServer (
136
148
serverOptions ,
@@ -140,6 +152,7 @@ export async function* serveWithVite(
140
152
browserOptions . externalDependencies ,
141
153
! ! browserOptions . ssr ,
142
154
prebundleTransformer ,
155
+ target ,
143
156
) ;
144
157
145
158
server = await createServer ( serverConfiguration ) ;
@@ -295,6 +308,7 @@ export async function setupServer(
295
308
prebundleExclude : string [ ] | undefined ,
296
309
ssr : boolean ,
297
310
prebundleTransformer : JavaScriptTransformer ,
311
+ target : string [ ] ,
298
312
) : Promise < InlineConfig > {
299
313
const proxy = await loadProxyConfiguration (
300
314
serverOptions . workspaceRoot ,
@@ -556,6 +570,9 @@ export async function setupServer(
556
570
entries : [ ] ,
557
571
// Add an esbuild plugin to run the Angular linker on dependencies
558
572
esbuildOptions : {
573
+ // Set esbuild supported targets.
574
+ target,
575
+ supported : getFeatureSupport ( target ) ,
559
576
plugins : [
560
577
{
561
578
name : 'angular-vite-optimize-deps' ,
0 commit comments