@@ -753,7 +753,7 @@ export function tryNodeResolve(
753753 const resolveId = deepMatch ? resolveDeepImport : resolvePackageEntry
754754 const unresolvedId = deepMatch ? '.' + id . slice ( pkgId . length ) : id
755755
756- let resolved = resolveId ( unresolvedId , pkg , options )
756+ let resolved = resolveId ( unresolvedId , pkg , options , externalize )
757757 if ( ! resolved ) {
758758 return
759759 }
@@ -893,6 +893,7 @@ export function resolvePackageEntry(
893893 id : string ,
894894 { dir, data, setResolvedCache, getResolvedCache } : PackageData ,
895895 options : InternalResolveOptions ,
896+ externalize ?: boolean ,
896897) : string | undefined {
897898 const { file : idWithoutPostfix , postfix } = splitFileAndPostfix ( id )
898899
@@ -907,7 +908,13 @@ export function resolvePackageEntry(
907908 // resolve exports field with highest priority
908909 // using https://github.com/lukeed/resolve.exports
909910 if ( data . exports ) {
910- entryPoint = resolveExportsOrImports ( data , '.' , options , 'exports' )
911+ entryPoint = resolveExportsOrImports (
912+ data ,
913+ '.' ,
914+ options ,
915+ 'exports' ,
916+ externalize ,
917+ )
911918 }
912919
913920 // fallback to mainFields if still not resolved
@@ -987,8 +994,12 @@ function resolveExportsOrImports(
987994 key : string ,
988995 options : InternalResolveOptions ,
989996 type : 'imports' | 'exports' ,
997+ externalize ?: boolean ,
990998) {
991- const conditions = options . conditions . map ( ( condition ) => {
999+ const rawConditions = externalize
1000+ ? options . externalConditions
1001+ : options . conditions
1002+ const conditions = rawConditions . map ( ( condition ) => {
9921003 if ( condition === DEV_PROD_CONDITION ) {
9931004 return options . isProduction ? 'production' : 'development'
9941005 }
@@ -1010,6 +1021,7 @@ function resolveDeepImport(
10101021 id : string ,
10111022 { setResolvedCache, getResolvedCache, dir, data } : PackageData ,
10121023 options : InternalResolveOptions ,
1024+ externalize ?: boolean ,
10131025) : string | undefined {
10141026 const cache = getResolvedCache ( id , options )
10151027 if ( cache ) {
@@ -1024,7 +1036,13 @@ function resolveDeepImport(
10241036 if ( isObject ( exportsField ) && ! Array . isArray ( exportsField ) ) {
10251037 // resolve without postfix (see #7098)
10261038 const { file, postfix } = splitFileAndPostfix ( relativeId )
1027- const exportsId = resolveExportsOrImports ( data , file , options , 'exports' )
1039+ const exportsId = resolveExportsOrImports (
1040+ data ,
1041+ file ,
1042+ options ,
1043+ 'exports' ,
1044+ externalize ,
1045+ )
10281046 if ( exportsId !== undefined ) {
10291047 relativeId = exportsId + postfix
10301048 } else {
0 commit comments