@@ -18,7 +18,9 @@ import type { AddressInfo } from 'node:net';
18
18
import path , { posix } from 'node:path' ;
19
19
import { Connect , InlineConfig , ViteDevServer , createServer , normalizePath } from 'vite' ;
20
20
import { JavaScriptTransformer } from '../../tools/esbuild/javascript-transformer' ;
21
+ import { getFeatureSupport , transformSupportedBrowsersToTargets } from '../../tools/esbuild/utils' ;
21
22
import { RenderOptions , renderPage } from '../../utils/server-rendering/render-page' ;
23
+ import { getSupportedBrowsers } from '../../utils/supported-browsers' ;
22
24
import { buildEsbuildBrowser } from '../browser-esbuild' ;
23
25
import { Schema as BrowserBuilderOptions } from '../browser-esbuild/schema' ;
24
26
import { loadProxyConfiguration } from './load-proxy-config' ;
@@ -88,6 +90,16 @@ export async function* serveWithVite(
88
90
if ( server ) {
89
91
handleUpdate ( generatedFiles , server , serverOptions , context . logger ) ;
90
92
} else {
93
+ const projectName = context . target ?. project ;
94
+ if ( ! projectName ) {
95
+ throw new Error ( 'The builder requires a target.' ) ;
96
+ }
97
+
98
+ const { root = '' } = await context . getProjectMetadata ( projectName ) ;
99
+ const projectRoot = path . join ( context . workspaceRoot , root as string ) ;
100
+ const browsers = getSupportedBrowsers ( projectRoot , context . logger ) ;
101
+ const target = transformSupportedBrowsersToTargets ( browsers ) ;
102
+
91
103
// Setup server and start listening
92
104
const serverConfiguration = await setupServer (
93
105
serverOptions ,
@@ -96,6 +108,7 @@ export async function* serveWithVite(
96
108
browserOptions . preserveSymlinks ,
97
109
browserOptions . externalDependencies ,
98
110
! ! browserOptions . ssr ,
111
+ target ,
99
112
) ;
100
113
101
114
server = await createServer ( serverConfiguration ) ;
@@ -237,6 +250,7 @@ export async function setupServer(
237
250
preserveSymlinks : boolean | undefined ,
238
251
prebundleExclude : string [ ] | undefined ,
239
252
ssr : boolean ,
253
+ target : string [ ] ,
240
254
) : Promise < InlineConfig > {
241
255
const proxy = await loadProxyConfiguration (
242
256
serverOptions . workspaceRoot ,
@@ -494,6 +508,9 @@ export async function setupServer(
494
508
entries : [ ] ,
495
509
// Add an esbuild plugin to run the Angular linker on dependencies
496
510
esbuildOptions : {
511
+ // Set esbuild supported targets.
512
+ target,
513
+ supported : getFeatureSupport ( target ) ,
497
514
plugins : [
498
515
{
499
516
name : 'angular-vite-optimize-deps' ,
0 commit comments