@@ -42,6 +42,11 @@ interface OutputFileRecord {
42
42
type : BuildOutputFileType ;
43
43
}
44
44
45
+ interface DevServerExternalResultMetadata extends Omit < ExternalResultMetadata , 'explicit' > {
46
+ explicitBrowser : string [ ] ;
47
+ explicitServer : string [ ] ;
48
+ }
49
+
45
50
export type BuilderAction = (
46
51
options : ApplicationBuilderInternalOptions ,
47
52
context : BuilderContext ,
@@ -140,10 +145,11 @@ export async function* serveWithVite(
140
145
let hadError = false ;
141
146
const generatedFiles = new Map < string , OutputFileRecord > ( ) ;
142
147
const assetFiles = new Map < string , string > ( ) ;
143
- const externalMetadata : ExternalResultMetadata = {
148
+ const externalMetadata : DevServerExternalResultMetadata = {
144
149
implicitBrowser : [ ] ,
145
150
implicitServer : [ ] ,
146
- explicit : [ ] ,
151
+ explicitBrowser : [ ] ,
152
+ explicitServer : [ ] ,
147
153
} ;
148
154
149
155
// Add cleanup logic via a builder teardown.
@@ -236,17 +242,20 @@ export async function* serveWithVite(
236
242
}
237
243
238
244
// 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 ;
240
247
externalMetadata . implicitServer . length = 0 ;
241
248
externalMetadata . implicitBrowser . length = 0 ;
242
249
243
- externalMetadata . explicit . push ( ...explicit ) ;
250
+ externalMetadata . explicitBrowser . push ( ...explicit ) ;
251
+ externalMetadata . explicitServer . push ( ...explicit , ...nodeJsBuiltinModules ) ;
244
252
externalMetadata . implicitServer . push ( ...implicitServerFiltered ) ;
245
253
externalMetadata . implicitBrowser . push ( ...implicitBrowserFiltered ) ;
246
254
247
255
// The below needs to be sorted as Vite uses these options are part of the hashing invalidation algorithm.
248
256
// 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 ( ) ;
250
259
externalMetadata . implicitServer . sort ( ) ;
251
260
externalMetadata . implicitBrowser . sort ( ) ;
252
261
}
@@ -494,7 +503,7 @@ export async function setupServer(
494
503
outputFiles : Map < string , OutputFileRecord > ,
495
504
assets : Map < string , string > ,
496
505
preserveSymlinks : boolean | undefined ,
497
- externalMetadata : ExternalResultMetadata ,
506
+ externalMetadata : DevServerExternalResultMetadata ,
498
507
ssr : boolean ,
499
508
prebundleTransformer : JavaScriptTransformer ,
500
509
target : string [ ] ,
@@ -573,18 +582,18 @@ export async function setupServer(
573
582
} ,
574
583
// This is needed when `externalDependencies` is used to prevent Vite load errors.
575
584
// NOTE: If Vite adds direct support for externals, this can be removed.
576
- preTransformRequests : externalMetadata . explicit . length === 0 ,
585
+ preTransformRequests : externalMetadata . explicitBrowser . length === 0 ,
577
586
} ,
578
587
ssr : {
579
588
// Note: `true` and `/.*/` have different sematics. When true, the `external` option is ignored.
580
589
noExternal : / .* / ,
581
590
// Exclude any Node.js built in module and provided dependencies (currently build defined externals)
582
- external : externalMetadata . explicit ,
591
+ external : externalMetadata . explicitServer ,
583
592
optimizeDeps : getDepOptimizationConfig ( {
584
593
// Only enable with caching since it causes prebundle dependencies to be cached
585
594
disabled : serverOptions . prebundle === false ,
586
595
// Exclude any explicitly defined dependencies (currently build defined externals and node.js built-ins)
587
- exclude : externalMetadata . explicit ,
596
+ exclude : externalMetadata . explicitServer ,
588
597
// Include all implict dependencies from the external packages internal option
589
598
include : externalMetadata . implicitServer ,
590
599
ssr : true ,
@@ -603,19 +612,19 @@ export async function setupServer(
603
612
outputFiles,
604
613
assets,
605
614
ssr,
606
- external : externalMetadata . explicit ,
615
+ external : externalMetadata . explicitBrowser ,
607
616
indexHtmlTransformer,
608
617
extensionMiddleware,
609
618
normalizePath,
610
619
} ) ,
611
- createRemoveIdPrefixPlugin ( externalMetadata . explicit ) ,
620
+ createRemoveIdPrefixPlugin ( externalMetadata . explicitBrowser ) ,
612
621
] ,
613
622
// Browser only optimizeDeps. (This does not run for SSR dependencies).
614
623
optimizeDeps : getDepOptimizationConfig ( {
615
624
// Only enable with caching since it causes prebundle dependencies to be cached
616
625
disabled : serverOptions . prebundle === false ,
617
626
// Exclude any explicitly defined dependencies (currently build defined externals)
618
- exclude : externalMetadata . explicit ,
627
+ exclude : externalMetadata . explicitBrowser ,
619
628
// Include all implict dependencies from the external packages internal option
620
629
include : externalMetadata . implicitBrowser ,
621
630
ssr : false ,
0 commit comments