0.2.0 • Published 4 years ago
vite-plugin-img v0.2.0
Vite Plugin Img
A Vite plugin to transform images in your HTML. For images, creates Responsive Images by cutting images at different sizes and formats. For gifs, transforms them into videos.
Installation
First, install from NPM:
$ npm install vite-plugin-img --save-devThen, include the plugin in your Vite config:
const { imgPlugin } = require('vite-plugin-img');
module.exports = {
plugins: [imgPlugin()],
};Usage
Images should be stored in, and referenced from, your Vite public directory. Then, write standard img tags referencing the images you want! As long as the img tag is in the rendered HTML, this plugin will pick it up and update it!
Options
The following options are available:
formats- The formats to includeresize- Image resize options. Images won't be upscaled, and are based on image widthresize.min- Smallest image width to cut, in pixels. Number, defaults to250resize.max- Largest image width to cut, in pixels. Number, defaults to1500resize.step- Difference, in pixels, between the width of each image cut. Number, defaults to150.
wrapSVG- Whether or not to wrap SVGs inpictureelements. Boolean, defaults tofalseattrs- Array of attribute names to include in wrappedpictureelement from the wrappingimgtag. Defaults to['class']sizes- Defaultsizesattribute, if one isn't available. Defaults to100vwlazy- Whether to lazyload images using theloadingattribute. Boolean, defaults totrueoptimizer- Which image optimizer to use,sharporsquoosh. Sharp is faster, but results in larger file sizes. Squoosh is slower, but results in smaller file sizes. Performance is only affected on build, not during dev. Defaults tosquoosh.