@rsbuild/plugin-image-compress 0.2.18 → 0.3.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/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  # Rsbuild
6
6
 
7
- Unleash the power of Rspack with the out-of-the-box build tool.
7
+ The Rspack-based build tool. It's fast, out-of-the-box and extensible.
8
8
 
9
9
  ## Documentation
10
10
 
package/dist/index.d.ts CHANGED
@@ -7,7 +7,7 @@ interface CodecBaseOptions {
7
7
  jpeg: JpegCompressOptions;
8
8
  png: PngQuantOptions;
9
9
  pngLossless: PNGLosslessOptions;
10
- ico: {};
10
+ ico: Record<string, never>;
11
11
  svg: Config;
12
12
  }
13
13
  interface BaseCompressOptions<T extends Codecs> {
package/dist/index.js CHANGED
@@ -5,6 +5,7 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
9
  var __export = (target, all) => {
9
10
  for (var name in all)
10
11
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -26,6 +27,10 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
27
  mod
27
28
  ));
28
29
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+ var __publicField = (obj, key, value) => {
31
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
32
+ return value;
33
+ };
29
34
 
30
35
  // src/index.ts
31
36
  var src_exports = {};
@@ -48,7 +53,7 @@ var jpegCodec = {
48
53
  return (0, import_image.compressJpeg)(buf, options);
49
54
  },
50
55
  defaultOptions: {
51
- test: /\.(jpg|jpeg)$/
56
+ test: /\.(?:jpg|jpeg)$/
52
57
  }
53
58
  };
54
59
  var pngCodec = {
@@ -72,7 +77,7 @@ var icoCodec = {
72
77
  return new import_image.Transformer(buf).ico();
73
78
  },
74
79
  defaultOptions: {
75
- test: /\.(ico|icon)$/
80
+ test: /\.(?:ico|icon)$/
76
81
  }
77
82
  };
78
83
  var svgCodec = {
@@ -97,7 +102,8 @@ var codecs_default = codecs;
97
102
  var IMAGE_MINIMIZER_PLUGIN_NAME = "@rsbuild/plugin-image-compress/minimizer";
98
103
  var ImageMinimizerPlugin = class {
99
104
  constructor(options) {
100
- this.name = IMAGE_MINIMIZER_PLUGIN_NAME;
105
+ __publicField(this, "name", IMAGE_MINIMIZER_PLUGIN_NAME);
106
+ __publicField(this, "options");
101
107
  this.options = options;
102
108
  }
103
109
  async optimize(compiler, compilation, assets) {
@@ -109,7 +115,9 @@ var ImageMinimizerPlugin = class {
109
115
  const message = file && context ? `"${file}" in "${context}" from Image Minimizer:
110
116
  ${cause.message}` : cause.message;
111
117
  const ret = new compiler.webpack.WebpackError(message);
112
- error instanceof Error && (ret.error = error);
118
+ if (error instanceof Error) {
119
+ ret.error = error;
120
+ }
113
121
  return ret;
114
122
  };
115
123
  const codec = codecs_default[this.options.use];
package/dist/index.mjs CHANGED
@@ -1,3 +1,10 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => {
4
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ return value;
6
+ };
7
+
1
8
  // ../../node_modules/.pnpm/@modern-js+module-tools@2.45.0_typescript@5.3.2/node_modules/@modern-js/module-tools/shims/esm.js
2
9
  import { fileURLToPath } from "url";
3
10
  import path from "path";
@@ -10,10 +17,10 @@ global.require = createRequire(import.meta.url);
10
17
  import assert2 from "assert";
11
18
 
12
19
  // src/minimizer.ts
13
- import { Buffer as Buffer2 } from "buffer";
20
+ import { Buffer as Buffer3 } from "buffer";
14
21
 
15
22
  // src/shared/codecs.ts
16
- import { Buffer } from "buffer";
23
+ import { Buffer as Buffer2 } from "buffer";
17
24
  import {
18
25
  compressJpeg,
19
26
  losslessCompressPng,
@@ -26,7 +33,7 @@ var jpegCodec = {
26
33
  return compressJpeg(buf, options);
27
34
  },
28
35
  defaultOptions: {
29
- test: /\.(jpg|jpeg)$/
36
+ test: /\.(?:jpg|jpeg)$/
30
37
  }
31
38
  };
32
39
  var pngCodec = {
@@ -50,13 +57,13 @@ var icoCodec = {
50
57
  return new Transformer(buf).ico();
51
58
  },
52
59
  defaultOptions: {
53
- test: /\.(ico|icon)$/
60
+ test: /\.(?:ico|icon)$/
54
61
  }
55
62
  };
56
63
  var svgCodec = {
57
64
  async handler(buf, options) {
58
65
  const result = svgo.optimize(buf.toString(), options);
59
- return Buffer.from(result.data);
66
+ return Buffer2.from(result.data);
60
67
  },
61
68
  defaultOptions: {
62
69
  test: /\.svg$/
@@ -75,7 +82,8 @@ var codecs_default = codecs;
75
82
  var IMAGE_MINIMIZER_PLUGIN_NAME = "@rsbuild/plugin-image-compress/minimizer";
76
83
  var ImageMinimizerPlugin = class {
77
84
  constructor(options) {
78
- this.name = IMAGE_MINIMIZER_PLUGIN_NAME;
85
+ __publicField(this, "name", IMAGE_MINIMIZER_PLUGIN_NAME);
86
+ __publicField(this, "options");
79
87
  this.options = options;
80
88
  }
81
89
  async optimize(compiler, compilation, assets) {
@@ -87,7 +95,9 @@ var ImageMinimizerPlugin = class {
87
95
  const message = file && context ? `"${file}" in "${context}" from Image Minimizer:
88
96
  ${cause.message}` : cause.message;
89
97
  const ret = new compiler.webpack.WebpackError(message);
90
- error instanceof Error && (ret.error = error);
98
+ if (error instanceof Error) {
99
+ ret.error = error;
100
+ }
91
101
  return ret;
92
102
  };
93
103
  const codec = codecs_default[this.options.use];
@@ -110,7 +120,7 @@ ${cause.message}` : cause.message;
110
120
  try {
111
121
  if (!result) {
112
122
  const input = inputSource.source();
113
- const buf = await codec.handler(Buffer2.from(input), opts);
123
+ const buf = await codec.handler(Buffer3.from(input), opts);
114
124
  result = { source: new RawSource(buf) };
115
125
  await cacheItem.storePromise(result);
116
126
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/plugin-image-compress",
3
- "version": "0.2.18",
3
+ "version": "0.3.1",
4
4
  "description": "Image compress plugin for Rsbuild",
5
5
  "homepage": "https://rsbuild.dev",
6
6
  "repository": {
@@ -24,16 +24,16 @@
24
24
  ],
25
25
  "dependencies": {
26
26
  "@napi-rs/image": "^1.7.0",
27
- "svgo": "^3.0.2",
28
- "@rsbuild/shared": "0.2.18"
27
+ "svgo": "^3.2.0",
28
+ "@rsbuild/shared": "0.3.1"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@types/node": "16.x",
32
32
  "typescript": "^5.3.0",
33
33
  "webpack": "^5.89.0",
34
- "@rsbuild/test-helper": "0.2.18",
35
- "@rsbuild/core": "0.2.18",
36
- "@rsbuild/webpack": "0.2.18"
34
+ "@rsbuild/core": "0.3.1",
35
+ "@rsbuild/webpack": "0.3.1",
36
+ "@scripts/test-helper": "1.0.0"
37
37
  },
38
38
  "publishConfig": {
39
39
  "access": "public",