@@ -107,26 +107,30 @@ export function shouldExternalizeForSSR(
107
107
108
108
export function createIsConfiguredAsSsrExternal (
109
109
config : ResolvedConfig
110
- ) : ( id : string ) => boolean {
110
+ ) : ( id : string ) => boolean | undefined {
111
111
const { ssr } = config
112
112
const noExternal = ssr ?. noExternal
113
113
const noExternalFilter =
114
114
noExternal !== 'undefined' &&
115
115
typeof noExternal !== 'boolean' &&
116
116
createFilter ( undefined , noExternal , { resolve : false } )
117
117
118
+ // Returns true if it is configured as external, false if it is filtered
119
+ // by noExternal and undefined if it isn't affected by the explicit config
118
120
return ( id : string ) => {
119
121
const { ssr } = config
120
- if ( ! ssr || ssr . external ?. includes ( id ) ) {
121
- return true
122
- }
123
- if ( typeof noExternal === 'boolean' ) {
124
- return ! noExternal
125
- }
126
- if ( noExternalFilter ) {
127
- return noExternalFilter ( id )
122
+ if ( ssr ) {
123
+ if ( ssr . external ?. includes ( id ) ) {
124
+ return true
125
+ }
126
+ if ( typeof noExternal === 'boolean' ) {
127
+ return ! noExternal
128
+ }
129
+ if ( noExternalFilter && ! noExternalFilter ( id ) ) {
130
+ return false
131
+ }
128
132
}
129
- return true
133
+ return undefined
130
134
}
131
135
}
132
136
@@ -165,10 +169,11 @@ function createIsSsrExternal(
165
169
if ( processedIds . has ( id ) ) {
166
170
return processedIds . get ( id )
167
171
}
168
- const external =
169
- ! id . startsWith ( '.' ) &&
170
- ! path . isAbsolute ( id ) &&
171
- ( isBuiltin ( id ) || ( isConfiguredAsExternal ( id ) && isValidPackageEntry ( id ) ) )
172
+ let external = false
173
+ if ( ! id . startsWith ( '.' ) && ! path . isAbsolute ( id ) ) {
174
+ external =
175
+ isBuiltin ( id ) || ( isConfiguredAsExternal ( id ) ?? isValidPackageEntry ( id ) )
176
+ }
172
177
processedIds . set ( id , external )
173
178
return external
174
179
}
0 commit comments