diff --git a/docs/content/3.providers/vercel.md b/docs/content/3.providers/vercel.md index dee9e38ff..a54f0e551 100644 --- a/docs/content/3.providers/vercel.md +++ b/docs/content/3.providers/vercel.md @@ -12,6 +12,10 @@ When deploying your nuxt applications to [Vercel](https://vercel.com/) platform, This provider will be enabled by default in vercel deployments. +::callout{icon="i-heroicons-exclamation-triangle" color="amber"} +Vercel requires you to explicitly list all the widths used in your app. [See example below.](#sizes) +:: + ## Domains To use external URLs (images not in `public/` directory), hostnames should be whitelisted. @@ -30,19 +34,33 @@ export default { ## Sizes -Specify any custom `width` property you use in ``, `` and `$img`. +You need to specify **every custom width** used in ``, `` or `$img` for vercel to resize them properly. [Source.](https://vercel.com/docs/build-output-api/v3/configuration#api) If a width is not defined, image will fallback to the next bigger width. +::callout{icon="i-heroicons-light-bulb"} +Don't forget to also take into account [`densities`](/get-started/configuration#densities). +:: + **Example:** -```ts [nuxt.config] -export default { - image: { - screens: { - icon: 40, - avatar: 24 +::code-group + + ```html [index.vue] + + ``` + + ```ts [nuxt.config] + export default { + image: { + screens: { + icon: 40, + icon2x: 80 + } } } -} -``` + ``` + +:: diff --git a/src/provider.ts b/src/provider.ts index 83e19b3f4..05c8f0ad4 100644 --- a/src/provider.ts +++ b/src/provider.ts @@ -56,7 +56,7 @@ export const providerSetup: Partial> = ipx: ipxSetup(), ipxStatic: ipxSetup({ isStatic: true }), - // https://vercel.com/docs/more/adding-your-framework#images + // https://vercel.com/docs/build-output-api/v3/configuration#images vercel(_providerOptions, moduleOptions, nuxt: Nuxt) { nuxt.options.nitro = defu(nuxt.options.nitro, { vercel: { @@ -65,6 +65,7 @@ export const providerSetup: Partial> = domains: moduleOptions.domains, minimumCacheTTL: 60 * 5, sizes: Array.from(new Set(Object.values(moduleOptions.screens || {}))), + formats: ['image/webp', 'image/avif'], }, }, } satisfies NitroConfig['vercel'], diff --git a/src/runtime/providers/vercel.ts b/src/runtime/providers/vercel.ts index dc0feb7aa..ec55626f5 100644 --- a/src/runtime/providers/vercel.ts +++ b/src/runtime/providers/vercel.ts @@ -1,7 +1,7 @@ import { stringifyQuery } from 'ufo' import type { ProviderGetImage } from '../../module' -// https://vercel.com/docs/more/adding-your-framework#images +// https://vercel.com/docs/build-output-api/v3/configuration#images export const getImage: ProviderGetImage = (src, { modifiers, baseURL = '/_vercel/image' } = {}, ctx) => { const validWidths = Object.values(ctx.options.screens || {}).sort((a, b) => a - b)