@rsbuild/plugin-image-compress 1.3.0 → 1.3.2
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.
- package/README.md +3 -3
- package/dist/index.cjs +9 -10
- package/dist/index.js +6 -7
- package/package.json +12 -12
package/README.md
CHANGED
|
@@ -79,7 +79,7 @@ pluginImageCompress([
|
|
|
79
79
|
// Options for @napi-rs/image `webp` method
|
|
80
80
|
{ use: "webp", quality: 80 },
|
|
81
81
|
// Options for svgo
|
|
82
|
-
{ use:
|
|
82
|
+
{ use: "svg", floatPrecision: 2 },
|
|
83
83
|
// No options yet
|
|
84
84
|
{ use: "ico" },
|
|
85
85
|
]);
|
|
@@ -107,7 +107,7 @@ pluginImageCompress(["jpeg", "pngLossless", "ico", "png"]);
|
|
|
107
107
|
|
|
108
108
|
The plugin is also compatible with Rspack.
|
|
109
109
|
|
|
110
|
-
If you are using Rspack instead of Rsbuild, you can import the `ImageMinimizerPlugin` from the package, use it in the [optimization.minimizer](https://rspack.
|
|
110
|
+
If you are using Rspack instead of Rsbuild, you can import the `ImageMinimizerPlugin` from the package, use it in the [optimization.minimizer](https://rspack.rs/config/optimization#optimizationminimizer) array.
|
|
111
111
|
|
|
112
112
|
```ts
|
|
113
113
|
// rspack.config.mjs
|
|
@@ -119,7 +119,7 @@ export default defineConfig({
|
|
|
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
125
|
use: "jpeg",
|
package/dist/index.cjs
CHANGED
|
@@ -33,10 +33,10 @@ var __webpack_require__ = {};
|
|
|
33
33
|
var __webpack_exports__ = {};
|
|
34
34
|
__webpack_require__.r(__webpack_exports__);
|
|
35
35
|
__webpack_require__.d(__webpack_exports__, {
|
|
36
|
-
pluginImageCompress: ()=>pluginImageCompress,
|
|
37
|
-
PLUGIN_IMAGE_COMPRESS_NAME: ()=>PLUGIN_IMAGE_COMPRESS_NAME,
|
|
38
36
|
DEFAULT_OPTIONS: ()=>DEFAULT_OPTIONS,
|
|
39
|
-
ImageMinimizerPlugin: ()=>ImageMinimizerPlugin
|
|
37
|
+
ImageMinimizerPlugin: ()=>ImageMinimizerPlugin,
|
|
38
|
+
PLUGIN_IMAGE_COMPRESS_NAME: ()=>PLUGIN_IMAGE_COMPRESS_NAME,
|
|
39
|
+
pluginImageCompress: ()=>pluginImageCompress
|
|
40
40
|
});
|
|
41
41
|
const external_node_assert_namespaceObject = require("node:assert");
|
|
42
42
|
var external_node_assert_default = /*#__PURE__*/ __webpack_require__.n(external_node_assert_namespaceObject);
|
|
@@ -101,7 +101,7 @@ const svgCodec = {
|
|
|
101
101
|
test: /\.svg$/
|
|
102
102
|
}
|
|
103
103
|
};
|
|
104
|
-
const
|
|
104
|
+
const codecs = {
|
|
105
105
|
jpeg: jpegCodec,
|
|
106
106
|
png: pngCodec,
|
|
107
107
|
pngLossless: pngLosslessCodec,
|
|
@@ -110,7 +110,7 @@ const codecs_codecs = {
|
|
|
110
110
|
avif: avifCodec,
|
|
111
111
|
webp: webpCodec
|
|
112
112
|
};
|
|
113
|
-
const
|
|
113
|
+
const src_codecs = codecs;
|
|
114
114
|
function _define_property(obj, key, value) {
|
|
115
115
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
116
116
|
value: value,
|
|
@@ -134,17 +134,16 @@ class ImageMinimizerPlugin {
|
|
|
134
134
|
if (error instanceof Error) ret.error = error;
|
|
135
135
|
return ret;
|
|
136
136
|
};
|
|
137
|
-
const codec =
|
|
137
|
+
const codec = src_codecs[this.options.use];
|
|
138
138
|
if (!codec) compilation.errors.push(buildError(new Error(`Codec ${this.options.use} is not supported`)));
|
|
139
139
|
const opts = {
|
|
140
140
|
...codec.defaultOptions,
|
|
141
141
|
...this.options
|
|
142
142
|
};
|
|
143
143
|
const handleAsset = async (name)=>{
|
|
144
|
-
|
|
145
|
-
const info = null == (_compilation_getAsset = compilation.getAsset(name)) ? void 0 : _compilation_getAsset.info;
|
|
144
|
+
const info = compilation.getAsset(name)?.info;
|
|
146
145
|
const fileName = name.split('?')[0];
|
|
147
|
-
if (
|
|
146
|
+
if (info?.minimized || !matchObject(opts, fileName)) return;
|
|
148
147
|
const asset = compilation.getAsset(name);
|
|
149
148
|
if (!asset) return;
|
|
150
149
|
const { source: inputSource } = asset;
|
|
@@ -193,7 +192,7 @@ const withDefaultOptions = (opt)=>{
|
|
|
193
192
|
const options = 'string' == typeof opt ? {
|
|
194
193
|
use: opt
|
|
195
194
|
} : opt;
|
|
196
|
-
const { defaultOptions } =
|
|
195
|
+
const { defaultOptions } = src_codecs[options.use];
|
|
197
196
|
const ret = {
|
|
198
197
|
...defaultOptions,
|
|
199
198
|
...options
|
package/dist/index.js
CHANGED
|
@@ -59,7 +59,7 @@ const svgCodec = {
|
|
|
59
59
|
test: /\.svg$/
|
|
60
60
|
}
|
|
61
61
|
};
|
|
62
|
-
const
|
|
62
|
+
const codecs = {
|
|
63
63
|
jpeg: jpegCodec,
|
|
64
64
|
png: pngCodec,
|
|
65
65
|
pngLossless: pngLosslessCodec,
|
|
@@ -68,7 +68,7 @@ const codecs_codecs = {
|
|
|
68
68
|
avif: avifCodec,
|
|
69
69
|
webp: webpCodec
|
|
70
70
|
};
|
|
71
|
-
const
|
|
71
|
+
const src_codecs = codecs;
|
|
72
72
|
function _define_property(obj, key, value) {
|
|
73
73
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
74
74
|
value: value,
|
|
@@ -92,17 +92,16 @@ class ImageMinimizerPlugin {
|
|
|
92
92
|
if (error instanceof Error) ret.error = error;
|
|
93
93
|
return ret;
|
|
94
94
|
};
|
|
95
|
-
const codec =
|
|
95
|
+
const codec = src_codecs[this.options.use];
|
|
96
96
|
if (!codec) compilation.errors.push(buildError(new Error(`Codec ${this.options.use} is not supported`)));
|
|
97
97
|
const opts = {
|
|
98
98
|
...codec.defaultOptions,
|
|
99
99
|
...this.options
|
|
100
100
|
};
|
|
101
101
|
const handleAsset = async (name)=>{
|
|
102
|
-
|
|
103
|
-
const info = null == (_compilation_getAsset = compilation.getAsset(name)) ? void 0 : _compilation_getAsset.info;
|
|
102
|
+
const info = compilation.getAsset(name)?.info;
|
|
104
103
|
const fileName = name.split('?')[0];
|
|
105
|
-
if (
|
|
104
|
+
if (info?.minimized || !matchObject(opts, fileName)) return;
|
|
106
105
|
const asset = compilation.getAsset(name);
|
|
107
106
|
if (!asset) return;
|
|
108
107
|
const { source: inputSource } = asset;
|
|
@@ -151,7 +150,7 @@ const withDefaultOptions = (opt)=>{
|
|
|
151
150
|
const options = 'string' == typeof opt ? {
|
|
152
151
|
use: opt
|
|
153
152
|
} : opt;
|
|
154
|
-
const { defaultOptions } =
|
|
153
|
+
const { defaultOptions } = src_codecs[options.use];
|
|
155
154
|
const ret = {
|
|
156
155
|
...defaultOptions,
|
|
157
156
|
...options
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsbuild/plugin-image-compress",
|
|
3
|
-
"version": "1.3.
|
|
4
|
-
"repository": "https://github.com/
|
|
3
|
+
"version": "1.3.2",
|
|
4
|
+
"repository": "https://github.com/rstackjs/rsbuild-plugin-image-compress",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"exports": {
|
|
@@ -33,29 +33,29 @@
|
|
|
33
33
|
]
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@napi-rs/image": "^1.11.
|
|
36
|
+
"@napi-rs/image": "^1.11.2",
|
|
37
37
|
"svgo": "^3.3.2"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@biomejs/biome": "^1.9.4",
|
|
41
|
-
"@playwright/test": "^1.
|
|
42
|
-
"@rsbuild/core": "1.
|
|
43
|
-
"@rslib/core": "^0.
|
|
44
|
-
"@types/node": "^
|
|
45
|
-
"nano-staged": "^0.
|
|
46
|
-
"playwright": "^1.
|
|
41
|
+
"@playwright/test": "^1.57.0",
|
|
42
|
+
"@rsbuild/core": "1.6.10",
|
|
43
|
+
"@rslib/core": "^0.18.2",
|
|
44
|
+
"@types/node": "^24.10.1",
|
|
45
|
+
"nano-staged": "^0.9.0",
|
|
46
|
+
"playwright": "^1.57.0",
|
|
47
47
|
"simple-git-hooks": "^2.13.1",
|
|
48
|
-
"typescript": "^5.9.
|
|
48
|
+
"typescript": "^5.9.3"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"@rsbuild/core": "1.
|
|
51
|
+
"@rsbuild/core": "^1.0.0 || ^2.0.0-0"
|
|
52
52
|
},
|
|
53
53
|
"peerDependenciesMeta": {
|
|
54
54
|
"@rsbuild/core": {
|
|
55
55
|
"optional": true
|
|
56
56
|
}
|
|
57
57
|
},
|
|
58
|
-
"packageManager": "pnpm@10.
|
|
58
|
+
"packageManager": "pnpm@10.24.0",
|
|
59
59
|
"publishConfig": {
|
|
60
60
|
"access": "public",
|
|
61
61
|
"registry": "https://registry.npmjs.org/"
|