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

Preset ipxStatic does not inherit ipx's providerOptions #1676

Open
IO-Fire opened this issue Jan 15, 2025 · 2 comments
Open

Preset ipxStatic does not inherit ipx's providerOptions #1676

IO-Fire opened this issue Jan 15, 2025 · 2 comments

Comments

@IO-Fire
Copy link

IO-Fire commented Jan 15, 2025

When static sites are generated, the configuration of the ipx provider is not used when building the site with SSG. This can cause different results and confusion between development and production using a nitro preset of static e.g. cloudflare_pages_static.

Using a static preset sets the provider to ipxStatic:

image/src/module.ts

Lines 138 to 139 in 5e90a19

const resolvedProvider = nitro.options.static || options.provider === 'ipxStatic'
? 'ipxStatic'

Therefore, the preset configuration of ipx is not applied here:

image/src/ipx.ts

Lines 39 to 54 in cef2f82

const ipxOptions: IPXRuntimeConfig = {
...providerOptions.options,
baseURL: ipxBaseURL,
alias: {
...moduleOptions.alias,
...providerOptions.options?.alias,
},
fs: (providerOptions.options?.fs !== false) && {
dir: nuxt.options.dev ? publicDirs : relativeDir,
...providerOptions.options?.fs,
},
http: (providerOptions.options?.http !== false) && {
domains: moduleOptions.domains,
...providerOptions.options?.http,
},
}

Example

Using the Nuxt config of:

// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
  
  image: {
    domains: ['https://blog.domain.tld'],
    ipx: {
      http: {
        fetchOptions: {
          headers: { "X-API-KEY": process.env.BLOG_IMG_API_KEY! },
        },
      },
    },
  },
  
});

Using SSG at build time results in providerOptions.options = {} as no ipxStatic preset options exist in the above nuxt.config.ts for:

...providerOptions.options?.http,

While this can be resolved by using duplicating the Nuxt configuration for the ipx provider into an ipxStatic provider, this may not be obvious to users.

// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
  
  image: {
    domains: ['https://blog.domain.tld'],
    ipx: {
      http: {
        fetchOptions: {
          headers: { "X-API-KEY": process.env.BLOG_IMG_API_KEY! },
        },
      },
    },
    ipxStatic: {
      http: {
        fetchOptions: {
          headers: { "X-API-KEY": process.env.BLOG_IMG_API_KEY! },
        },
      },
    },
  },
  
});

Suggested Solutions

One

Remove the ipxStatic preset and update the logic to signal that the build is static another way.

Two

Update the preset logic on ipxStatic to first import the ipx preset options and runtime options then override with any ipxStatic options.

Three

Update https://image.nuxt.com/advanced/static-images to warn that the ipxStatic preset is not the same as ipx and that the ipxStatic preset options should be set to mirror ipx.

Four

Warn at build time that the ipxStatic preset is being used instead of ipx and that the ipxStatic preset options should be set to mirror ipx.

Copy link
Member

I think ipxStatic provider options should inherit from ipx.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants