{"id":22484849,"url":"https://github.com/jw-12138/vite-plugin-vsharp","last_synced_at":"2025-03-04T18:39:28.674Z","repository":{"id":45775664,"uuid":"431183295","full_name":"jw-12138/vite-plugin-vsharp","owner":"jw-12138","description":"Compress Images for the Web with Vite and Sharp","archived":false,"fork":false,"pushed_at":"2024-06-07T03:47:53.000Z","size":1247,"stargazers_count":49,"open_issues_count":1,"forks_count":0,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-02-25T09:47:29.227Z","etag":null,"topics":["image-processing","sharp-js","vite-plugin"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jw-12138.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2021-11-23T16:55:40.000Z","updated_at":"2025-01-19T01:31:58.000Z","dependencies_parsed_at":"2023-11-19T13:44:24.207Z","dependency_job_id":null,"html_url":"https://github.com/jw-12138/vite-plugin-vsharp","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jw-12138%2Fvite-plugin-vsharp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jw-12138%2Fvite-plugin-vsharp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jw-12138%2Fvite-plugin-vsharp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jw-12138%2Fvite-plugin-vsharp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jw-12138","download_url":"https://codeload.github.com/jw-12138/vite-plugin-vsharp/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241903817,"owners_count":20040011,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["image-processing","sharp-js","vite-plugin"],"created_at":"2024-12-06T17:11:39.588Z","updated_at":"2025-03-04T18:39:28.649Z","avatar_url":"https://github.com/jw-12138.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# VSharp: Compress Images for the Web with Vite and Sharp\n\nVSharp is a powerful Vite plugin that utilizes the formidable Sharp library to compress and optimize static images during your build process. This helps to significantly reduce image sizes, enhancing your website or application's load time and overall performance. With VSharp, maintaining high-quality images at smaller file sizes becomes an effortless part of your development workflow.\n\n\u003cimg width=\"716\" alt=\"image\" src=\"https://github.com/jw-12138/vite-plugin-vsharp/assets/29943110/3e4b97f4-892c-47c0-b850-d1e0fc46b245\"\u003e\n\n\n## Features\n\n- Supported image formats: `.jpg/.jpeg`, `.png`, `.gif`, `.webp`.\n- Integrates image compression features from Sharp's API, including `sharp().jpeg()`, `sharp().png()`, `sharp().gif()`, and `sharp().webp()` ([Sharp documentation](https://sharp.pixelplumbing.com/api-output)).\n\n## Getting Started\n\n### Installation\n\nTo install the plugin, run the following command:\n\n```bash\nnpm install vite-plugin-vsharp --save-dev\n```\n\n### Configuration\n\nAdd VSharp to your Vite configuration file:\n\n```javascript\n// vite.config.js\nimport vsharp from 'vite-plugin-vsharp';\n\nexport default {\n  plugins: [\n    vsharp({\n      // Plugin options go here\n    }),\n  ],\n};\n```\n\n## Plugin Options\n\nCustomize the behavior of VSharp with the following options:\n\n1. `exclude`: Specify which image files to skip **during image bundling**. Simple names without path prefixes are required.\n\n   ```js\n   // vite.config.js\n   {\n     // ...\n     plugins: [\n       vsharp({\n         exclude: [\n           \"bg.jpg\", // Includes \"bg.jpg\"\n           // Do not add path prefixes or hashes\n         ],\n       }),\n     ]\n   }\n   ```\n\n2. `excludePublic`: Exclude images from the public directory using glob patterns. Prefixes relative to your project's root are necessary.\n\n   ```js\n   // vite.config.js\n   {\n     // ...\n     plugins: [\n       vsharp({\n         excludePublic: [\n           \"public/test_img/*\", // Exclude all images in public/test_img\n         ],\n       }),\n     ]\n   }\n   ```\n\n3. `includePublic`: Specifically include images from an excluded directory, overriding the `excludePublic` option.\n\n   ```js\n   // vite.config.js\n   {\n     // ...\n     plugins: [\n       vsharp({\n         excludePublic: [\n           \"public/test_img/*\"\n         ],\n         includePublic: [\n           \"public/test_img/001.jpg\", // Include this particular image\n         ],\n       }),\n     ]\n   }\n   ```\n\n4. Resize options: Configure dimensions or scaling to resize images.\n\n   ```js\n   // vite.config.js\n   {\n     // ...\n     plugins: [\n       vsharp({\n         width: 800, // Max width, images with a smaller width than this will not be resized\n         height: 800, // Max height, images with a smaller height than this will not be resized\n         scale: 0.8, // Overrides width and height\n       }),\n     ]\n   }\n   ```\n\n5. Preserve Metadata: Maintain image metadata such as orientation.\n\n   ```js\n   // vite.config.js\n   {\n     // ...\n     plugins: [\n       vsharp({\n         preserveMetadata: {\n           orientation: true, // Preserves image orientation\n         },\n       }),\n     ]\n   }\n   ```\n\n## Default Settings\n\nThe plugin provides sensible defaults, which can be overridden by specifying your own settings in the plugin options:\n\n```json\n{\n  \"includePublic\": [],\n  \"excludePublic\": [],\n  \"exclude\": [],\n  \".jpg\": {\n    \"quality\": 80\n  },\n  \".jpeg\": {\n    \"quality\": 80\n  },\n  \".png\": {\n    \"quality\": 80,\n    \"palette\": true\n  },\n  \".webp\": {\n    \"lossless\": true\n  },\n  \".gif\": {\n    \n  },\n  \"preserveMetadata\": {\n    \"orientation\": false\n  }\n}\n```\n\nFor additional Sharp function parameters, refer to the [official Sharp documentation](https://sharp.pixelplumbing.com/api-constructor).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjw-12138%2Fvite-plugin-vsharp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjw-12138%2Fvite-plugin-vsharp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjw-12138%2Fvite-plugin-vsharp/lists"}