@drovp/optimize
Advanced tools
Comparing version 5.0.1 to 5.1.0
@@ -34,3 +34,3 @@ "use strict"; | ||
let outputBuffer; | ||
let plugin; | ||
let optimizer; | ||
switch (encoder) { | ||
@@ -43,3 +43,3 @@ case 'mozjpeg': { | ||
delete pluginOptions.smooth; | ||
plugin = require('imagemin-mozjpeg')(pluginOptions); | ||
optimizer = (await nativeImport('imagemin-mozjpeg')).default(pluginOptions); | ||
break; | ||
@@ -65,13 +65,13 @@ } | ||
delete pluginOptions.size; | ||
plugin = require('imagemin-webp')({ ...pluginOptions, size }); | ||
optimizer = (await nativeImport('imagemin-webp')).default({ ...pluginOptions, size }); | ||
break; | ||
} | ||
case 'pngquant': | ||
plugin = require('imagemin-pngquant')(options.pngquant); | ||
optimizer = (await nativeImport('imagemin-pngquant')).default(options.pngquant); | ||
break; | ||
case 'optipng': | ||
plugin = require('imagemin-optipng')(options.optipng); | ||
optimizer = (await nativeImport('imagemin-optipng')).default(options.optipng); | ||
break; | ||
case 'gifsicle': | ||
plugin = require('imagemin-gifsicle')(options.gifsicle); | ||
optimizer = (await nativeImport('imagemin-gifsicle')).default(options.gifsicle); | ||
break; | ||
@@ -88,3 +88,3 @@ case 'gif2webp': | ||
delete pluginOptions.mode; | ||
plugin = require('imagemin-gif2webp')(pluginOptions); | ||
optimizer = (await nativeImport('imagemin-gif2webp')).default(pluginOptions); | ||
break; | ||
@@ -97,8 +97,7 @@ case 'svgo': { | ||
} | ||
plugin = (await nativeImport('imagemin-svgo')).default({ plugins }); | ||
optimizer = (await nativeImport('imagemin-svgo')).default({ plugins }); | ||
break; | ||
} | ||
} | ||
const { default: imagemin } = await nativeImport('imagemin'); | ||
outputBuffer = await imagemin.buffer(inputBuffer, { plugins: [plugin] }); | ||
outputBuffer = await optimizer(inputBuffer); | ||
if (!outputBuffer) { | ||
@@ -118,3 +117,20 @@ console.error(`imagemin didn't produce any output.`); | ||
}); | ||
output.file(outputPath); | ||
const savings = ((inputBuffer.byteLength - outputBuffer.byteLength) / inputBuffer.byteLength) * -1; | ||
const savingsPercent = numberToPercent(savings); | ||
output.file(outputPath, { | ||
flair: savings < 0 | ||
? { | ||
variant: 'success', | ||
title: savingsPercent, | ||
description: `Result is ${savingsPercent} smaller than the original.`, | ||
} | ||
: { | ||
variant: 'danger', | ||
title: `+${savingsPercent}`, | ||
description: `Result is ${savingsPercent} larger than the original.`, | ||
}, | ||
}); | ||
}; | ||
function numberToPercent(value) { | ||
return `${(value * 100).toFixed(Math.abs(value) > 0.01 ? 0 : 1)}%`; | ||
} |
{ | ||
"name": "@drovp/optimize", | ||
"version": "5.0.1", | ||
"version": "5.1.0", | ||
"description": "Perceptually lossless png, jpg, svg, webp, and gif size optimization.", | ||
@@ -52,16 +52,15 @@ "homepage": "https://github.com/drovp/optimize", | ||
"tslib": "^2.3.1", | ||
"typescript": "^4.5.2" | ||
"typescript": "^4.6.3" | ||
}, | ||
"dependencies": { | ||
"@drovp/save-as-path": "^2.0.0", | ||
"@drovp/types": "^3.0.2", | ||
"imagemin": "^8.0.1", | ||
"@drovp/types": "^4.2.1", | ||
"imagemin-gif2webp": "^3.0.0", | ||
"imagemin-gifsicle": "^7.0.0", | ||
"imagemin-mozjpeg": "^9.0.0", | ||
"imagemin-mozjpeg": "^10.0.0", | ||
"imagemin-optipng": "^8.0.0", | ||
"imagemin-pngquant": "^9.0.2", | ||
"imagemin-svgo": "^10.0.0", | ||
"imagemin-webp": "^6.0.0" | ||
"imagemin-webp": "^7.0.0" | ||
} | ||
} |
@@ -9,6 +9,13 @@ # @drovp/optimize | ||
- JPG: mozjpeg, libwebp | ||
- PNG: pngquant, optipng, libwebp | ||
- WEBP: libwebp | ||
- GIF: gifsicle, gif2webp | ||
- SVG: svgo | ||
- JPG: mozjpeg, libwebp | ||
- PNG: pngquant, optipng, libwebp | ||
- WEBP: libwebp | ||
- GIF: gifsicle, gif2webp | ||
- SVG: svgo | ||
## Changelog | ||
### 5.1.0 | ||
- Added output flairs with file size savings percentage. | ||
- Updated dependencies. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
39879
9
1023
21
+ Added@drovp/types@4.11.0(transitive)
+ Addedcwebp-bin@7.0.1(transitive)
+ Addedexeca@6.1.0(transitive)
+ Addedhuman-signals@3.0.1(transitive)
+ Addedimagemin-mozjpeg@10.0.0(transitive)
+ Addedimagemin-webp@7.0.0(transitive)
+ Addedis-jpg@3.0.0(transitive)
+ Addedis-stream@3.0.0(transitive)
+ Addedmimic-fn@4.0.0(transitive)
+ Addedmozjpeg@8.0.0(transitive)
+ Addednpm-run-path@5.3.0(transitive)
+ Addedonetime@6.0.0(transitive)
+ Addedpath-key@4.0.0(transitive)
+ Addedstrip-final-newline@3.0.0(transitive)
- Removedimagemin@^8.0.1
- Removed@drovp/types@3.1.0(transitive)
- Removed@nodelib/fs.scandir@2.1.5(transitive)
- Removed@nodelib/fs.stat@2.0.5(transitive)
- Removed@nodelib/fs.walk@1.2.8(transitive)
- Removed@tokenizer/token@0.3.0(transitive)
- Removedarray-union@3.0.1(transitive)
- Removedbraces@3.0.3(transitive)
- Removedcwebp-bin@6.1.2(transitive)
- Removeddir-glob@3.0.1(transitive)
- Removedfast-glob@3.3.2(transitive)
- Removedfastq@1.17.1(transitive)
- Removedfile-type@16.5.4(transitive)
- Removedfill-range@7.1.1(transitive)
- Removedglob-parent@5.1.2(transitive)
- Removedglobby@12.2.0(transitive)
- Removedignore@5.3.2(transitive)
- Removedimagemin@8.0.1(transitive)
- Removedimagemin-mozjpeg@9.0.0(transitive)
- Removedimagemin-webp@6.1.0(transitive)
- Removedis-extglob@2.1.1(transitive)
- Removedis-glob@4.0.3(transitive)
- Removedis-jpg@2.0.0(transitive)
- Removedis-number@7.0.0(transitive)
- Removedjunk@3.1.0(transitive)
- Removedmerge2@1.4.1(transitive)
- Removedmicromatch@4.0.8(transitive)
- Removedmozjpeg@7.1.1(transitive)
- Removedp-pipe@4.0.0(transitive)
- Removedpath-type@4.0.0(transitive)
- Removedpeek-readable@4.1.0(transitive)
- Removedpicomatch@2.3.1(transitive)
- Removedqueue-microtask@1.2.3(transitive)
- Removedreadable-web-to-node-stream@3.0.2(transitive)
- Removedreplace-ext@2.0.0(transitive)
- Removedreusify@1.0.4(transitive)
- Removedrun-parallel@1.2.0(transitive)
- Removedslash@3.0.04.0.0(transitive)
- Removedstrtok3@6.3.0(transitive)
- Removedto-regex-range@5.0.1(transitive)
- Removedtoken-types@4.2.1(transitive)
Updated@drovp/types@^4.2.1
Updatedimagemin-mozjpeg@^10.0.0
Updatedimagemin-webp@^7.0.0