{"id":24580428,"url":"https://github.com/ichengbo/react-native-imagemin-asset-plugin","last_synced_at":"2025-04-24T01:09:52.724Z","repository":{"id":38188466,"uuid":"395537881","full_name":"iChengbo/react-native-imagemin-asset-plugin","owner":"iChengbo","description":"React Native plugin for compressing image assets in builds. 用于在项目构建阶段自动压缩图片资源的RN插件。","archived":false,"fork":false,"pushed_at":"2024-09-27T18:15:45.000Z","size":8295,"stargazers_count":17,"open_issues_count":5,"forks_count":2,"subscribers_count":2,"default_branch":"dev","last_synced_at":"2025-04-24T01:09:44.723Z","etag":null,"topics":["asset-plugin","imagemin","metro","react-native"],"latest_commit_sha":null,"homepage":"","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/iChengbo.png","metadata":{"files":{"readme":"README-CN.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-08-13T06:03:49.000Z","updated_at":"2024-09-19T14:56:55.000Z","dependencies_parsed_at":"2024-01-10T03:58:15.498Z","dependency_job_id":"a8f57f9c-af09-4e8d-bbb3-de5641e12718","html_url":"https://github.com/iChengbo/react-native-imagemin-asset-plugin","commit_stats":{"total_commits":69,"total_committers":4,"mean_commits":17.25,"dds":0.3913043478260869,"last_synced_commit":"702b6357700278d297d5ef0d9f6eddd60051ecd9"},"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iChengbo%2Freact-native-imagemin-asset-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iChengbo%2Freact-native-imagemin-asset-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iChengbo%2Freact-native-imagemin-asset-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iChengbo%2Freact-native-imagemin-asset-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iChengbo","download_url":"https://codeload.github.com/iChengbo/react-native-imagemin-asset-plugin/tar.gz/refs/heads/dev","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250540941,"owners_count":21447427,"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":["asset-plugin","imagemin","metro","react-native"],"created_at":"2025-01-24T01:54:10.943Z","updated_at":"2025-04-24T01:09:52.698Z","avatar_url":"https://github.com/iChengbo.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-native-imagemin-asset-plugin\n\n[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)\n[![LICENSE](https://img.shields.io/badge/license-MIT-blue)](./LICENSE)\n[![npm-version](https://img.shields.io/npm/v/react-native-imagemin-asset-plugin)](https://www.npmjs.com/package/react-native-imagemin-asset-plugin)\n[![npm](https://img.shields.io/npm/dm/react-native-imagemin-asset-plugin.svg)](https://www.npmjs.com/package/react-native-imagemin-asset-plugin)\n\n**用于压缩 React-Native 图片资源的 metro 插件**\n\n\u003e 使用 [imagemin](https://github.com/imagemin/imagemin) 完美压缩 PNG, JPG, JPEG 格式图片或者将其转为 WEBP 格式图片。\n\n\u003cimg width=\"414px\" src=\"https://github.com/iChengbo/react-native-imagemin-asset-plugin/blob/master/example.png?raw=true\" alt=\"example\" /\u003e\n\n## 安装\n\n```sh\nyarn add -D react-native-imagemin-asset-plugin imagemin\n```\n\nor\n\n```sh\nnpm install --save-dev react-native-imagemin-asset-plugin imagemin\n```\n\n## 配置\n\n你可以通过修改 `metro.config.js` 文件，在 `transformer` 中添加 `assetPlugins` 属性，并设置为 `['react-native-imagemin-asset-plugin']`\n\n根据需求选择不同的压缩方式，有以下两种搭配供参考：\n\n**推荐用于无损优化的 imagemin 插件**\n\n```sh\nnpm install imagemin-gifsicle imagemin-jpegtran imagemin-optipng imagemin-svgo --save-dev\n```\n\n**推荐用于有损优化的 imagemin 插件**\n\n```sh\nnpm install imagemin-gifsicle imagemin-mozjpeg imagemin-pngquant imagemin-svgo --save-dev\n```\n\n对于 `imagemin-svgo` v9.0.0+ 需要使用 svgo [配置](https://github.com/svg/svgo#configuration)\n\n\n**metro.config.js (React Native Cli)**\n\n```js\nmodule.exports = {\n  transformer: {\n    // ...\n    assetPlugins: ['react-native-imagemin-asset-plugin'],\n    imageminAssetPlugin: {\n      cacheDir: '.compressed-images',\n      minimizer: {\n        implementation: 'imagemin',\n        options: {\n          // Lossless optimization with custom option\n          // Feel free to experiment with options for better result for you\n          plugins: [\n            [\"gifsicle\", { interlaced: true }],\n            [\"jpegtran\", { progressive: true }],\n            ['pngquant'],\n          ]\n        }\n      }\n    },\n  },\n};\n```\n**metro.config.js (Expo Go)**\n\n```js\n// Learn more https://docs.expo.io/guides/customizing-metro\nconst { getDefaultConfig } = require('expo/metro-config');\n\n/** @type {import('expo/metro-config').MetroConfig} */\nconst config = getDefaultConfig(__dirname);\n\n// use plugin to compress assets\nconfig.transformer.assetPlugins.push('react-native-imagemin-asset-plugin');\nconfig.transformer.imageminAssetPlugin = {\n  cacheDir: '.compressed-images',\n  minimizer: {\n    implementation: 'imagemin',\n    options: {\n      // Lossless optimization with custom option\n      // Feel free to experiment with options for better result for you\n      plugins: [\n        [\"gifsicle\", { interlaced: true }],\n        [\"jpegtran\", { progressive: true }],\n        ['pngquant'],\n      ]\n    }\n  }\n}\n\nmodule.exports = config;\n```\n\n## LICENSE\n\n[MIT](./LICENSE)\n\n## 其他 \n\n...\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fichengbo%2Freact-native-imagemin-asset-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fichengbo%2Freact-native-imagemin-asset-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fichengbo%2Freact-native-imagemin-asset-plugin/lists"}