-
Notifications
You must be signed in to change notification settings - Fork 287
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
Images inside <template [tag]> are not generated during nuxt generate, but work in development mode #1608
Comments
Did you manage to solve the issue? |
no ( |
Note Please see here for a better solution I wrote a utility to manually collect all possible images: interface ImageOptions {
width: number
height: number
sizes?: string
}
export function ensureGenImages(urls: string[], opts?: ImageOptions) {
if (!import.meta.server)
return
const img = useImage()
const { width, height, sizes } = opts || {}
urls.forEach((url) => {
if (opts) {
const srcset = img.getSizes(url, { modifiers: { width, height }, sizes })
// we don't need this in deed, see another comment below
extractUrls(srcset.srcset).forEach((url) => {
$fetch(url)
})
}
else {
// we don't need the `$fetch` call in deed, see another comment below
$fetch(img(url))
}
})
}
function extractUrls(srcset: string) {
return srcset.split(',').map(s => s.trim().split(' ')[0])
} The The not graceful place is that you need to extract the And you need to call this utility function at somewhere always render. |
It's already a solution, thanks for sharing. |
I found that practically the interface ImageOptions {
width: number
height: number
sizes?: string
}
export function ensureGenImages(urls: string[], opts?: ImageOptions) {
if (!import.meta.server || !import.meta.prerender)
return
const img = useImage()
const { width, height, sizes } = opts || {}
urls.forEach((url) => {
if (opts) {
img.getSizes(url, { modifiers: { width, height }, sizes })
}
else {
img(url)
}
})
} |
It's already a solution, thanks for sharing. |
I have encountered a problem with the @nuxt/image module when using it inside a
<template>
tag. Images are not generated correctly when running nuxt generate, although they work fine in development mode ( nuxt dev ).When running
nuxt dev
- the image will be displayed correctly.When I run
nuxt generate
and try to open the page, the image is not generated and the browser shows a 404 error http://localhost:3000/_ipx/f_webp/img/example.webp<template #panel>
Expected behavior: The image should be generated and available during static generation, similar to how it works in development mode.
The image is not generated during static site generation and the page shows a 404 error when trying to load the image. However, the image works fine when running nuxt dev.
package.json
Additional information:
This issue seems to be related specifically to the use of NuxtImg inside a tag with a named slot ( #panel in this case).
The images work fine in development mode, but are not generated during static build.
I have verified that the images are correctly placed.
When I remove the slot ( without #panel), the image is generated correctly during static build. But adding #panel or any other gives an error.
The text was updated successfully, but these errors were encountered: