@divriots/jampack 0.7.1 → 0.7.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.
Files changed (2) hide show
  1. package/dist/optimize.js +16 -10
  2. package/package.json +1 -1
package/dist/optimize.js CHANGED
@@ -273,27 +273,33 @@ async function processImage(htmlfile, $, imgElement, isAboveTheFold) {
273
273
  while (valueW > config.image.srcset_min_width) {
274
274
  const src = imageSrc(`@${valueW}w`);
275
275
  const absoluteFilename = translateSrc($state.dir, path.dirname(htmlfile), src);
276
+ let doAddToSrcSet = true;
276
277
  // Don't generate srcset file twice
277
278
  if (!$state.compressedFiles.has(absoluteFilename)) {
278
- // Add file to list avoid recompression
279
- $state.compressedFiles.add(absoluteFilename);
280
279
  const compressedImage = await compressImage(await originalImage.getData(), {
281
280
  resize: { width: valueW, height: valueH },
282
281
  toFormat: canBeProgressiveJpeg ? 'pjpg' : targetFormat,
283
282
  });
284
283
  if (!(compressedImage === null || compressedImage === void 0 ? void 0 : compressedImage.data) ||
285
284
  compressedImage.data.length >= previousImageSize) {
286
- // jampack was not able to compress below the original image
287
- // Let's move on
288
- continue;
285
+ // New image is not compressed or bigger than previous image in srcset
286
+ // Don't add to srcset
287
+ doAddToSrcSet = false;
289
288
  }
290
- if (!$state.args.nowrite) {
291
- fs.writeFile(absoluteFilename, compressedImage.data);
289
+ else {
290
+ // Write file
291
+ if (!$state.args.nowrite) {
292
+ fs.writeFile(absoluteFilename, compressedImage.data);
293
+ }
294
+ // Set new previous size to beat
295
+ previousImageSize = compressedImage.data.length;
296
+ // Add file to list avoid recompression
297
+ $state.compressedFiles.add(absoluteFilename);
292
298
  }
293
- // Add previous smaller file size
294
- previousImageSize = compressedImage.data.length;
295
299
  }
296
- new_srcset += `, ${src} ${valueW}w`;
300
+ if (doAddToSrcSet) {
301
+ new_srcset += `, ${src} ${valueW}w`;
302
+ }
297
303
  // reduce size
298
304
  valueW -= step;
299
305
  valueH = Math.trunc(valueW / ratio);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@divriots/jampack",
3
- "version": "0.7.1",
3
+ "version": "0.7.2",
4
4
  "description": "Packer for static websites",
5
5
  "author": "Georges Gomes @georges-gomes",
6
6
  "bin": {