@rsbuild/plugin-image-compress 0.6.15 → 0.7.0-beta.1
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/dist/{index.mjs → index.cjs} +51 -29
- package/dist/index.d.ts +1 -1
- package/dist/index.js +29 -51
- package/package.json +10 -10
|
@@ -1,35 +1,56 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
4
3
|
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
8
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
6
30
|
var __publicField = (obj, key, value) => {
|
|
7
31
|
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
8
32
|
return value;
|
|
9
33
|
};
|
|
10
34
|
|
|
11
|
-
// ../../node_modules/.pnpm/@modern-js+module-tools@2.49.3_eslint@8.57.0_typescript@5.4.5/node_modules/@modern-js/module-tools/shims/esm.js
|
|
12
|
-
import { fileURLToPath } from "url";
|
|
13
|
-
import path from "path";
|
|
14
|
-
|
|
15
35
|
// src/index.ts
|
|
16
|
-
|
|
36
|
+
var src_exports = {};
|
|
37
|
+
__export(src_exports, {
|
|
38
|
+
DEFAULT_OPTIONS: () => DEFAULT_OPTIONS,
|
|
39
|
+
pluginImageCompress: () => pluginImageCompress
|
|
40
|
+
});
|
|
41
|
+
module.exports = __toCommonJS(src_exports);
|
|
42
|
+
var import_node_assert2 = __toESM(require("assert"));
|
|
17
43
|
|
|
18
44
|
// src/minimizer.ts
|
|
19
|
-
|
|
45
|
+
var import_node_buffer2 = require("buffer");
|
|
20
46
|
|
|
21
47
|
// src/shared/codecs.ts
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
compressJpeg,
|
|
26
|
-
losslessCompressPng,
|
|
27
|
-
pngQuantize
|
|
28
|
-
} from "@napi-rs/image";
|
|
29
|
-
import svgo from "svgo";
|
|
48
|
+
var import_node_buffer = require("buffer");
|
|
49
|
+
var import_image = require("@napi-rs/image");
|
|
50
|
+
var import_svgo = __toESM(require("svgo"));
|
|
30
51
|
var jpegCodec = {
|
|
31
52
|
handler(buf, options) {
|
|
32
|
-
return compressJpeg(buf, options);
|
|
53
|
+
return (0, import_image.compressJpeg)(buf, options);
|
|
33
54
|
},
|
|
34
55
|
defaultOptions: {
|
|
35
56
|
test: /\.(?:jpg|jpeg)$/
|
|
@@ -37,7 +58,7 @@ var jpegCodec = {
|
|
|
37
58
|
};
|
|
38
59
|
var pngCodec = {
|
|
39
60
|
handler(buf, options) {
|
|
40
|
-
return pngQuantize(buf, options);
|
|
61
|
+
return (0, import_image.pngQuantize)(buf, options);
|
|
41
62
|
},
|
|
42
63
|
defaultOptions: {
|
|
43
64
|
test: /\.png$/
|
|
@@ -45,7 +66,7 @@ var pngCodec = {
|
|
|
45
66
|
};
|
|
46
67
|
var pngLosslessCodec = {
|
|
47
68
|
handler(buf, options) {
|
|
48
|
-
return losslessCompressPng(buf, options);
|
|
69
|
+
return (0, import_image.losslessCompressPng)(buf, options);
|
|
49
70
|
},
|
|
50
71
|
defaultOptions: {
|
|
51
72
|
test: /\.png$/
|
|
@@ -53,7 +74,7 @@ var pngLosslessCodec = {
|
|
|
53
74
|
};
|
|
54
75
|
var icoCodec = {
|
|
55
76
|
handler(buf) {
|
|
56
|
-
return new Transformer(buf).ico();
|
|
77
|
+
return new import_image.Transformer(buf).ico();
|
|
57
78
|
},
|
|
58
79
|
defaultOptions: {
|
|
59
80
|
test: /\.(?:ico|icon)$/
|
|
@@ -61,8 +82,8 @@ var icoCodec = {
|
|
|
61
82
|
};
|
|
62
83
|
var svgCodec = {
|
|
63
84
|
async handler(buf, options) {
|
|
64
|
-
const result =
|
|
65
|
-
return
|
|
85
|
+
const result = import_svgo.default.optimize(buf.toString(), options);
|
|
86
|
+
return import_node_buffer.Buffer.from(result.data);
|
|
66
87
|
},
|
|
67
88
|
defaultOptions: {
|
|
68
89
|
test: /\.svg$/
|
|
@@ -119,7 +140,7 @@ ${cause.message}` : cause.message;
|
|
|
119
140
|
try {
|
|
120
141
|
if (!result) {
|
|
121
142
|
const input = inputSource.source();
|
|
122
|
-
const buf = await codec.handler(
|
|
143
|
+
const buf = await codec.handler(import_node_buffer2.Buffer.from(input), opts);
|
|
123
144
|
result = { source: new RawSource(buf) };
|
|
124
145
|
await cacheItem.storePromise(result);
|
|
125
146
|
}
|
|
@@ -153,12 +174,12 @@ ${cause.message}` : cause.message;
|
|
|
153
174
|
};
|
|
154
175
|
|
|
155
176
|
// src/shared/utils.ts
|
|
156
|
-
|
|
177
|
+
var import_node_assert = __toESM(require("assert"));
|
|
157
178
|
var withDefaultOptions = (opt) => {
|
|
158
179
|
const options = typeof opt === "string" ? { use: opt } : opt;
|
|
159
180
|
const { defaultOptions } = codecs_default[options.use];
|
|
160
181
|
const ret = { ...defaultOptions, ...options };
|
|
161
|
-
|
|
182
|
+
(0, import_node_assert.default)("test" in ret);
|
|
162
183
|
return ret;
|
|
163
184
|
};
|
|
164
185
|
|
|
@@ -171,7 +192,7 @@ var castOptions = (args) => {
|
|
|
171
192
|
}
|
|
172
193
|
const ret = [];
|
|
173
194
|
for (const arg of args) {
|
|
174
|
-
|
|
195
|
+
(0, import_node_assert2.default)(!Array.isArray(arg));
|
|
175
196
|
ret.push(arg);
|
|
176
197
|
}
|
|
177
198
|
return ret;
|
|
@@ -196,7 +217,8 @@ var pluginImageCompress = (...args) => ({
|
|
|
196
217
|
});
|
|
197
218
|
}
|
|
198
219
|
});
|
|
199
|
-
export
|
|
220
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
221
|
+
0 && (module.exports = {
|
|
200
222
|
DEFAULT_OPTIONS,
|
|
201
223
|
pluginImageCompress
|
|
202
|
-
};
|
|
224
|
+
});
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,56 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
1
|
+
import { createRequire } from 'module';
|
|
2
|
+
var require = createRequire(import.meta['url']);
|
|
3
|
+
|
|
3
4
|
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
5
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
-
var __export = (target, all) => {
|
|
10
|
-
for (var name in all)
|
|
11
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
-
};
|
|
13
|
-
var __copyProps = (to, from, except, desc) => {
|
|
14
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
-
for (let key of __getOwnPropNames(from))
|
|
16
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
-
}
|
|
19
|
-
return to;
|
|
20
|
-
};
|
|
21
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
-
mod
|
|
28
|
-
));
|
|
29
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
6
|
var __publicField = (obj, key, value) => {
|
|
31
7
|
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
32
8
|
return value;
|
|
33
9
|
};
|
|
34
10
|
|
|
11
|
+
// ../../node_modules/.pnpm/@modern-js+module-tools@2.49.3_eslint@8.57.0_typescript@5.4.5/node_modules/@modern-js/module-tools/shims/esm.js
|
|
12
|
+
import { fileURLToPath } from "url";
|
|
13
|
+
import path from "path";
|
|
14
|
+
|
|
35
15
|
// src/index.ts
|
|
36
|
-
|
|
37
|
-
__export(src_exports, {
|
|
38
|
-
DEFAULT_OPTIONS: () => DEFAULT_OPTIONS,
|
|
39
|
-
pluginImageCompress: () => pluginImageCompress
|
|
40
|
-
});
|
|
41
|
-
module.exports = __toCommonJS(src_exports);
|
|
42
|
-
var import_node_assert2 = __toESM(require("assert"));
|
|
16
|
+
import assert2 from "assert";
|
|
43
17
|
|
|
44
18
|
// src/minimizer.ts
|
|
45
|
-
|
|
19
|
+
import { Buffer as Buffer3 } from "buffer";
|
|
46
20
|
|
|
47
21
|
// src/shared/codecs.ts
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
22
|
+
import { Buffer as Buffer2 } from "buffer";
|
|
23
|
+
import {
|
|
24
|
+
Transformer,
|
|
25
|
+
compressJpeg,
|
|
26
|
+
losslessCompressPng,
|
|
27
|
+
pngQuantize
|
|
28
|
+
} from "@napi-rs/image";
|
|
29
|
+
import svgo from "svgo";
|
|
51
30
|
var jpegCodec = {
|
|
52
31
|
handler(buf, options) {
|
|
53
|
-
return
|
|
32
|
+
return compressJpeg(buf, options);
|
|
54
33
|
},
|
|
55
34
|
defaultOptions: {
|
|
56
35
|
test: /\.(?:jpg|jpeg)$/
|
|
@@ -58,7 +37,7 @@ var jpegCodec = {
|
|
|
58
37
|
};
|
|
59
38
|
var pngCodec = {
|
|
60
39
|
handler(buf, options) {
|
|
61
|
-
return
|
|
40
|
+
return pngQuantize(buf, options);
|
|
62
41
|
},
|
|
63
42
|
defaultOptions: {
|
|
64
43
|
test: /\.png$/
|
|
@@ -66,7 +45,7 @@ var pngCodec = {
|
|
|
66
45
|
};
|
|
67
46
|
var pngLosslessCodec = {
|
|
68
47
|
handler(buf, options) {
|
|
69
|
-
return
|
|
48
|
+
return losslessCompressPng(buf, options);
|
|
70
49
|
},
|
|
71
50
|
defaultOptions: {
|
|
72
51
|
test: /\.png$/
|
|
@@ -74,7 +53,7 @@ var pngLosslessCodec = {
|
|
|
74
53
|
};
|
|
75
54
|
var icoCodec = {
|
|
76
55
|
handler(buf) {
|
|
77
|
-
return new
|
|
56
|
+
return new Transformer(buf).ico();
|
|
78
57
|
},
|
|
79
58
|
defaultOptions: {
|
|
80
59
|
test: /\.(?:ico|icon)$/
|
|
@@ -82,8 +61,8 @@ var icoCodec = {
|
|
|
82
61
|
};
|
|
83
62
|
var svgCodec = {
|
|
84
63
|
async handler(buf, options) {
|
|
85
|
-
const result =
|
|
86
|
-
return
|
|
64
|
+
const result = svgo.optimize(buf.toString(), options);
|
|
65
|
+
return Buffer2.from(result.data);
|
|
87
66
|
},
|
|
88
67
|
defaultOptions: {
|
|
89
68
|
test: /\.svg$/
|
|
@@ -140,7 +119,7 @@ ${cause.message}` : cause.message;
|
|
|
140
119
|
try {
|
|
141
120
|
if (!result) {
|
|
142
121
|
const input = inputSource.source();
|
|
143
|
-
const buf = await codec.handler(
|
|
122
|
+
const buf = await codec.handler(Buffer3.from(input), opts);
|
|
144
123
|
result = { source: new RawSource(buf) };
|
|
145
124
|
await cacheItem.storePromise(result);
|
|
146
125
|
}
|
|
@@ -174,12 +153,12 @@ ${cause.message}` : cause.message;
|
|
|
174
153
|
};
|
|
175
154
|
|
|
176
155
|
// src/shared/utils.ts
|
|
177
|
-
|
|
156
|
+
import assert from "assert";
|
|
178
157
|
var withDefaultOptions = (opt) => {
|
|
179
158
|
const options = typeof opt === "string" ? { use: opt } : opt;
|
|
180
159
|
const { defaultOptions } = codecs_default[options.use];
|
|
181
160
|
const ret = { ...defaultOptions, ...options };
|
|
182
|
-
(
|
|
161
|
+
assert("test" in ret);
|
|
183
162
|
return ret;
|
|
184
163
|
};
|
|
185
164
|
|
|
@@ -192,7 +171,7 @@ var castOptions = (args) => {
|
|
|
192
171
|
}
|
|
193
172
|
const ret = [];
|
|
194
173
|
for (const arg of args) {
|
|
195
|
-
(
|
|
174
|
+
assert2(!Array.isArray(arg));
|
|
196
175
|
ret.push(arg);
|
|
197
176
|
}
|
|
198
177
|
return ret;
|
|
@@ -217,8 +196,7 @@ var pluginImageCompress = (...args) => ({
|
|
|
217
196
|
});
|
|
218
197
|
}
|
|
219
198
|
});
|
|
220
|
-
|
|
221
|
-
0 && (module.exports = {
|
|
199
|
+
export {
|
|
222
200
|
DEFAULT_OPTIONS,
|
|
223
201
|
pluginImageCompress
|
|
224
|
-
}
|
|
202
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsbuild/plugin-image-compress",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0-beta.1",
|
|
4
4
|
"description": "Image compress plugin for Rsbuild",
|
|
5
5
|
"homepage": "https://rsbuild.dev",
|
|
6
6
|
"repository": {
|
|
@@ -9,15 +9,15 @@
|
|
|
9
9
|
"directory": "packages/plugin-image-compress"
|
|
10
10
|
},
|
|
11
11
|
"license": "MIT",
|
|
12
|
-
"type": "
|
|
12
|
+
"type": "module",
|
|
13
13
|
"exports": {
|
|
14
14
|
".": {
|
|
15
15
|
"types": "./dist/index.d.ts",
|
|
16
|
-
"import": "./dist/index.
|
|
17
|
-
"
|
|
16
|
+
"import": "./dist/index.js",
|
|
17
|
+
"require": "./dist/index.cjs"
|
|
18
18
|
}
|
|
19
19
|
},
|
|
20
|
-
"main": "./dist/index.
|
|
20
|
+
"main": "./dist/index.cjs",
|
|
21
21
|
"types": "./dist/index.d.ts",
|
|
22
22
|
"files": [
|
|
23
23
|
"dist"
|
|
@@ -25,18 +25,18 @@
|
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@napi-rs/image": "^1.9.2",
|
|
27
27
|
"svgo": "^3.3.2",
|
|
28
|
-
"@rsbuild/shared": "0.
|
|
28
|
+
"@rsbuild/shared": "0.7.0-beta.1"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@types/node": "18.x",
|
|
32
32
|
"typescript": "^5.4.2",
|
|
33
33
|
"webpack": "^5.91.0",
|
|
34
|
-
"@rsbuild/core": "0.
|
|
35
|
-
"@rsbuild/webpack": "0.
|
|
36
|
-
"@scripts/test-helper": "0.
|
|
34
|
+
"@rsbuild/core": "0.7.0-beta.1",
|
|
35
|
+
"@rsbuild/webpack": "0.7.0-beta.1",
|
|
36
|
+
"@scripts/test-helper": "0.7.0-beta.1"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
|
-
"@rsbuild/core": "^0.
|
|
39
|
+
"@rsbuild/core": "^0.7.0-beta.1"
|
|
40
40
|
},
|
|
41
41
|
"publishConfig": {
|
|
42
42
|
"access": "public",
|