@@ -83,24 +83,7 @@ export function createBrowserCodeBundleOptions(
8383 buildOptions . plugins ?. push ( ...options . plugins ) ;
8484 }
8585
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 ) ;
10487
10588 return buildOptions ;
10689 } ;
@@ -302,9 +285,7 @@ export function createServerMainCodeBundleOptions(
302285
303286 buildOptions . plugins ??= [ ] ;
304287
305- if ( externalPackages ) {
306- buildOptions . packages = 'external' ;
307- } else {
288+ if ( ! externalPackages ) {
308289 buildOptions . plugins . push ( createRxjsEsmResolutionPlugin ( ) ) ;
309290 }
310291
@@ -381,6 +362,8 @@ export function createServerMainCodeBundleOptions(
381362 buildOptions . plugins . push ( ...options . plugins ) ;
382363 }
383364
365+ appendOptionsForExternalPackages ( options , buildOptions ) ;
366+
384367 return buildOptions ;
385368 } ;
386369}
@@ -442,9 +425,7 @@ export function createSsrEntryCodeBundleOptions(
442425
443426 buildOptions . plugins ??= [ ] ;
444427
445- if ( externalPackages ) {
446- buildOptions . packages = 'external' ;
447- } else {
428+ if ( ! externalPackages ) {
448429 buildOptions . plugins . push ( createRxjsEsmResolutionPlugin ( ) ) ;
449430 }
450431
@@ -516,6 +497,8 @@ export function createSsrEntryCodeBundleOptions(
516497 buildOptions . plugins . push ( ...options . plugins ) ;
517498 }
518499
500+ appendOptionsForExternalPackages ( options , buildOptions ) ;
501+
519502 return buildOptions ;
520503 } ;
521504}
@@ -721,3 +704,29 @@ function entryFileToWorkspaceRelative(workspaceRoot: string, entryFile: string):
721704 . replace ( / \\ / g, '/' )
722705 ) ;
723706}
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