@@ -40,6 +40,11 @@ interface OutputFileRecord {
40
40
servable : boolean ;
41
41
}
42
42
43
+ interface DevServerExternalResultMetadata extends Omit < ExternalResultMetadata , 'explicit' > {
44
+ explicitBrowser : string [ ] ;
45
+ explicitServer : string [ ] ;
46
+ }
47
+
43
48
export type BuilderAction = (
44
49
options : ApplicationBuilderInternalOptions ,
45
50
context : BuilderContext ,
@@ -138,10 +143,11 @@ export async function* serveWithVite(
138
143
let hadError = false ;
139
144
const generatedFiles = new Map < string , OutputFileRecord > ( ) ;
140
145
const assetFiles = new Map < string , string > ( ) ;
141
- const externalMetadata : ExternalResultMetadata = {
146
+ const externalMetadata : DevServerExternalResultMetadata = {
142
147
implicitBrowser : [ ] ,
143
148
implicitServer : [ ] ,
144
- explicit : [ ] ,
149
+ explicitBrowser : [ ] ,
150
+ explicitServer : [ ] ,
145
151
} ;
146
152
147
153
// Add cleanup logic via a builder teardown.
@@ -234,17 +240,20 @@ export async function* serveWithVite(
234
240
}
235
241
236
242
// 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 ;
238
245
externalMetadata . implicitServer . length = 0 ;
239
246
externalMetadata . implicitBrowser . length = 0 ;
240
247
241
- externalMetadata . explicit . push ( ...explicit ) ;
248
+ externalMetadata . explicitBrowser . push ( ...explicit ) ;
249
+ externalMetadata . explicitServer . push ( ...explicit , ...nodeJsBuiltinModules ) ;
242
250
externalMetadata . implicitServer . push ( ...implicitServerFiltered ) ;
243
251
externalMetadata . implicitBrowser . push ( ...implicitBrowserFiltered ) ;
244
252
245
253
// The below needs to be sorted as Vite uses these options are part of the hashing invalidation algorithm.
246
254
// 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 ( ) ;
248
257
externalMetadata . implicitServer . sort ( ) ;
249
258
externalMetadata . implicitBrowser . sort ( ) ;
250
259
}
@@ -478,7 +487,7 @@ export async function setupServer(
478
487
outputFiles : Map < string , OutputFileRecord > ,
479
488
assets : Map < string , string > ,
480
489
preserveSymlinks : boolean | undefined ,
481
- externalMetadata : ExternalResultMetadata ,
490
+ externalMetadata : DevServerExternalResultMetadata ,
482
491
ssr : boolean ,
483
492
prebundleTransformer : JavaScriptTransformer ,
484
493
target : string [ ] ,
@@ -557,18 +566,18 @@ export async function setupServer(
557
566
} ,
558
567
// This is needed when `externalDependencies` is used to prevent Vite load errors.
559
568
// NOTE: If Vite adds direct support for externals, this can be removed.
560
- preTransformRequests : externalMetadata . explicit . length === 0 ,
569
+ preTransformRequests : externalMetadata . explicitBrowser . length === 0 ,
561
570
} ,
562
571
ssr : {
563
572
// Note: `true` and `/.*/` have different sematics. When true, the `external` option is ignored.
564
573
noExternal : / .* / ,
565
574
// Exclude any Node.js built in module and provided dependencies (currently build defined externals)
566
- external : externalMetadata . explicit ,
575
+ external : externalMetadata . explicitServer ,
567
576
optimizeDeps : getDepOptimizationConfig ( {
568
577
// Only enable with caching since it causes prebundle dependencies to be cached
569
578
disabled : serverOptions . prebundle === false ,
570
579
// Exclude any explicitly defined dependencies (currently build defined externals and node.js built-ins)
571
- exclude : externalMetadata . explicit ,
580
+ exclude : externalMetadata . explicitServer ,
572
581
// Include all implict dependencies from the external packages internal option
573
582
include : externalMetadata . implicitServer ,
574
583
ssr : true ,
@@ -587,19 +596,19 @@ export async function setupServer(
587
596
outputFiles,
588
597
assets,
589
598
ssr,
590
- external : externalMetadata . explicit ,
599
+ external : externalMetadata . explicitBrowser ,
591
600
indexHtmlTransformer,
592
601
extensionMiddleware,
593
602
normalizePath,
594
603
} ) ,
595
- createRemoveIdPrefixPlugin ( externalMetadata . explicit ) ,
604
+ createRemoveIdPrefixPlugin ( externalMetadata . explicitBrowser ) ,
596
605
] ,
597
606
// Browser only optimizeDeps. (This does not run for SSR dependencies).
598
607
optimizeDeps : getDepOptimizationConfig ( {
599
608
// Only enable with caching since it causes prebundle dependencies to be cached
600
609
disabled : serverOptions . prebundle === false ,
601
610
// Exclude any explicitly defined dependencies (currently build defined externals)
602
- exclude : externalMetadata . explicit ,
611
+ exclude : externalMetadata . explicitBrowser ,
603
612
// Include all implict dependencies from the external packages internal option
604
613
include : externalMetadata . implicitBrowser ,
605
614
ssr : false ,
0 commit comments