@@ -40,6 +40,11 @@ interface OutputFileRecord {
4040 servable : boolean ;
4141}
4242
43+ interface DevServerExternalResultMetadata extends Omit < ExternalResultMetadata , 'explicit' > {
44+ explicitBrowser : string [ ] ;
45+ explicitServer : string [ ] ;
46+ }
47+
4348export type BuilderAction = (
4449 options : ApplicationBuilderInternalOptions ,
4550 context : BuilderContext ,
@@ -138,10 +143,11 @@ export async function* serveWithVite(
138143 let hadError = false ;
139144 const generatedFiles = new Map < string , OutputFileRecord > ( ) ;
140145 const assetFiles = new Map < string , string > ( ) ;
141- const externalMetadata : ExternalResultMetadata = {
146+ const externalMetadata : DevServerExternalResultMetadata = {
142147 implicitBrowser : [ ] ,
143148 implicitServer : [ ] ,
144- explicit : [ ] ,
149+ explicitBrowser : [ ] ,
150+ explicitServer : [ ] ,
145151 } ;
146152
147153 // Add cleanup logic via a builder teardown.
@@ -234,17 +240,20 @@ export async function* serveWithVite(
234240 }
235241
236242 // Empty Arrays to avoid growing unlimited with every re-build.
237- externalMetadata . explicit . length = 0 ;
243+ externalMetadata . explicitBrowser . length = 0 ;
244+ externalMetadata . explicitServer . length = 0 ;
238245 externalMetadata . implicitServer . length = 0 ;
239246 externalMetadata . implicitBrowser . length = 0 ;
240247
241- externalMetadata . explicit . push ( ...explicit ) ;
248+ externalMetadata . explicitBrowser . push ( ...explicit ) ;
249+ externalMetadata . explicitServer . push ( ...explicit , ...nodeJsBuiltinModules ) ;
242250 externalMetadata . implicitServer . push ( ...implicitServerFiltered ) ;
243251 externalMetadata . implicitBrowser . push ( ...implicitBrowserFiltered ) ;
244252
245253 // The below needs to be sorted as Vite uses these options are part of the hashing invalidation algorithm.
246254 // See: https://github.com/vitejs/vite/blob/0873bae0cfe0f0718ad2f5743dd34a17e4ab563d/packages/vite/src/node/optimizer/index.ts#L1203-L1239
247- externalMetadata . explicit . sort ( ) ;
255+ externalMetadata . explicitBrowser . sort ( ) ;
256+ externalMetadata . explicitServer . sort ( ) ;
248257 externalMetadata . implicitServer . sort ( ) ;
249258 externalMetadata . implicitBrowser . sort ( ) ;
250259 }
@@ -478,7 +487,7 @@ export async function setupServer(
478487 outputFiles : Map < string , OutputFileRecord > ,
479488 assets : Map < string , string > ,
480489 preserveSymlinks : boolean | undefined ,
481- externalMetadata : ExternalResultMetadata ,
490+ externalMetadata : DevServerExternalResultMetadata ,
482491 ssr : boolean ,
483492 prebundleTransformer : JavaScriptTransformer ,
484493 target : string [ ] ,
@@ -557,18 +566,18 @@ export async function setupServer(
557566 } ,
558567 // This is needed when `externalDependencies` is used to prevent Vite load errors.
559568 // NOTE: If Vite adds direct support for externals, this can be removed.
560- preTransformRequests : externalMetadata . explicit . length === 0 ,
569+ preTransformRequests : externalMetadata . explicitBrowser . length === 0 ,
561570 } ,
562571 ssr : {
563572 // Note: `true` and `/.*/` have different sematics. When true, the `external` option is ignored.
564573 noExternal : / .* / ,
565574 // Exclude any Node.js built in module and provided dependencies (currently build defined externals)
566- external : externalMetadata . explicit ,
575+ external : externalMetadata . explicitServer ,
567576 optimizeDeps : getDepOptimizationConfig ( {
568577 // Only enable with caching since it causes prebundle dependencies to be cached
569578 disabled : serverOptions . prebundle === false ,
570579 // Exclude any explicitly defined dependencies (currently build defined externals and node.js built-ins)
571- exclude : externalMetadata . explicit ,
580+ exclude : externalMetadata . explicitServer ,
572581 // Include all implict dependencies from the external packages internal option
573582 include : externalMetadata . implicitServer ,
574583 ssr : true ,
@@ -587,19 +596,19 @@ export async function setupServer(
587596 outputFiles,
588597 assets,
589598 ssr,
590- external : externalMetadata . explicit ,
599+ external : externalMetadata . explicitBrowser ,
591600 indexHtmlTransformer,
592601 extensionMiddleware,
593602 normalizePath,
594603 } ) ,
595- createRemoveIdPrefixPlugin ( externalMetadata . explicit ) ,
604+ createRemoveIdPrefixPlugin ( externalMetadata . explicitBrowser ) ,
596605 ] ,
597606 // Browser only optimizeDeps. (This does not run for SSR dependencies).
598607 optimizeDeps : getDepOptimizationConfig ( {
599608 // Only enable with caching since it causes prebundle dependencies to be cached
600609 disabled : serverOptions . prebundle === false ,
601610 // Exclude any explicitly defined dependencies (currently build defined externals)
602- exclude : externalMetadata . explicit ,
611+ exclude : externalMetadata . explicitBrowser ,
603612 // Include all implict dependencies from the external packages internal option
604613 include : externalMetadata . implicitBrowser ,
605614 ssr : false ,
0 commit comments