Preset `ipxStatic` does not inherit `ipx`'s `providerOptions`
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:
https://github.com/nuxt/image/blob/5e90a19e71ea7440445c246e3fc8b6627bef9bfc/src/module.ts#L138-L139
Therefore, the preset configuration of ipx is not applied here:
https://github.com/nuxt/image/blob/cef2f826d634fe1133167d176cc06cc3550c32ed/src/ipx.ts#L39-L54
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:
https://github.com/nuxt/image/blob/cef2f826d634fe1133167d176cc06cc3550c32ed/src/ipx.ts#L52
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.
Possibly related to:
- #1394
- #1397
I think ipxStatic provider options should inherit from ipx.