Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use ipx for static builds instead of auto detect #1224

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,11 @@ export default defineNuxtModule<ModuleOptions>({
// 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<CreateImageOptions, 'providers' | 'nuxt'> = pick(options, [
Expand Down Expand Up @@ -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] || {}
Expand Down
22 changes: 15 additions & 7 deletions src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,24 @@ const autodetectableProviders: Partial<Record<ProviderName, ImageProviderName>>
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
}
}
}