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

vadimages-nextjs-image-optimizer

v1.3.4

Published

Auto image optimization with mobile image support

Downloads

251

Readme

Vadimages Next.js image optimizer

This is a simple image optimizer for Next.js projects. It uses the sharp library to optimize images and the next/image component to display them.

Installation

npm install vadimages-nextjs-image-optimizer

Requirements

  • Node.js 16 or higher
  • Next.js 12 or higher
  • Set meta tag <meta name="viewport" content="width=device-width, initial-scale=1"> in your layout head

Usage

1. Set environment variables

// In your next.config.js file
module.exports = {
    env: {
        vadImage_imagesPath: "public/assets",
        vadImage_buildFolderPath: "build",
        vadImage_quality: "92",
        vadImage_formats: ['webp', 'avif'].join(','),
        vadImage_optimizationDirName: "/opt/",
        vadImage_imagesSizes: [320, 480, 512, 640, 787, 1024, 1280, 1440, 1920].join(','),
        vadImage_pixelRatio: [1, 2, 3].join(','),

        vadImage_enableUpload: "true",
        vadImage_upload_accessKey: "YOUR_CF_ACCESS_KEY",
        vadImage_upload_secretKey: "YOUR_CF_SECRET_KEY",
        vadImage_upload_endpoint: "https://YOUR_CF_ACCOUNT_ID.r2.cloudflarestorage.com",
        vadImage_upload_domain: "https://pub-YOUR_CF_ACCOUNNT_ID.r2.dev/",
        vadImage_upload_bucket: "R2_BUCKET_NAME",
    },
}

| Variable | Description | |--------------------------------|-------------------------------------------------------------------| | vadImage_imagesPath | The path to the images folder in your project. | | vadImage_buildFolderPath | The path to the build folder in your project. | | vadImage_quality | The quality of the optimized images. | | vadImage_formats | The formats of the optimized images. | | vadImage_optimizationDirName | The name of the folder where the optimized images will be stored. | | vadImage_imagesSizes | The sizes of the optimized images. | | vadImage_pixelRatio | The pixel ratios of the optimized images. | | vadImage_enableUpload | Enable or disable image upload to Cloudflare. | | vadImage_upload_accessKey | The access key for the Cloudflare account. | | vadImage_upload_secretKey | The secret key for the Cloudflare account. | | vadImage_upload_endpoint | The endpoint for the Cloudflare account. | | vadImage_upload_domain | The domain for the Cloudflare account. | | vadImage_upload_bucket | The bucket name for the Cloudflare account. |

2. Setup and run images build command

// In your package.json file
{
  "scripts": {
    "build:images": "vadimages-nextjs-image-optimizer --nextConfigPath ./next.config.js"
  }
}
npm run build:images

3. Use the VadImage component

import VadImage from 'vadimages-nextjs-image-optimizer';

export default function Home() {
    return (
        <VadImage
            src="/assets/image.jpg"
            alt="Image"
            width={1920}
            height={1080}
            mobileSrc="/assets/mobile-image.jpg"
            mobileWidth={640}
            mobileHeight={360}
        />
    );
}

The VadImage component has all the same props as the next/image component, plus the following additional props:

| Prop | Description | |----------------|---------------------------------| | mobileSrc | The path to the mobile image. | | mobileWidth | The width of the mobile image. | | mobileHeight | The height of the mobile image. |