@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.
- package/dist/optimize.js +16 -10
- 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
|
-
//
|
|
287
|
-
//
|
|
288
|
-
|
|
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
|
-
|
|
291
|
-
|
|
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
|
-
|
|
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);
|