99import { BuilderContext , targetFromTargetString } from '@angular-devkit/architect' ;
1010import path from 'node:path' ;
1111import { normalizeCacheOptions } from '../../utils/normalize-cache' ;
12+ import { normalizeOptimization } from '../../utils/normalize-optimization' ;
13+ import { isEsbuildBased } from './builder' ;
1214import { Schema as DevServerOptions } from './schema' ;
1315
1416export type NormalizedDevServerOptions = Awaited < ReturnType < typeof normalizeOptions > > ;
@@ -28,7 +30,7 @@ export async function normalizeOptions(
2830 projectName : string ,
2931 options : DevServerOptions ,
3032) {
31- const workspaceRoot = context . workspaceRoot ;
33+ const { workspaceRoot, logger } = context ;
3234 const projectMetadata = await context . getProjectMetadata ( projectName ) ;
3335 const projectRoot = path . join ( workspaceRoot , ( projectMetadata . root as string | undefined ) ?? '' ) ;
3436
@@ -38,6 +40,27 @@ export async function normalizeOptions(
3840 const buildTargetSpecifier = options . buildTarget ?? options . browserTarget ?? `::development` ;
3941 const buildTarget = targetFromTargetString ( buildTargetSpecifier , projectName , 'build' ) ;
4042
43+ // Get the application builder options.
44+ const browserBuilderName = await context . getBuilderNameForTarget ( buildTarget ) ;
45+ const rawBuildOptions = await context . getTargetOptions ( buildTarget ) ;
46+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
47+ const buildOptions = ( await context . validateOptions ( rawBuildOptions , browserBuilderName ) ) as any ;
48+ const optimization = normalizeOptimization ( buildOptions . optimization ) ;
49+
50+ if ( options . prebundle !== false && isEsbuildBased ( browserBuilderName ) ) {
51+ if ( ! cacheOptions . enabled ) {
52+ // Warn if the initial options provided by the user enable prebundling but caching is disabled
53+ logger . warn (
54+ 'Prebundling has been configured but will not be used because caching has been disabled.' ,
55+ ) ;
56+ } else if ( optimization . scripts ) {
57+ // Warn if the initial options provided by the user enable prebundling but script optimization is enabled.
58+ logger . warn (
59+ 'Prebundling has been configured but will not be used because scripts optimization is enabled.' ,
60+ ) ;
61+ }
62+ }
63+
4164 // Initial options to keep
4265 const {
4366 host,
@@ -86,6 +109,6 @@ export async function normalizeOptions(
86109 sslKey,
87110 forceEsbuild,
88111 // Prebundling defaults to true but requires caching to function
89- prebundle : cacheOptions . enabled && ( prebundle ?? true ) ,
112+ prebundle : cacheOptions . enabled && ! optimization . scripts && ( prebundle ?? true ) ,
90113 } ;
91114}
0 commit comments