@@ -42,6 +42,11 @@ interface OutputFileRecord {
4242 type : BuildOutputFileType ;
4343}
4444
45+ interface DevServerExternalResultMetadata extends Omit < ExternalResultMetadata , 'explicit' > {
46+ explicitBrowser : string [ ] ;
47+ explicitServer : string [ ] ;
48+ }
49+
4550export type BuilderAction = (
4651 options : ApplicationBuilderInternalOptions ,
4752 context : BuilderContext ,
@@ -140,10 +145,11 @@ export async function* serveWithVite(
140145 let hadError = false ;
141146 const generatedFiles = new Map < string , OutputFileRecord > ( ) ;
142147 const assetFiles = new Map < string , string > ( ) ;
143- const externalMetadata : ExternalResultMetadata = {
148+ const externalMetadata : DevServerExternalResultMetadata = {
144149 implicitBrowser : [ ] ,
145150 implicitServer : [ ] ,
146- explicit : [ ] ,
151+ explicitBrowser : [ ] ,
152+ explicitServer : [ ] ,
147153 } ;
148154
149155 // Add cleanup logic via a builder teardown.
@@ -236,17 +242,20 @@ export async function* serveWithVite(
236242 }
237243
238244 // Empty Arrays to avoid growing unlimited with every re-build.
239- externalMetadata . explicit . length = 0 ;
245+ externalMetadata . explicitBrowser . length = 0 ;
246+ externalMetadata . explicitServer . length = 0 ;
240247 externalMetadata . implicitServer . length = 0 ;
241248 externalMetadata . implicitBrowser . length = 0 ;
242249
243- externalMetadata . explicit . push ( ...explicit ) ;
250+ externalMetadata . explicitBrowser . push ( ...explicit ) ;
251+ externalMetadata . explicitServer . push ( ...explicit , ...nodeJsBuiltinModules ) ;
244252 externalMetadata . implicitServer . push ( ...implicitServerFiltered ) ;
245253 externalMetadata . implicitBrowser . push ( ...implicitBrowserFiltered ) ;
246254
247255 // The below needs to be sorted as Vite uses these options are part of the hashing invalidation algorithm.
248256 // See: https://github.com/vitejs/vite/blob/0873bae0cfe0f0718ad2f5743dd34a17e4ab563d/packages/vite/src/node/optimizer/index.ts#L1203-L1239
249- externalMetadata . explicit . sort ( ) ;
257+ externalMetadata . explicitBrowser . sort ( ) ;
258+ externalMetadata . explicitServer . sort ( ) ;
250259 externalMetadata . implicitServer . sort ( ) ;
251260 externalMetadata . implicitBrowser . sort ( ) ;
252261 }
@@ -494,7 +503,7 @@ export async function setupServer(
494503 outputFiles : Map < string , OutputFileRecord > ,
495504 assets : Map < string , string > ,
496505 preserveSymlinks : boolean | undefined ,
497- externalMetadata : ExternalResultMetadata ,
506+ externalMetadata : DevServerExternalResultMetadata ,
498507 ssr : boolean ,
499508 prebundleTransformer : JavaScriptTransformer ,
500509 target : string [ ] ,
@@ -573,18 +582,18 @@ export async function setupServer(
573582 } ,
574583 // This is needed when `externalDependencies` is used to prevent Vite load errors.
575584 // NOTE: If Vite adds direct support for externals, this can be removed.
576- preTransformRequests : externalMetadata . explicit . length === 0 ,
585+ preTransformRequests : externalMetadata . explicitBrowser . length === 0 ,
577586 } ,
578587 ssr : {
579588 // Note: `true` and `/.*/` have different sematics. When true, the `external` option is ignored.
580589 noExternal : / .* / ,
581590 // Exclude any Node.js built in module and provided dependencies (currently build defined externals)
582- external : externalMetadata . explicit ,
591+ external : externalMetadata . explicitServer ,
583592 optimizeDeps : getDepOptimizationConfig ( {
584593 // Only enable with caching since it causes prebundle dependencies to be cached
585594 disabled : serverOptions . prebundle === false ,
586595 // Exclude any explicitly defined dependencies (currently build defined externals and node.js built-ins)
587- exclude : externalMetadata . explicit ,
596+ exclude : externalMetadata . explicitServer ,
588597 // Include all implict dependencies from the external packages internal option
589598 include : externalMetadata . implicitServer ,
590599 ssr : true ,
@@ -603,19 +612,19 @@ export async function setupServer(
603612 outputFiles,
604613 assets,
605614 ssr,
606- external : externalMetadata . explicit ,
615+ external : externalMetadata . explicitBrowser ,
607616 indexHtmlTransformer,
608617 extensionMiddleware,
609618 normalizePath,
610619 } ) ,
611- createRemoveIdPrefixPlugin ( externalMetadata . explicit ) ,
620+ createRemoveIdPrefixPlugin ( externalMetadata . explicitBrowser ) ,
612621 ] ,
613622 // Browser only optimizeDeps. (This does not run for SSR dependencies).
614623 optimizeDeps : getDepOptimizationConfig ( {
615624 // Only enable with caching since it causes prebundle dependencies to be cached
616625 disabled : serverOptions . prebundle === false ,
617626 // Exclude any explicitly defined dependencies (currently build defined externals)
618- exclude : externalMetadata . explicit ,
627+ exclude : externalMetadata . explicitBrowser ,
619628 // Include all implict dependencies from the external packages internal option
620629 include : externalMetadata . implicitBrowser ,
621630 ssr : false ,
0 commit comments