{"id":13605772,"url":"https://github.com/60late/vite-plugin-minipic","last_synced_at":"2025-08-18T07:04:41.995Z","repository":{"id":189263615,"uuid":"680080351","full_name":"60late/vite-plugin-minipic","owner":"60late","description":"Based on sharp.js, compress your image before vite generate bundle. It's easy and fast! 基于sharp.js的vite图片压缩插件，又快又好用！","archived":false,"fork":false,"pushed_at":"2025-07-30T09:58:08.000Z","size":67750,"stargazers_count":59,"open_issues_count":2,"forks_count":5,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-30T11:55:24.267Z","etag":null,"topics":["compression","image","image-compress","image-compression","jpeg","png","vite","vite-compression","vite-plugin","webp"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/60late.png","metadata":{"files":{"readme":"README.CN.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-08-18T09:42:50.000Z","updated_at":"2025-07-30T09:58:12.000Z","dependencies_parsed_at":"2023-08-19T03:27:36.335Z","dependency_job_id":"9e9904c4-3614-4b25-9930-eab8b5793e71","html_url":"https://github.com/60late/vite-plugin-minipic","commit_stats":{"total_commits":86,"total_committers":2,"mean_commits":43.0,"dds":"0.011627906976744207","last_synced_commit":"4a3a198020f380615acd00d517c94ba7179d2520"},"previous_names":["60late/vite-plugin-minipic"],"tags_count":36,"template":false,"template_full_name":null,"purl":"pkg:github/60late/vite-plugin-minipic","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/60late%2Fvite-plugin-minipic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/60late%2Fvite-plugin-minipic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/60late%2Fvite-plugin-minipic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/60late%2Fvite-plugin-minipic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/60late","download_url":"https://codeload.github.com/60late/vite-plugin-minipic/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/60late%2Fvite-plugin-minipic/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270956483,"owners_count":24674943,"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","status":"online","status_checked_at":"2025-08-18T02:00:08.743Z","response_time":89,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["compression","image","image-compress","image-compression","jpeg","png","vite","vite-compression","vite-plugin","webp"],"created_at":"2024-08-01T19:01:02.556Z","updated_at":"2025-08-18T07:04:41.978Z","avatar_url":"https://github.com/60late.png","language":"TypeScript","funding_links":[],"categories":["Plugins"],"sub_categories":["Framework-agnostic Plugins"],"readme":"# vite-plugin-minipic\n\n**中文** | [English](README.md)  \nvite图片压缩插件，使用简单，重要的是它真的很快 🚀🚀🚀🚀！!  \n基于[sharp](https://github.com/lovell/sharp)开发  \n![example](./examples/vue3-vite/src/assets/img/performance.gif)\n\n## ❓为什么选择minipic?\n\n- 🚀 极快压缩速率  \n  本插件基于[sharp.js](https://github.com/lovell/sharp)，压缩速率极快。  \n  完全满足项目多图、大图压缩需求。  \n  实测40M的图片文件压缩时间只需要3秒左右，整体压缩体积可以在70%~80%以上（设备：macbook m1。压缩质量设定：75%）。\n- 💾 增量压缩/缓存控制  \n  默认开启增量压缩功能，在首次进行图片压缩时会把压缩后的图片存在本地磁盘中，后续直接读取缓存文件加快压缩速率，杜绝多次重复压缩图片\n\n- 📷 图片类型转换  \n  可以在压缩同时将图片转为其他格式\n\n- 🔎 特定图片压缩/排除  \n  可以框定压缩图片的范围，也可以对不想进行压缩的图片进行排除\n\n- 📂 Public文件夹压缩支持 (Version≥1.1)\n  支持压缩public文件夹下的图片\n\n## 📦 安装\n\n```JS\nnpm install vite-plugin-minipic -D\n```\n\n你可以自由选择任何包管理工具，推荐`yarn`和`pnpm`\n\n❗❗❗ 安装失败？  \n如果你无法安装，请在你全局或者项目目录下的.npmrc文件中加入以下配置\n\n```JS\nregistry=\"https://registry.npmmirror.com\"\nsharp_binary_host=\"https://registry.npmmirror.com/-/binary/sharp\"\nsharp_libvips_binary_host=\"https://registry.npmmirror.com/-/binary/sharp-libvips\"\n```\n\n更多问题见：[常见问题及解决方法](https://github.com/60late/vite-plugin-minipic/issues/2)\n\n## 💻 使用\n\n### 基本使用\n\nin vite.config.js\n\n```javascript\nimport minipic from 'vite-plugin-minipic'\nexport default defineConfig({\n\tplugins: [minipic()]\n})\n```\n\n### 自定义配置\n\nin vite.config.js\n\n```javascript\nimport minipic from 'vite-plugin-minipic'\nexport default defineConfig({\n\tplugins: [\n\t\tminipic({\n\t\t\tsharpOptions: {\n\t\t\t\tpng: {\n\t\t\t\t\tquality: 70\n\t\t\t\t},\n\t\t\t\tjpeg: {\n\t\t\t\t\tquality: 33\n\t\t\t\t},\n\t\t\t\tjpg: {\n\t\t\t\t\tquality: 70\n\t\t\t\t}\n\t\t\t},\n\t\t\tconvert: [\n\t\t\t\t{ from: 'png', to: 'webp' },\n\t\t\t\t{ from: 'jpg', to: 'webp' },\n\t\t\t\t{ from: 'jpeg', to: 'jpg' }\n\t\t\t],\n\t\t\tconvertPublic: false,\n\t\t\tcache: true\n\t\t})\n\t]\n})\n```\n\n## 🔨 配置项\n\n| 参数                                | 类型                   | 默认值                        | 说明                                                                                                                                                                                                                                                                                                        |\n| ----------------------------------- | ---------------------- | ----------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| sharpOptions                        | Object                 | [sharpOptions](#sharpoptions) | 图片压缩选项，和sharp.js的配置保持一致.关于更多sharp.js的配置项，见[sharp.js](https://sharp.pixelplumbing.com/api-output#jpeg)                                                                                                                                                                              |\n| convert                             | Object                 | [convert](#convert)           | 你可以通过这个选项控制图片经过处理后的类型 `from` 是原始类型 `to` 是处理后的类型                                                                                                                                                                                                                            |\n| converPublic （version\u003e=1.3）       | Boolean                | true                          | 你可以通过把这个选项设置为`true`来让pulic文件夹下的文件也进行类型转换。但是这个操作会导致最终生成的产物文件后缀发生改变，你应该谨慎使用该指标，确认不会造成意外影响后再使用                                                                                                                                 |\n| cache                               | Boolean                | true                          | 第一次压缩后会将已压缩文件存入磁盘中进行缓存以提高压缩速度，如果不想占用本地磁盘空间将此值设置为false，则每次都会全量压缩                                                                                                                                                                                   |\n| exclude                             | `string` or `string[]` | []                            | 你可以通过通过这个选项排除不想要进行压缩的文件。 1.如果值为一个字符串数组，比如`exclude:['pic1.jpg','pic2.jpg']`,那么pic1和pic2将会被排除。2. 如果值为一个字符串，比如`exclude:'.jpg'`,那么这个值将被作为一个正则表达式，所有的.jpg文件都会被排除在外.如果`exclude`和`include`同时存在时，`include`将会失效 |\n| include                             | `string` or `string[]` | []                            | 你可以通过通过这个选项排除不想要进行压缩的文件。1.如果值为一个字符串数组，比如`include:['pic1.jpg','pic2.jpg']`,那么pic1和pic2将会被压缩。 2. 如果值为一个字符串，比如`include:'.jpg'`,那么这个值将被作为一个正则表达式，所有的.jpg文件都会被压缩. 如果`exclude`和`include`同时存在时，`include`将会失效    |\n| limitInputPixels （version\u003e=1.3.1） | boolean                | true                          | 只对`gif` 图片有效。Sharp在处理gif图片时，如果超出其限制，那么会抛出错误。此值默认设置为true，遇到超出限制的图片时，本插件会自动跳过对该图片的处理。如果你设置这个值为false，那么会强行对该图片进行压缩，可能会导致`OOM`问题，请谨慎使用该属性                                                              |\n\n### sharpOptions\n\n图片压缩选项，和sharp.js的配置保持一致。  \n关于更多sharp.js的配置项，见[sharp.js](https://sharp.pixelplumbing.com/api-output#jpeg)\n\n默认值：\n\n```javascript\nsharpOptions: {\n\tavif: {\n\t\tquality: 75\n\t},\n\tjpeg: {\n\t\tquality: 75\n\t},\n\tjpg: {\n\t\tquality: 75\n\t},\n\tpng: {\n\t\tquality: 75\n\t},\n\twebp: {\n\t\tquality: 75\n\t},\n\tgif:{}\n}\n```\n\n### convert\n\n你可以通过这个选项控制图片经过处理后的类型\n`from` 是原始类型\n`to` 是处理后的类型\n\n例子:\n\n```javascript\nconvert: [\n\t{ from: 'png', to: 'png' },\n\t{ from: 'jpg', to: 'jpeg' },\n\t{ from: 'jpeg', to: 'webp' },\n\t{ from: 'avif', to: 'avif' }\n]\n```\n\nFor more detail config, see [sharp.js](https://sharp.pixelplumbing.com/api-output#jpeg).\n\n## 看看例子\n\nRun examples\n\n```\nyarn vue3\n```\n\nor\n\n```\nnpm run vue3\n```\n\n## 目前支持的图片格式\n\n目前只支持 avif、jpeg、jpg、png、webp、gif 格式\n更多图片格式会在后续版本中进行支持  \n目前不支持public文件夹下的压缩，后续版本会添加支持\n\n## 待办\n\n- [x] 缓存功能\n- [x] 排除特定不压缩的文件\n- [x] 只对特定文件进行压缩\n- [x] 支持public文件夹内容压缩(version\u003e1.1)\n- [ ] 更多图片类型支持\n- [ ] 文件夹级别的排除和压缩功能\n\n## 证书\n\nMIT\n\n## 灵感来源\n\n[vite-plugin-imagemin](https://github.com/vbenjs/vite-plugin-imagemin)  \n[unplugin-imagemin](https://github.com/ErKeLost/unplugin-imagemin)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F60late%2Fvite-plugin-minipic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F60late%2Fvite-plugin-minipic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F60late%2Fvite-plugin-minipic/lists"}