@rsbuild/plugin-image-compress 1.3.3 → 1.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +21 -21
  2. package/dist/codecs.d.ts +4 -1
  3. package/package.json +18 -25
package/README.md CHANGED
@@ -24,7 +24,7 @@ Add plugin to your `rsbuild.config.ts`:
24
24
 
25
25
  ```ts
26
26
  // rsbuild.config.ts
27
- import { pluginImageCompress } from "@rsbuild/plugin-image-compress";
27
+ import { pluginImageCompress } from '@rsbuild/plugin-image-compress';
28
28
 
29
29
  export default {
30
30
  plugins: [pluginImageCompress()],
@@ -38,11 +38,11 @@ This plugin is compatible with both Rsbuild and Rspack. If you are using Rspack
38
38
  By default, the plugin will enable `jpeg`, `png`, `ico` image compressors, which are equivalent to the following two examples:
39
39
 
40
40
  ```js
41
- pluginImageCompress(["jpeg", "png", "ico"]);
41
+ pluginImageCompress(['jpeg', 'png', 'ico']);
42
42
  ```
43
43
 
44
44
  ```js
45
- pluginImageCompress([{ use: "jpeg" }, { use: "png" }, { use: "ico" }]);
45
+ pluginImageCompress([{ use: 'jpeg' }, { use: 'png' }, { use: 'ico' }]);
46
46
  ```
47
47
 
48
48
  ## Supported Compressors
@@ -71,17 +71,17 @@ For example, to allow the jpeg compressor to recognize new extension name and to
71
71
  ```js
72
72
  pluginImageCompress([
73
73
  // Options for @napi-rs/image `compressJpeg` method
74
- { use: "jpeg", test: /\.(?:jpg|jpeg|jpe)$/ },
74
+ { use: 'jpeg', test: /\.(?:jpg|jpeg|jpe)$/ },
75
75
  // Options for @napi-rs/image `pngQuantize` method
76
- { use: "png", minQuality: 50 },
76
+ { use: 'png', minQuality: 50 },
77
77
  // Options for @napi-rs/image `avif` method
78
- { use: "avif", quality: 80 },
78
+ { use: 'avif', quality: 80 },
79
79
  // Options for @napi-rs/image `webp` method
80
- { use: "webp", quality: 80 },
80
+ { use: 'webp', quality: 80 },
81
81
  // Options for svgo
82
- { use: "svg", floatPrecision: 2 },
82
+ { use: 'svg', floatPrecision: 2 },
83
83
  // No options yet
84
- { use: "ico" },
84
+ { use: 'ico' },
85
85
  ]);
86
86
  ```
87
87
 
@@ -92,7 +92,7 @@ For more information on compressors, please visit [@napi-rs/image](https://image
92
92
  The default `png` compressor is lossy. If you want to replace it with a lossless compressor, you can use the following configuration.
93
93
 
94
94
  ```js
95
- pluginImageCompress(["jpeg", "pngLossless", "ico"]);
95
+ pluginImageCompress(['jpeg', 'pngLossless', 'ico']);
96
96
  ```
97
97
 
98
98
  The list of configuration options will eventually be converted to the corresponding bundler loader configuration, so compressors follow the same bottom-to-top matching rule.
@@ -100,7 +100,7 @@ The list of configuration options will eventually be converted to the correspond
100
100
  For example, the `png` compressor will take precedence over the `pngLossless` compressor for the following configuration:
101
101
 
102
102
  ```js
103
- pluginImageCompress(["jpeg", "pngLossless", "ico", "png"]);
103
+ pluginImageCompress(['jpeg', 'pngLossless', 'ico', 'png']);
104
104
  ```
105
105
 
106
106
  ## Rspack Usage
@@ -111,42 +111,42 @@ If you are using Rspack instead of Rsbuild, you can import the `ImageMinimizerPl
111
111
 
112
112
  ```ts
113
113
  // rspack.config.mjs
114
- import { ImageMinimizerPlugin } from "@rsbuild/plugin-image-compress";
115
- import { defineConfig } from "@rspack/cli";
114
+ import { ImageMinimizerPlugin } from '@rsbuild/plugin-image-compress';
115
+ import { defineConfig } from '@rspack/cli';
116
116
 
117
117
  export default defineConfig({
118
- mode: process.env.NODE_ENV === "production" ? "production" : "development",
118
+ mode: process.env.NODE_ENV === 'production' ? 'production' : 'development',
119
119
  optimization: {
120
120
  minimizer: [
121
121
  // Use `...` to preserve the default JS and CSS minimizers of Rspack
122
- "...",
122
+ '...',
123
123
  // Add the image minimizer plugins
124
124
  new ImageMinimizerPlugin({
125
- use: "jpeg",
125
+ use: 'jpeg',
126
126
  test: /\.(?:jpg|jpeg)$/,
127
127
  }),
128
128
  new ImageMinimizerPlugin({
129
- use: "png",
129
+ use: 'png',
130
130
  test: /\.png$/,
131
131
  maxQuality: 50,
132
132
  }),
133
133
  new ImageMinimizerPlugin({
134
- use: "avif",
134
+ use: 'avif',
135
135
  test: /\.avif$/,
136
136
  quality: 80,
137
137
  }),
138
138
  new ImageMinimizerPlugin({
139
- use: "webp",
139
+ use: 'webp',
140
140
  test: /\.webp$/,
141
141
  quality: 80,
142
142
  }),
143
143
  new ImageMinimizerPlugin({
144
- use: "svg",
144
+ use: 'svg',
145
145
  test: /\.svg$/,
146
146
  floatPrecision: 2,
147
147
  }),
148
148
  new ImageMinimizerPlugin({
149
- use: "ico",
149
+ use: 'ico',
150
150
  test: /\.(?:ico|icon)$/,
151
151
  }),
152
152
  ],
package/dist/codecs.d.ts CHANGED
@@ -6,5 +6,8 @@ export declare const icoCodec: Codec<'ico'>;
6
6
  export declare const avifCodec: Codec<'avif'>;
7
7
  export declare const webpCodec: Codec<'webp'>;
8
8
  export declare const svgCodec: Codec<'svg'>;
9
- declare const codecs: Record<Codecs, Codec<any>>;
9
+ type CodecMap = {
10
+ [K in Codecs]: Codec<K>;
11
+ };
12
+ declare const codecs: CodecMap;
10
13
  export default codecs;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/plugin-image-compress",
3
- "version": "1.3.3",
3
+ "version": "1.3.4",
4
4
  "repository": "https://github.com/rstackjs/rsbuild-plugin-image-compress",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -17,35 +17,21 @@
17
17
  "files": [
18
18
  "dist"
19
19
  ],
20
- "scripts": {
21
- "build": "rslib",
22
- "dev": "rslib -w",
23
- "lint": "biome check .",
24
- "lint:write": "biome check . --write",
25
- "prepare": "simple-git-hooks && npm run build",
26
- "test": "playwright test",
27
- "bump": "npx bumpp"
28
- },
29
20
  "simple-git-hooks": {
30
- "pre-commit": "npx nano-staged"
31
- },
32
- "nano-staged": {
33
- "*.{js,jsx,ts,tsx,mjs,cjs}": [
34
- "biome check --write --no-errors-on-unmatched"
35
- ]
21
+ "pre-commit": "pnpm run lint:write"
36
22
  },
37
23
  "dependencies": {
38
24
  "@napi-rs/image": "1.11.2",
39
25
  "svgo": "^3.3.3"
40
26
  },
41
27
  "devDependencies": {
42
- "@biomejs/biome": "^1.9.4",
43
- "@playwright/test": "^1.59.1",
44
- "@rsbuild/core": "^2.0.0",
45
- "@rslib/core": "^0.21.3",
46
- "@types/node": "^24.12.2",
47
- "nano-staged": "^1.0.2",
48
- "playwright": "^1.59.1",
28
+ "@playwright/test": "^1.60.0",
29
+ "@rsbuild/core": "^2.0.6",
30
+ "@rslib/core": "^0.21.5",
31
+ "@rslint/core": "^0.5.3",
32
+ "@types/node": "^24.12.4",
33
+ "playwright": "^1.60.0",
34
+ "prettier": "^3.8.3",
49
35
  "simple-git-hooks": "^2.13.1",
50
36
  "typescript": "6.0.3"
51
37
  },
@@ -57,9 +43,16 @@
57
43
  "optional": true
58
44
  }
59
45
  },
60
- "packageManager": "pnpm@10.33.1",
61
46
  "publishConfig": {
62
47
  "access": "public",
63
48
  "registry": "https://registry.npmjs.org/"
49
+ },
50
+ "scripts": {
51
+ "build": "rslib",
52
+ "dev": "rslib -w",
53
+ "lint": "rslint && prettier -c .",
54
+ "lint:write": "rslint --fix && prettier -w .",
55
+ "test": "playwright test",
56
+ "bump": "npx bumpp"
64
57
  }
65
- }
58
+ }