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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@kingkongdevs/vite-plugin-image-sizes

v1.0.12

Published

Plugin for Vite that compresses and generates alternate sizes for images, and rewrites HTML with the corresponding <picture> tags.

Downloads

70

Readme

Vite Plugin Image Sizes

What it does

Compresses - Generates the Webp or AVIF version of your images using the Sharp library.

Generates - Takes the original image and generates resized versions for common breakpoints like mobile, tablet, desktop etc. Images are only generated on build, during development watch mode the original images are used contained within <picture> tags.

Renames with semantic HTML - No need to write out file paths for your project, just use the image name and type, and this plugin will take care of the rest <img src="image-name.jpg">. Also takes care of adding all srcset image references. If your image doens't have an alt attribute, it will add it, along with the natural image height and width. Falls back to the original image for browsers without <picture> and <source> tag support.

Lazyloading - Adds the lazyload class to all images.

Usage

Import viteImageSizes from @kingkongdevs/vite-plugin-image-sizes

import viteImageSizes from @kingkongdevs/vite-plugin-image-sizes'

Add the viteImageSizes to your vite.config.js file's plugins array:

plugins: [
  viteImageSizes({
    outputDir: 'dist/assets/images',
    imgInputDir: 'src/assets/images'
  }),
]

Plugin Options

outputDir

  • Type: string

  • Default: 'dist/assets/images'

    The directory where the optimized images will be output.

imgInputDir

  • Type: string

  • Default: 'src/assets/images'

    The directory containing the original images. This is where the plugin will look to process the images from.

sizes

  • Type: array

  • Default: [320, 640, 1024]

    An array of numbers used to generate resized versions of the images. These will be used to generate the srcset values.

Examples

HTML:

<img src="placeholder.png">

Dev Output:

<picture>
  <img data-src="assets/images/placeholder.png" alt="" width="1900" height="1200" class="lazyload">
</picture>

Build Output:

<picture>
  <source data-srcset="/assets/images/placeholder-320px.webp 320w, /assets/images/placeholder-640px.webp 640w, /assets/images/placeholder-1024px.webp 1024w" type="image/webp" />
  <img data-src="assets/images/placeholder.png" alt="" width="1900" height="1200" class="lazyload" />
</picture>