@@ -765,7 +765,7 @@ export function tryNodeResolve(
765765 const resolveId = deepMatch ? resolveDeepImport : resolvePackageEntry
766766 const unresolvedId = deepMatch ? '.' + id . slice ( pkgId . length ) : id
767767
768- let resolved = resolveId ( unresolvedId , pkg , options )
768+ let resolved = resolveId ( unresolvedId , pkg , options , externalize )
769769 if ( ! resolved ) {
770770 return
771771 }
@@ -905,6 +905,7 @@ export function resolvePackageEntry(
905905 id : string ,
906906 { dir, data, setResolvedCache, getResolvedCache } : PackageData ,
907907 options : InternalResolveOptions ,
908+ externalize ?: boolean ,
908909) : string | undefined {
909910 const { file : idWithoutPostfix , postfix } = splitFileAndPostfix ( id )
910911
@@ -919,7 +920,13 @@ export function resolvePackageEntry(
919920 // resolve exports field with highest priority
920921 // using https://github.com/lukeed/resolve.exports
921922 if ( data . exports ) {
922- entryPoint = resolveExportsOrImports ( data , '.' , options , 'exports' )
923+ entryPoint = resolveExportsOrImports (
924+ data ,
925+ '.' ,
926+ options ,
927+ 'exports' ,
928+ externalize ,
929+ )
923930 }
924931
925932 // fallback to mainFields if still not resolved
@@ -999,8 +1006,12 @@ function resolveExportsOrImports(
9991006 key : string ,
10001007 options : InternalResolveOptions ,
10011008 type : 'imports' | 'exports' ,
1009+ externalize ?: boolean ,
10021010) {
1003- const conditions = options . conditions . map ( ( condition ) => {
1011+ const rawConditions = externalize
1012+ ? options . externalConditions
1013+ : options . conditions
1014+ const conditions = rawConditions . map ( ( condition ) => {
10041015 if ( condition === DEV_PROD_CONDITION ) {
10051016 return options . isProduction ? 'production' : 'development'
10061017 }
@@ -1022,6 +1033,7 @@ function resolveDeepImport(
10221033 id : string ,
10231034 { setResolvedCache, getResolvedCache, dir, data } : PackageData ,
10241035 options : InternalResolveOptions ,
1036+ externalize ?: boolean ,
10251037) : string | undefined {
10261038 const cache = getResolvedCache ( id , options )
10271039 if ( cache ) {
@@ -1036,7 +1048,13 @@ function resolveDeepImport(
10361048 if ( isObject ( exportsField ) && ! Array . isArray ( exportsField ) ) {
10371049 // resolve without postfix (see #7098)
10381050 const { file, postfix } = splitFileAndPostfix ( relativeId )
1039- const exportsId = resolveExportsOrImports ( data , file , options , 'exports' )
1051+ const exportsId = resolveExportsOrImports (
1052+ data ,
1053+ file ,
1054+ options ,
1055+ 'exports' ,
1056+ externalize ,
1057+ )
10401058 if ( exportsId !== undefined ) {
10411059 relativeId = exportsId + postfix
10421060 } else {
0 commit comments