Skip to content

Commit 804b59f

Browse files
committed
docs: update readme
1 parent f4302a1 commit 804b59f

File tree

2 files changed

+61
-36
lines changed

2 files changed

+61
-36
lines changed

README-CN.md

+60-35
Original file line numberDiff line numberDiff line change
@@ -11,68 +11,93 @@
1111
1212
<img width="414px" src="./example.png?raw=true" alt="example" />
1313

14-
## 使用
15-
16-
### 步骤 1: 安装
14+
## 安装
1715

1816
```sh
19-
yarn add -D react-native-imagemin-asset-plugin
17+
yarn add -D react-native-imagemin-asset-plugin imagemin
2018
```
2119

2220
or
2321

2422
```sh
25-
npm install --save-dev react-native-imagemin-asset-plugin
23+
npm install --save-dev react-native-imagemin-asset-plugin imagemin
2624
```
2725

28-
### 步骤 2: 配置 `metro.config.js`
26+
## 配置
2927

30-
如下,修改 `metro.config.js` 文件,在 `transformer` 中添加 `assetPlugins` 属性,并设置为 `['react-native-imagemin-asset-plugin']`
28+
你可以通过修改 `metro.config.js` 文件,在 `transformer` 中添加 `assetPlugins` 属性,并设置为 `['react-native-imagemin-asset-plugin']`
3129

32-
```js
33-
module.exports = {
34-
transformer: {
35-
// ...
36-
assetPlugins: ['react-native-imagemin-asset-plugin'],
37-
},
38-
};
30+
根据需求选择不同的压缩方式,有以下两种搭配供参考:
31+
32+
**推荐用于无损优化的 imagemin 插件**
33+
34+
```sh
35+
npm install imagemin-gifsicle imagemin-jpegtran imagemin-optipng imagemin-svgo --save-dev
3936
```
4037

41-
## 配置
38+
**推荐用于有损优化的 imagemin 插件**
39+
40+
```sh
41+
npm install imagemin-gifsicle imagemin-mozjpeg imagemin-pngquant imagemin-svgo --save-dev
42+
```
43+
44+
对于 `imagemin-svgo` v9.0.0+ 需要使用 svgo [配置](https://github.com/svg/svgo#configuration)
4245

43-
如下,可以在 `metro.config.js` 文件的 `transformer` 属性中添加 `imageminAssetPlugin` 以自定义插件的功能。
4446

47+
**metro.config.js (React Native Cli)**
4548

4649
```js
4750
module.exports = {
4851
transformer: {
4952
// ...
5053
assetPlugins: ['react-native-imagemin-asset-plugin'],
5154
imageminAssetPlugin: {
52-
imageminDir: '.compressed-images',
53-
pngquant: {
54-
quality: [0.6, 0.8],
55-
},
56-
mozjpeg: {
57-
quality: 60,
58-
},
55+
cacheDir: '.compressed-images',
56+
minimizer: {
57+
implementation: 'imagemin',
58+
options: {
59+
// Lossless optimization with custom option
60+
// Feel free to experiment with options for better result for you
61+
plugins: [
62+
["gifsicle", { interlaced: true }],
63+
["jpegtran", { progressive: true }],
64+
['pngquant'],
65+
]
66+
}
67+
}
5968
},
6069
},
6170
};
6271
```
72+
**metro.config.js (Expo Go)**
6373

64-
| 属性 | 描述 | 参考 |
65-
| ----------- | --------------------------------------------- | ------------------------------------------------------------ |
66-
| imageminDir | 存储压缩后图片的临时文件夹 | Default: `.shrunken` |
67-
| giflossy<br />(deprecated) | (有损)压缩 GIF 格式图片 | https://github.com/imagemin/imagemin-giflossy |
68-
| gifsicle | (无损)压缩 GIF 格式图片 | https://github.com/imagemin/imagemin-gifsicle |
69-
| mozjpeg | (有损)压缩 JPEG 格式图片 | https://github.com/imagemin/imagemin-mozjpeg |
70-
| jpegtran | (无损)压缩 JPEG 格式图片 | https://github.com/imagemin/imagemin-jpegtran |
71-
| pngquant | (有损)压缩 PNG 格式图片 | https://github.com/imagemin/imagemin-pngquant |
72-
| optipng | (无损)压缩 PNG 格式图片 | https://github.com/imagemin/imagemin-optipng |
73-
| svgo | (有损)压缩 SVG 格式图片 | https://github.com/imagemin/imagemin-svgo |
74-
| webp<br /> | 压缩 JPG & PNG 格式图片 为 WEBP 格式图片 | https://github.com/imagemin/imagemin-webp |
75-
74+
```js
75+
// Learn more https://docs.expo.io/guides/customizing-metro
76+
const { getDefaultConfig } = require('expo/metro-config');
77+
78+
/** @type {import('expo/metro-config').MetroConfig} */
79+
const config = getDefaultConfig(__dirname);
80+
81+
// use plugin to compress assets
82+
config.transformer.assetPlugins.push('react-native-imagemin-asset-plugin');
83+
config.transformer.imageminAssetPlugin = {
84+
cacheDir: '.compressed-images',
85+
minimizer: {
86+
implementation: 'imagemin',
87+
options: {
88+
// Lossless optimization with custom option
89+
// Feel free to experiment with options for better result for you
90+
plugins: [
91+
["gifsicle", { interlaced: true }],
92+
["jpegtran", { progressive: true }],
93+
['pngquant'],
94+
]
95+
}
96+
}
97+
}
98+
99+
module.exports = config;
100+
```
76101

77102
## LICENSE
78103

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ npm install --save-dev react-native-imagemin-asset-plugin imagemin
3131
3232
## Configuration
3333

34-
You can configure the plugin behaviour through the optional `imageminAssetPlugin` field in your `metro.config.js` file under the `transformer` section.
34+
You can configure the plugin behaviour through the optional `assetPlugins` field in your `metro.config.js` file under the `transformer` section.
3535

3636
Explore the options to get the best result for you.
3737

0 commit comments

Comments
 (0)