N
Nuxt2w ago
kb

NuxtImg + Vercel

Im using NuxtImg on Vercel, but I cannot figure out what I need to put in the nuxt.config.js because the docs say im supposed to supply every custom width? (https://image.nuxt.com/providers/vercel) I am running vuetify, and tailwind, if this helps. But as far as sizes, in the given component, im rendering out a few images, with unique sizes per, where im passing this; into my NuxtImg, sizes (in a loop)
[
{
"src": "/home-bg/home-bg-top-1.webp",
"class": "home-bg-top-1",
"sizes": "xs:56px sm:104px md:88px lg:120px xl:136px",
"key": "home-bg-top-1"
},
{
"src": "/home-bg/home-bg-top-2.webp",
"class": "home-bg-top-2",
"sizes": "xs:66px sm:114px md:98px lg:130px xl:146px",
"key": "home-bg-top-2"
},
{
"src": "/home-bg/home-bg-top-3.webp",
"class": "home-bg-top-3",
"sizes": "xs:130px sm:146px md:146px lg:226px xl:226px",
"key": "home-bg-top-3"
},
{
"src": "/home-bg/home-bg-top-4.webp",
"class": "home-bg-top-4",
"sizes": "xs:62px sm:78px md:94px lg:110px xl:126px",
"key": "home-bg-top-4"
},
{
"src": "/home-bg/home-bg-bottom-1.webp",
"class": "home-bg-bottom-1",
"sizes": "xs:100px sm:164px md:148px lg:225px xl:180px",
"key": "home-bg-bottom-1"
},
{
"src": "/home-bg/home-bg-bottom-2.webp",
"class": "home-bg-bottom-2",
"sizes": "xs:70px sm:94px md:94px lg:110px xl:110px",
"key": "home-bg-bottom-2"
},
{
"src": "/home-bg/home-bg-bottom-3.webp",
"class": "home-bg-bottom-3",
"sizes": "xs:131px sm:179px md:163px lg:179px xl:227px",
"key": "home-bg-bottom-3"
}
]
[
{
"src": "/home-bg/home-bg-top-1.webp",
"class": "home-bg-top-1",
"sizes": "xs:56px sm:104px md:88px lg:120px xl:136px",
"key": "home-bg-top-1"
},
{
"src": "/home-bg/home-bg-top-2.webp",
"class": "home-bg-top-2",
"sizes": "xs:66px sm:114px md:98px lg:130px xl:146px",
"key": "home-bg-top-2"
},
{
"src": "/home-bg/home-bg-top-3.webp",
"class": "home-bg-top-3",
"sizes": "xs:130px sm:146px md:146px lg:226px xl:226px",
"key": "home-bg-top-3"
},
{
"src": "/home-bg/home-bg-top-4.webp",
"class": "home-bg-top-4",
"sizes": "xs:62px sm:78px md:94px lg:110px xl:126px",
"key": "home-bg-top-4"
},
{
"src": "/home-bg/home-bg-bottom-1.webp",
"class": "home-bg-bottom-1",
"sizes": "xs:100px sm:164px md:148px lg:225px xl:180px",
"key": "home-bg-bottom-1"
},
{
"src": "/home-bg/home-bg-bottom-2.webp",
"class": "home-bg-bottom-2",
"sizes": "xs:70px sm:94px md:94px lg:110px xl:110px",
"key": "home-bg-bottom-2"
},
{
"src": "/home-bg/home-bg-bottom-3.webp",
"class": "home-bg-bottom-3",
"sizes": "xs:131px sm:179px md:163px lg:179px xl:227px",
"key": "home-bg-bottom-3"
}
]
So what exactly does my nuxt config want me to put, for it to work on vercel? thx!!
Nuxt Image
Vercel - Nuxt Image Providers
Optimize images at Vercel's Edge Network.
7 Replies
kapa.ai
kapa.ai2w ago
Hi @kb. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- To use NuxtImg with Vercel, you need to specify all the custom widths used in your application in the nuxt.config.js file. Based on the information you provided and the Vercel provider documentation for Nuxt Image, here's what you should add to your nuxt.config.js:
export default defineNuxtConfig({
image: {
vercel: {
sizes: [56, 62, 66, 70, 78, 88, 94, 98, 100, 104, 110, 114, 120, 126, 130, 131, 136, 146, 148, 163, 164, 179, 180, 225, 226, 227]
}
}
})
export default defineNuxtConfig({
image: {
vercel: {
sizes: [56, 62, 66, 70, 78, 88, 94, 98, 100, 104, 110, 114, 120, 126, 130, 131, 136, 146, 148, 163, 164, 179, 180, 225, 226, 227]
}
}
})
This configuration includes all the unique width values from the sizes properties in your image data. Here's why this is necessary: 1. Vercel requires you to explicitly list all the widths used in your app for proper image resizing as mentioned in the Vercel provider documentation (https://image.nuxt.com/providers/vercel#sizes). 2. The sizes you've provided use the format xs:56px sm:104px md:88px lg:120px xl:136px, which corresponds to different screen sizes. Vercel needs the actual pixel values. 3. I've extracted all unique pixel values from your sizes data and included them in the sizes array. 4. This configuration tells Vercel which image widths to prepare, ensuring that all your responsive image sizes are properly handled. Remember that if you use any other custom widths elsewhere in your application, you should add those to this array as well. Also, keep in mind that Vercel will use the next larger width if an exact match isn't found in this list. So, you might be able to optimize this list by removing some values if you're comfortable with slight rounding up of image sizes. Lastly, ensure that your images are placed in the public/ directory of your Nuxt project, as that's where the default provider expects to find them according to the documentation (https://image.nuxt.com/get-started/providers#local-images). With this configuration, your NuxtImg components should work correctly when deployed to Vercel. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai2w ago
<@310160452221140996> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
kb
kbOP2w ago
my images are in public/home-bg/ is that ok @kapa.ai
kapa.ai
kapa.ai2w ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- Yes, placing your images in the public/home-bg/ directory is perfectly fine. The public/ directory in Nuxt is used to serve static assets, and any subdirectory within it will work as expected. According to the Nuxt documentation on the public directory (https://nuxt.com/docs/guide/directory-structure/public), files in the public/ directory are served at the root of your website and are not modified by the build process. This means your images in public/home-bg/ will be accessible and can be used with NuxtImg. For example, if you have an image at public/home-bg/image.webp, you can reference it in your NuxtImg component like this:
<NuxtImg src="/home-bg/image.webp" />
<NuxtImg src="/home-bg/image.webp" />
The path in the src attribute starts with a forward slash because it's relative to the root of your website, not the public directory itself. This approach is consistent with how you're already referencing your images in the data you provided earlier, where you have paths like /home-bg/home-bg-top-1.webp. These paths correctly point to the images in your public/home-bg/ directory. So, to answer your question directly: yes, having your images in public/home-bg/ is perfectly okay and will work well with NuxtImg and Vercel deployment. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai2w ago
<@310160452221140996> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
kb
kbOP2w ago
it did not work. I have this deploying to a non vercel environment too, which works as expected. here is the smallest one at 66px and then the same one on vercel simply doing the opposite
No description
No description
kb
kbOP2w ago
every doc says something different. this cannot be what i need to do surely
image: {
screens: {
56: 56,
66: 66,
70: 70,
78: 78,
88: 88,
94: 94,
100: 100,
104: 104,
110: 110,
114: 114,
120: 120,
126: 126,
130: 130,
131: 131,
136: 136,
146: 146,
148: 148,
163: 163,
164: 164,
179: 179,
180: 180,
225: 225,
226: 226,
227: 227,
},
vercel: {
screens: {
56: 56,
66: 66,
70: 70,
78: 78,
88: 88,
94: 94,
100: 100,
104: 104,
110: 110,
114: 114,
120: 120,
126: 126,
130: 130,
131: 131,
136: 136,
146: 146,
148: 148,
163: 163,
164: 164,
179: 179,
180: 180,
225: 225,
226: 226,
227: 227,
},
},
},
image: {
screens: {
56: 56,
66: 66,
70: 70,
78: 78,
88: 88,
94: 94,
100: 100,
104: 104,
110: 110,
114: 114,
120: 120,
126: 126,
130: 130,
131: 131,
136: 136,
146: 146,
148: 148,
163: 163,
164: 164,
179: 179,
180: 180,
225: 225,
226: 226,
227: 227,
},
vercel: {
screens: {
56: 56,
66: 66,
70: 70,
78: 78,
88: 88,
94: 94,
100: 100,
104: 104,
110: 110,
114: 114,
120: 120,
126: 126,
130: 130,
131: 131,
136: 136,
146: 146,
148: 148,
163: 163,
164: 164,
179: 179,
180: 180,
225: 225,
226: 226,
227: 227,
},
},
},
Want results from more Discord servers?
Add your server