{"id":22432528,"url":"https://github.com/zhusiqing/sharp-webpack-plugin","last_synced_at":"2025-03-27T07:42:28.494Z","repository":{"id":224509005,"uuid":"763453335","full_name":"zhusiqing/sharp-webpack-plugin","owner":"zhusiqing","description":"基于sharp图片压缩的webpack插件","archived":false,"fork":false,"pushed_at":"2024-02-26T10:54:38.000Z","size":34,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-02T18:09:08.850Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/zhusiqing.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,"roadmap":null,"authors":null,"dei":null}},"created_at":"2024-02-26T10:22:31.000Z","updated_at":"2024-02-26T10:54:43.000Z","dependencies_parsed_at":"2024-02-26T11:06:02.449Z","dependency_job_id":"c83afe10-aba4-4b08-9f90-e37394c97673","html_url":"https://github.com/zhusiqing/sharp-webpack-plugin","commit_stats":null,"previous_names":["zhusiqing/sharp-webpack-plugin"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhusiqing%2Fsharp-webpack-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhusiqing%2Fsharp-webpack-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhusiqing%2Fsharp-webpack-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhusiqing%2Fsharp-webpack-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zhusiqing","download_url":"https://codeload.github.com/zhusiqing/sharp-webpack-plugin/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245806026,"owners_count":20675291,"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":[],"created_at":"2024-12-05T22:12:03.989Z","updated_at":"2025-03-27T07:42:28.461Z","avatar_url":"https://github.com/zhusiqing.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# sharp-webpack-plugin\n\n\u003e 基于sharp图片压缩的webpack插件\n\n目前只支持png、jpg、jpeg格式的图片压缩\n\n## 依赖\n\n`webpack \u003e= 4.0.0`\n`node \u003e= 14.0.0`\n`sharp = 0.32.6`\n\n\u003e 因为要兼容webpack4和node14，所以sharp的版本锁定在0.32.6\n\n## 安装\n\n```bash\n# npm\nnpm install -D sharp-webpack-plugin\n# yarn\nyarn add -D sharp-webpack-plugin\n# pnpm\npnpm add -D sharp-webpack-plugin\n```\n\n国内安装时，可能会因为某种原因安装失败，这里可以将sharp的二进制源更换为国内镜像源\n\n`sharp@0.32.6`对应的`sharp-libvips`版本为`8.14.5`\n\n```bash\n# .npmrc\nregistry=https://registry.npmmirror.com\nSHARP_DIST_BASE_URL=https://registry.npmmirror.com/-/binary/sharp-libvips/v8.14.5/\n```\n\n## 使用\n\n```js\n  const { sharpWebpackPlugin } = require('sharp-webpack-plugin');\n  module.exports = {\n    plugin: [\n      new sharpWebpackPlugin()\n    ]\n  }\n```\n\n## 配置参数(Options)\n\n#### Options.quality: number\n\n统一的图片压缩质量，范围是0-100，默认为60\n\n#### Options.minSize: number\n\n统一的图片压缩最小尺寸，单位为B，默认为300 * 1024(300KB)\n\n#### Options.log: boolean\n\n是否打印压缩日志，默认为false\n\n#### Options.filter: (filename: string) =\u003e boolean\n\n过滤器，可以自定义过滤规则，只对符合过滤规则的文件进行压缩，函数的第一个参数为图片的路径地址加文件名，函数返回true表示需要压缩，false表示不压缩，默认为不过滤\n\n#### Options.png: sharp.PngOptions\n\npng压缩配置，参考[sharp文档](https://sharp.pixelplumbing.com/api-output#png)\n\n\u003e 配置参数中的quality优先于Options.quality\n\n#### Options.jpg: sharp.JpgOptions\n\njpg压缩配置，参考[sharp文档](https://sharp.pixelplumbing.com/api-output#jpeg)\n\n\u003e 配置参数中的quality优先于Options.quality\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhusiqing%2Fsharp-webpack-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzhusiqing%2Fsharp-webpack-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhusiqing%2Fsharp-webpack-plugin/lists"}