nuxt / nuxt/image

Generating WebP images with nuxt-picture not working for static generated site (ssr:true,target:static)

Open
#442 4 comments 7 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

v0
Dominant language
TypeScript
Stars
1.5k
Forks
331
Avg merge
19h 52m
Merged PRs (30d)
9

Description

Nuxt version: 2.15.8
@nuxt/image version: 0.5.0
target: 'static',
ssr: true,
buildModules: [
['@nuxt/image'],
],
image: {
provider: 'static',
},

Using nuxt-picture with WebP type works in the dev mode. It generates images via _ipx. Here's a sample code from the dev mode that works:

This code (in dev mode)

  nuxt-picture.image.image-desktop(
    format="webp"
    quality="80"
    src="/images/xyz-header-large.jpg"
    sizes="mobile:100vw tablet:100vw desktop:100vw widescreen:100vw fullhd:100vw"
  )

will generate this code, which uses WebP images (in dev mode)

<source type="image/webp" srcset="/_ipx/images/xyz-header-large.jpg?w=768&amp;f=webp&amp;q=80 768w, /_ipx/images/xyz-header-large.jpg?w=769&amp;f=webp&amp;q=80 769w, /_ipx/images/xyz-header-large.jpg?w=1024&amp;f=webp&amp;q=80 1024w, /_ipx/images/xyz-header-large.jpg?w=1216&amp;f=webp&amp;q=80 1216w, /_ipx/images/xyz-header-large.jpg?w=1408&amp;f=webp&amp;q=80 1408w" sizes="(max-width: 768px) 100vw, (max-width: 769px) 100vw, (max-width: 1024px) 100vw, (max-width: 1216px) 100vw, 100vw">

However, when trying to generate a static site using yarn generate, the console output indicates that WebP images were created and indeed I can find them in _nuxt/image/ folder. But the generated static code does not link to WebP images, but uses the original "jpg" or "png" images instead.

Any help on this would be greatly appreciated.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Nuxt 2.15.8 configuration shown in the issue and run yarn generate using target: 'static', ssr: true, and the static image provider. Compare the generated static markup with the WebP files in _nuxt/image/. Done means nuxt-picture output references the generated WebP images instead of the original JPG or PNG files.

Written by the indexing model from the issue text.

Assessment

Tech stack
nuxt, typescript
Domain
web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.