New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

@bro-academy/vite-plugin-image-optimizer

Package Overview
Dependencies
Maintainers
2
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bro-academy/vite-plugin-image-optimizer

Vite plugin to optimize images in HTML and CSS

latest
npmnpm
Version
0.0.2
Version published
Maintainers
2
Created
Source

@bro-academy/vite-plugin-image-optimizer

A Vite plugin to optimize images in HTML and CSS during the build process. Supports automatic image dimension injection and conversion to modern formats.

Features

  • Optimizes PNG and JPEG images in your build output
  • Converts images to WebP and AVIF formats (if requested)
  • Injects image dimensions into HTML
  • Updates HTML and CSS to reference optimized/converted images

Installation

Install the plugin and its peer dependency:

npm install @bro-academy/vite-plugin-image-optimizer --save-dev

Usage

Add the plugin to your vite.config.js:

import imageOptimizer from '@bro-academy/vite-plugin-image-optimizer';

export default {
  plugins: [
    imageOptimizer({
      dimensions: true // Set to false to skip adding width/height
    })
  ]
};

How it works

  • During build, the plugin scans your HTML and CSS for image references.
  • It optimizes and converts only the images actually used in the output.
  • HTML and CSS are updated to reference the optimized/converted images.
  • Image dimensions are injected into <img> tags if enabled.

Options

OptionTypeDefaultDescription
dimensionsbooleantrueInjects width/height attributes into <img>

Example

HTML

<img src="/src/assets/images/banner.png?format=avif">
<img src="/src/assets/images/banner.png?format=webp">

<picture>
    <source srcset="/src/assets/images/banner.png?format=webp" type="image/webp">
    <source srcset="/src/assets/images/banner.png?format=avif" type="image/avif">
    <img src="/src/assets/images/main-banner.png">
</picture>

CSS

.class {
    background-image: url('/src/assets/images/banner.png?format=webp');
}

License

ISC

Keywords

vite

FAQs

Package last updated on 01 Jun 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts