@@ -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
@@ -378,6 +359,8 @@ export function createServerMainCodeBundleOptions(
378359 buildOptions . plugins . push ( ...options . plugins ) ;
379360 }
380361
362+ appendOptionsForExternalPackages ( options , buildOptions ) ;
363+
381364 return buildOptions ;
382365 } ;
383366}
@@ -439,9 +422,7 @@ export function createSsrEntryCodeBundleOptions(
439422
440423 buildOptions . plugins ??= [ ] ;
441424
442- if ( externalPackages ) {
443- buildOptions . packages = 'external' ;
444- } else {
425+ if ( ! externalPackages ) {
445426 buildOptions . plugins . push ( createRxjsEsmResolutionPlugin ( ) ) ;
446427 }
447428
@@ -513,6 +494,8 @@ export function createSsrEntryCodeBundleOptions(
513494 buildOptions . plugins . push ( ...options . plugins ) ;
514495 }
515496
497+ appendOptionsForExternalPackages ( options , buildOptions ) ;
498+
516499 return buildOptions ;
517500 } ;
518501}
@@ -718,3 +701,29 @@ function entryFileToWorkspaceRelative(workspaceRoot: string, entryFile: string):
718701 . replace ( / \\ / g, '/' )
719702 ) ;
720703}
704+
705+ function appendOptionsForExternalPackages (
706+ options : NormalizedApplicationBuildOptions ,
707+ buildOptions : BuildOptions ,
708+ ) : void {
709+ if ( ! options . externalPackages ) {
710+ return ;
711+ }
712+
713+ buildOptions . plugins ??= [ ] ;
714+
715+ // Package files affected by a customized loader should not be implicitly marked as external
716+ if ( options . loaderExtensions || options . plugins || typeof options . externalPackages === 'object' ) {
717+ // Plugin must be added after custom plugins to ensure any added loader options are considered
718+ buildOptions . plugins . push (
719+ createExternalPackagesPlugin (
720+ options . externalPackages !== true ? options . externalPackages : undefined ,
721+ ) ,
722+ ) ;
723+
724+ buildOptions . packages = undefined ;
725+ } else {
726+ // Safe to use the packages external option directly
727+ buildOptions . packages = 'external' ;
728+ }
729+ }
0 commit comments