diff --git a/packages/vite/src/node/plugins/resolve.ts b/packages/vite/src/node/plugins/resolve.ts index 34bdcf4a699a55..0d5f4100877dbe 100644 --- a/packages/vite/src/node/plugins/resolve.ts +++ b/packages/vite/src/node/plugins/resolve.ts @@ -670,7 +670,6 @@ function tryResolveRealFileWithExtensions( export type InternalResolveOptionsWithOverrideConditions = InternalResolveOptions & { /** - * @deprecated In future, `conditions` will work like this. * @internal */ overrideConditions?: string[] @@ -1072,8 +1071,6 @@ function packageEntryFailure(id: string, details?: string) { ) } -const conditionalConditions = new Set(['production', 'development', 'module']) - function resolveExportsOrImports( pkg: PackageData['data'], key: string, @@ -1081,43 +1078,31 @@ function resolveExportsOrImports( targetWeb: boolean, type: 'imports' | 'exports', ) { - const overrideConditions = options.overrideConditions - ? new Set(options.overrideConditions) - : undefined + const additionalConditions = new Set( + options.overrideConditions || [ + 'production', + 'development', + 'module', + ...options.conditions, + ], + ) - const conditions = [] - if ( - (!overrideConditions || overrideConditions.has('production')) && - options.isProduction - ) { - conditions.push('production') - } - if ( - (!overrideConditions || overrideConditions.has('development')) && - !options.isProduction - ) { - conditions.push('development') - } - if ( - (!overrideConditions || overrideConditions.has('module')) && - !options.isRequire - ) { - conditions.push('module') - } - if (options.overrideConditions) { - conditions.push( - ...options.overrideConditions.filter((condition) => - conditionalConditions.has(condition), - ), - ) - } else if (options.conditions.length > 0) { - conditions.push(...options.conditions) - } + const conditions = [...additionalConditions].filter((condition) => { + switch (condition) { + case 'production': + return options.isProduction + case 'development': + return !options.isProduction + case 'module': + return !options.isRequire + } + return true + }) const fn = type === 'imports' ? imports : exports const result = fn(pkg, key, { - browser: targetWeb && !conditions.includes('node'), - require: options.isRequire && !conditions.includes('import'), + browser: targetWeb && !additionalConditions.has('node'), + require: options.isRequire && !additionalConditions.has('import'), conditions, })