Registry / devops / vite-plugin-vsharp

vite-plugin-vsharp

JSON →
library1.9.1jsnpmunverified

A Vite plugin that compresses static images (jpg, png, gif, webp) after each build using sharp.js. Version 1.9.1 is the latest stable. Ideal for Vite projects needing automated image optimization without manual tooling. It works with Vite 2.6 to 5, handles public folder images, and offers per-format options. The plugin differs from others by being Vite-native, supporting exclude/include patterns for public assets, and allowing resizing and metadata preservation.

npm install vite-plugin-vsharp
INSTALL
IMPORT
SIG · VITE-PLUGIN-VSHARP
V
vite-plugin-vsharp
devopsjavascriptv1.9.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import vsharp from 'vite-plugin-vsharp'
const vsharp = require('vite-plugin-vsharp')
ES module only; CommonJS require is not supported.
vsharp (named export)
import { vsharp } from 'vite-plugin-vsharp'
The package also exports a named export 'vsharp' identical to default. Use whichever style you prefer.
VSharpOptions type
import type { VSharpOptions } from 'vite-plugin-vsharp'
import { VSharpOptions } from 'vite-plugin-vsharp' (will cause runtime error)
TypeScript only; use type import to avoid runtime issues.

Demonstrates setting up VSharp with custom options: per-format quality, exclusions, resizing, and metadata preservation.

// vite.config.js import vsharp from 'vite-plugin-vsharp'; export default { plugins: [ vsharp({ // Compress all images with default settings // Override as needed: '.jpg': { quality: 80 }, '.png': { quality: 80, palette: true }, '.webp': { lossless: true }, exclude: ['large-bg.png'], excludePublic: ['public/icons/*'], includePublic: ['public/images/keep/*'], width: 1920, height: 1080, preserveMetadata: { orientation: true }, }), ], };
Debug
Known issues
breakingPlugin only works with Vite >=2.6 and <=5. Incompatible with Vite 6+.
fix
Downgrade Vite to <=5 or switch to an alternative plugin that supports newer Vite.
affects: >=1.0.0
deprecatedThe options 'publicDir' and 'outDir' are deprecated. Use 'excludePublic' and 'includePublic' instead.
fix
Replace 'publicDir' with 'excludePublic' and 'outDir' with 'includePublic'.
affects: >=1.0.0
gotchaExclude patterns for public folders are relative to the project root, not the public folder itself.
fix
Use patterns like 'public/images/*' without leading slash.
affects: >=1.0.0
gotchaSetting 'scale' overrides 'width' and 'height'. Cannot use both.
fix
Use either scale or width/height, not both.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'sharp'
Sharp is required but not installed. The plugin depends on sharp as a local package.
fix
Run 'npm install sharp' or ensure sharp is installed in your project.
Error: [vsharp] excludePublic: pattern "public/*" must be a string or an array of strings
Incorrect type for excludePublic option.
fix
Provide an array of strings: excludePublic: ['public/*']
TypeError: vsharp is not a function
Using CommonJS require with default import.
fix
Use ES module import: import vsharp from 'vite-plugin-vsharp'
Upgrade
Version history
1.9.1latest on npm
Audit
Dependencies
viterequiredPlugin requires Vite as a peer dependency, works with versions >=2.6 and <=5.
Agent activity
13 hits · last 30 days
node
12
OpenAI (training)
1
Resources
vite-plugin-vsharp — npm install vite-plugin-vsharp · libregistry