npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

vite-webp-avif-generator-plugin

v2.2.1

Published

Vite plugin for automatic image conversion to WebP and AVIF formats in dev mode

Readme

Vite WebP & AVIF Generator Plugin

Vite plugin for automatic image conversion to WebP and AVIF during dev server runtime.

Features

  • Converts newly added images in watched folders
  • Skips existing targets to avoid extra work
  • Avoids loops on generated .webp and .avif files
  • Runs WebP and AVIF conversions in parallel
  • Supports Vite publicDir when it lives outside Vite root
  • Supports Nuxt setups with srcDir and project-level public/
  • Works in dev only via apply: 'serve'

Installation

npm install -D vite-webp-avif-generator-plugin sharp chokidar

Basic Usage

// vite.config.js
import { defineConfig } from 'vite'
import convertImages from 'vite-webp-avif-generator-plugin'

export default defineConfig({
  plugins: [convertImages()],
})

Nuxt Support

The plugin supports Nuxt projects where Vite root is moved by srcDir, while static assets still live in the project-level public/ directory.

That means you can keep paths like public/img in plugin options without overriding Vite root in development.

Example:

convertImages({
  folders: ['src/assets/img', 'public/img'],
  exclude: ['public/img/generated'],
})

This is especially useful for setups like:

export default defineNuxtConfig({
  srcDir: './src',
})

Options

| Option | Type | Default | Description | | --- | --- | --- | --- | | folders | string[] | ['src/img', 'public/img'] | Folders to watch | | exclude | string[] | [] | Folders to exclude | | enableAvif | boolean | true | Enable AVIF conversion |

Path Resolution

  • Absolute paths are used as-is.
  • Relative paths are resolved from Vite root.
  • Paths that start with the configured public directory name, for example public/img, are resolved from the parent of Vite publicDir.

This keeps the plugin compatible with standard Vite apps and with frameworks such as Nuxt that can shift the effective Vite root.

Supported Formats

Input:

  • .jpg
  • .jpeg
  • .png
  • .webp

Output:

  • .webp when source is not already WebP
  • .avif when enableAvif is true

Behavior

On each new file:

  1. Check supported extension
  2. Check excluded folders
  3. Skip generated .webp and .avif files
  4. Build conversion tasks
  5. Run conversions with Promise.allSettled
  6. Log success and error counts

Existing files are ignored on startup because the watcher uses ignoreInitial: true.

Compatibility

  • Vite 4.x to 8.x
  • Nuxt projects powered by Vite, including srcDir setups
  • Chokidar 3.5.3+ and 4.x
  • Sharp 0.32+, 0.33+, 0.34+

Node runtime depends on the Vite major used in the host project.

For the currently declared package support:

  • Vite 7.x to 8.x: Node 20.19+

If you plan to use older Vite majors, align the project runtime with that Vite version's official Node requirements.

Notes

  • The plugin is intentionally dev-only.
  • The main conversion flow is file-system based and does not transform Vite modules.
  • If you change runtime behavior, update the runtime file, typings, and README together.