diff --git a/src/module.ts b/src/module.ts index 3ff65a943..db0e5d4c7 100644 --- a/src/module.ts +++ b/src/module.ts @@ -66,10 +66,11 @@ export default defineNuxtModule({ // Normalize alias to start with leading slash options.alias = Object.fromEntries(Object.entries(options.alias).map(e => [withLeadingSlash(e[0]), e[1]])) - options.provider = detectProvider(options.provider)! + const _detectedProvider = detectProvider(options.provider)! if (options.provider) { options[options.provider] = options[options.provider] || {} } + options.provider = _detectedProvider?.provider options.densities = options.densities || [] const imageOptions: Omit = pick(options, [ @@ -130,10 +131,10 @@ ${providers.map(p => ` ['${p.name}']: { provider: ${p.importName}, defaults: ${ }) nuxt.hook('nitro:init', async (nitro) => { - if (!options.provider || options.provider === 'ipx' || options.provider === 'ipxStatic') { + if (!options.provider || options.provider === 'ipx' || options.provider === 'ipxStatic' || _detectedProvider?.auto) { const resolvedProvider = nitro.options.static || options.provider === 'ipxStatic' ? 'ipxStatic' - : nitro.options.node ? 'ipx' : 'none' + : _detectedProvider?.provider || (nitro.options.node ? 'ipx' : 'none') imageOptions.provider = options.provider = resolvedProvider options[resolvedProvider] = options[resolvedProvider] || {} diff --git a/src/provider.ts b/src/provider.ts index 7eab191bf..9bff2c034 100644 --- a/src/provider.ts +++ b/src/provider.ts @@ -139,16 +139,24 @@ const autodetectableProviders: Partial> aws_amplify: 'awsAmplify' } -export function detectProvider (userInput: string = '') { +export function detectProvider (userInput: string = ''): undefined | { provider: string; auto: boolean } { if (process.env.NUXT_IMAGE_PROVIDER) { - return process.env.NUXT_IMAGE_PROVIDER + return { + provider: process.env.NUXT_IMAGE_PROVIDER, + auto: false + } } - if (userInput && userInput !== 'auto') { - return userInput + return { + provider: userInput, + auto: false + } } - - if (provider in autodetectableProviders) { - return autodetectableProviders[provider] + const autoDetected = autodetectableProviders[provider] + if (autoDetected) { + return { + provider: autoDetected, + auto: true + } } }