@@ -83,24 +83,7 @@ export function createBrowserCodeBundleOptions(
83
83
buildOptions . plugins ?. push ( ...options . plugins ) ;
84
84
}
85
85
86
- if ( options . externalPackages ) {
87
- // Package files affected by a customized loader should not be implicitly marked as external
88
- if (
89
- options . loaderExtensions ||
90
- options . plugins ||
91
- typeof options . externalPackages === 'object'
92
- ) {
93
- // Plugin must be added after custom plugins to ensure any added loader options are considered
94
- buildOptions . plugins ?. push (
95
- createExternalPackagesPlugin (
96
- options . externalPackages !== true ? options . externalPackages : undefined ,
97
- ) ,
98
- ) ;
99
- } else {
100
- // Safe to use the packages external option directly
101
- buildOptions . packages = 'external' ;
102
- }
103
- }
86
+ appendOptionsForExternalPackages ( options , buildOptions ) ;
104
87
105
88
return buildOptions ;
106
89
} ;
@@ -302,9 +285,7 @@ export function createServerMainCodeBundleOptions(
302
285
303
286
buildOptions . plugins ??= [ ] ;
304
287
305
- if ( externalPackages ) {
306
- buildOptions . packages = 'external' ;
307
- } else {
288
+ if ( ! externalPackages ) {
308
289
buildOptions . plugins . push ( createRxjsEsmResolutionPlugin ( ) ) ;
309
290
}
310
291
@@ -381,6 +362,8 @@ export function createServerMainCodeBundleOptions(
381
362
buildOptions . plugins . push ( ...options . plugins ) ;
382
363
}
383
364
365
+ appendOptionsForExternalPackages ( options , buildOptions ) ;
366
+
384
367
return buildOptions ;
385
368
} ;
386
369
}
@@ -442,9 +425,7 @@ export function createSsrEntryCodeBundleOptions(
442
425
443
426
buildOptions . plugins ??= [ ] ;
444
427
445
- if ( externalPackages ) {
446
- buildOptions . packages = 'external' ;
447
- } else {
428
+ if ( ! externalPackages ) {
448
429
buildOptions . plugins . push ( createRxjsEsmResolutionPlugin ( ) ) ;
449
430
}
450
431
@@ -516,6 +497,8 @@ export function createSsrEntryCodeBundleOptions(
516
497
buildOptions . plugins . push ( ...options . plugins ) ;
517
498
}
518
499
500
+ appendOptionsForExternalPackages ( options , buildOptions ) ;
501
+
519
502
return buildOptions ;
520
503
} ;
521
504
}
@@ -721,3 +704,29 @@ function entryFileToWorkspaceRelative(workspaceRoot: string, entryFile: string):
721
704
. replace ( / \\ / g, '/' )
722
705
) ;
723
706
}
707
+
708
+ function appendOptionsForExternalPackages (
709
+ options : NormalizedApplicationBuildOptions ,
710
+ buildOptions : BuildOptions ,
711
+ ) : void {
712
+ if ( ! options . externalPackages ) {
713
+ return ;
714
+ }
715
+
716
+ buildOptions . plugins ??= [ ] ;
717
+
718
+ // Package files affected by a customized loader should not be implicitly marked as external
719
+ if ( options . loaderExtensions || options . plugins || typeof options . externalPackages === 'object' ) {
720
+ // Plugin must be added after custom plugins to ensure any added loader options are considered
721
+ buildOptions . plugins . push (
722
+ createExternalPackagesPlugin (
723
+ options . externalPackages !== true ? options . externalPackages : undefined ,
724
+ ) ,
725
+ ) ;
726
+
727
+ buildOptions . packages = undefined ;
728
+ } else {
729
+ // Safe to use the packages external option directly
730
+ buildOptions . packages = 'external' ;
731
+ }
732
+ }
0 commit comments