Build-time images
Resize project-local PNG/JPEG files into WebP variants during swelte build. A
host-side V tool uses stbi and libwebp; the production server needs neither the tool
nor the codec library.
libwebp-dev on Debian/Ubuntu, or webp on Homebrew. Cross-compiling the server still processes
images on the host.Configure variants
export default {
swelte: {
images: [{ src: 'assets/hero.png', widths: [320, 640, 1280], quality: 80 }]
}
}Sources must resolve inside the project, including after following symlinks. Widths are integers from 1 to 8192, at most 20 per source. Quality is 1–100 (default 80), and sources are limited to 64 million pixels. Variants preserve aspect ratio, never upscale and keep PNG alpha. Repeated effective widths collapse into one output.
Use generated metadata
<script>
import images from '#app/images'
const variants = images['assets/hero.png']
const largest = variants[variants.length - 1]
</script>
<img src={largest.src}
srcset={variants.map(image => `${image.src} ${image.width}w`).join(', ')}
width={largest.width} height={largest.height} alt="Mountain sunrise" />#app/images exports an object keyed by the configured source path. Each value is an array of src, width, height and format: 'webp' objects, ordered by ascending width. URLs include swelte.base. The same module
resolves in client and SSR builds; with no configured images it exports an empty object.
Outputs and limits
dist/images/<input-and-options-hash>-<width>.webpcontains the variants.dist/images/manifest.jsonpublishes the metadata. Only referenced variants are copied into the build.- Originals are not copied by this pipeline. Generated metadata and intermediate assets live under
outDir. - Processing runs during
swelte build; dev can use metadata from the last build. - Metadata is stripped and EXIF orientation is not applied. Use sources whose pixels already have the intended orientation.
- Decode, resize or encode failures fail the build.