9
9
import { BuilderContext , targetFromTargetString } from '@angular-devkit/architect' ;
10
10
import path from 'node:path' ;
11
11
import { normalizeCacheOptions } from '../../utils/normalize-cache' ;
12
+ import { normalizeOptimization } from '../../utils/normalize-optimization' ;
13
+ import { isEsbuildBased } from './builder' ;
12
14
import { Schema as DevServerOptions } from './schema' ;
13
15
14
16
export type NormalizedDevServerOptions = Awaited < ReturnType < typeof normalizeOptions > > ;
@@ -28,7 +30,7 @@ export async function normalizeOptions(
28
30
projectName : string ,
29
31
options : DevServerOptions ,
30
32
) {
31
- const workspaceRoot = context . workspaceRoot ;
33
+ const { workspaceRoot, logger } = context ;
32
34
const projectMetadata = await context . getProjectMetadata ( projectName ) ;
33
35
const projectRoot = path . join ( workspaceRoot , ( projectMetadata . root as string | undefined ) ?? '' ) ;
34
36
@@ -38,6 +40,27 @@ export async function normalizeOptions(
38
40
const buildTargetSpecifier = options . buildTarget ?? options . browserTarget ?? `::development` ;
39
41
const buildTarget = targetFromTargetString ( buildTargetSpecifier , projectName , 'build' ) ;
40
42
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
+
41
64
// Initial options to keep
42
65
const {
43
66
host,
@@ -86,6 +109,6 @@ export async function normalizeOptions(
86
109
sslKey,
87
110
forceEsbuild,
88
111
// Prebundling defaults to true but requires caching to function
89
- prebundle : cacheOptions . enabled && ( prebundle ?? true ) ,
112
+ prebundle : cacheOptions . enabled && ! optimization . scripts && ( prebundle ?? true ) ,
90
113
} ;
91
114
}
0 commit comments