{"id":22918,"library":"vite-plugin-vsharp","title":"Vite Plugin VSharp","description":"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.","status":"active","version":"1.9.1","language":"javascript","source_language":"en","source_url":"https://github.com/jw-12138/vite-plugin-vsharp","tags":["javascript","vite","vite-plugin","sharp.js","typescript"],"install":[{"cmd":"npm install vite-plugin-vsharp","lang":"bash","label":"npm"},{"cmd":"yarn add vite-plugin-vsharp","lang":"bash","label":"yarn"},{"cmd":"pnpm add vite-plugin-vsharp","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Plugin requires Vite as a peer dependency, works with versions >=2.6 and <=5.","package":"vite","optional":false}],"imports":[{"note":"ES module only; CommonJS require is not supported.","wrong":"const vsharp = require('vite-plugin-vsharp')","symbol":"default","correct":"import vsharp from 'vite-plugin-vsharp'"},{"note":"The package also exports a named export 'vsharp' identical to default. Use whichever style you prefer.","wrong":null,"symbol":"vsharp (named export)","correct":"import { vsharp } from 'vite-plugin-vsharp'"},{"note":"TypeScript only; use type import to avoid runtime issues.","wrong":"import { VSharpOptions } from 'vite-plugin-vsharp' (will cause runtime error)","symbol":"VSharpOptions type","correct":"import type { VSharpOptions } from 'vite-plugin-vsharp'"}],"quickstart":{"code":"// vite.config.js\nimport vsharp from 'vite-plugin-vsharp';\n\nexport default {\n  plugins: [\n    vsharp({\n      // Compress all images with default settings\n      // Override as needed:\n      '.jpg': { quality: 80 },\n      '.png': { quality: 80, palette: true },\n      '.webp': { lossless: true },\n      exclude: ['large-bg.png'],\n      excludePublic: ['public/icons/*'],\n      includePublic: ['public/images/keep/*'],\n      width: 1920,\n      height: 1080,\n      preserveMetadata: { orientation: true },\n    }),\n  ],\n};","lang":"javascript","description":"Demonstrates setting up VSharp with custom options: per-format quality, exclusions, resizing, and metadata preservation."},"warnings":[{"fix":"Downgrade Vite to <=5 or switch to an alternative plugin that supports newer Vite.","message":"Plugin only works with Vite >=2.6 and <=5. Incompatible with Vite 6+.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Replace 'publicDir' with 'excludePublic' and 'outDir' with 'includePublic'.","message":"The options 'publicDir' and 'outDir' are deprecated. Use 'excludePublic' and 'includePublic' instead.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Use patterns like 'public/images/*' without leading slash.","message":"Exclude patterns for public folders are relative to the project root, not the public folder itself.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use either scale or width/height, not both.","message":"Setting 'scale' overrides 'width' and 'height'. Cannot use both.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Run 'npm install sharp' or ensure sharp is installed in your project.","cause":"Sharp is required but not installed. The plugin depends on sharp as a local package.","error":"Error: Cannot find module 'sharp'"},{"fix":"Provide an array of strings: excludePublic: ['public/*']","cause":"Incorrect type for excludePublic option.","error":"Error: [vsharp] excludePublic: pattern \"public/*\" must be a string or an array of strings"},{"fix":"Use ES module import: import vsharp from 'vite-plugin-vsharp'","cause":"Using CommonJS require with default import.","error":"TypeError: vsharp is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}