@divriots/jampack 0.9.3 → 0.9.4
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 +32 -40
- package/dist/state.d.ts +0 -1
- package/dist/state.js +0 -1
- package/package.json +2 -5
package/dist/optimize.js
CHANGED
|
@@ -227,47 +227,39 @@ async function processImage(htmlfile, $, imgElement, isAboveTheFold) {
|
|
|
227
227
|
? 'unchanged'
|
|
228
228
|
: 'webp';
|
|
229
229
|
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
) {
|
|
240
|
-
|
|
241
|
-
const newExtension = `.${newImage.format}`;
|
|
242
|
-
const additionalExtension = path.extname(originalImage.filePathAbsolute) === newExtension
|
|
243
|
-
? ''
|
|
244
|
-
: newExtension;
|
|
245
|
-
const newFilename = originalImage.filePathAbsolute + additionalExtension;
|
|
246
|
-
if (!$state.args.nowrite) {
|
|
247
|
-
fs.writeFile(newFilename, newImage.data);
|
|
248
|
-
}
|
|
249
|
-
// Mark new file as optimized
|
|
250
|
-
$state.compressedFiles.add(newFilename);
|
|
251
|
-
// Report compression result
|
|
252
|
-
$state.reportSummary({
|
|
253
|
-
action: newFilename !== originalImage.filePathAbsolute
|
|
254
|
-
? `${await originalImage.getExt()}->${newImage.format}`
|
|
255
|
-
: path.extname(originalImage.filePathAbsolute),
|
|
256
|
-
originalSize: await originalImage.getLen(),
|
|
257
|
-
compressedSize: newImage.data.length,
|
|
258
|
-
});
|
|
259
|
-
img.attr('src', attrib_src + additionalExtension);
|
|
260
|
-
}
|
|
261
|
-
else {
|
|
262
|
-
// Drop new Image
|
|
263
|
-
newImage = undefined;
|
|
264
|
-
// Report non-compression
|
|
265
|
-
$state.reportSummary({
|
|
266
|
-
action: path.extname(originalImage.filePathAbsolute),
|
|
267
|
-
originalSize: await originalImage.getLen(),
|
|
268
|
-
compressedSize: await originalImage.getLen(),
|
|
269
|
-
});
|
|
230
|
+
newImage = await compressImage(await originalImage.getData(), {
|
|
231
|
+
toFormat: srcToFormat,
|
|
232
|
+
});
|
|
233
|
+
if ((newImage === null || newImage === void 0 ? void 0 : newImage.data) &&
|
|
234
|
+
(newImage.data.length < (await originalImage.getLen()) ||
|
|
235
|
+
srcToFormat === 'jpeg+progressive') // Progressive override all even if worse
|
|
236
|
+
) {
|
|
237
|
+
const additionalExtension = `.${newImage.format}`;
|
|
238
|
+
const newFilename = originalImage.filePathAbsolute + additionalExtension;
|
|
239
|
+
if (!$state.compressedFiles.has(newFilename) && !$state.args.nowrite) {
|
|
240
|
+
fs.writeFile(newFilename, newImage.data);
|
|
270
241
|
}
|
|
242
|
+
// Mark new file as compressed
|
|
243
|
+
$state.compressedFiles.add(newFilename);
|
|
244
|
+
// Report compression result
|
|
245
|
+
$state.reportSummary({
|
|
246
|
+
action: newFilename !== originalImage.filePathAbsolute
|
|
247
|
+
? `${await originalImage.getExt()}->${newImage.format}`
|
|
248
|
+
: path.extname(originalImage.filePathAbsolute),
|
|
249
|
+
originalSize: await originalImage.getLen(),
|
|
250
|
+
compressedSize: newImage.data.length,
|
|
251
|
+
});
|
|
252
|
+
img.attr('src', attrib_src + additionalExtension);
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
// Drop new Image
|
|
256
|
+
newImage = undefined;
|
|
257
|
+
// Report non-compression
|
|
258
|
+
$state.reportSummary({
|
|
259
|
+
action: path.extname(originalImage.filePathAbsolute),
|
|
260
|
+
originalSize: await originalImage.getLen(),
|
|
261
|
+
compressedSize: await originalImage.getLen(),
|
|
262
|
+
});
|
|
271
263
|
}
|
|
272
264
|
/*
|
|
273
265
|
* Embed small images
|
package/dist/state.d.ts
CHANGED
package/dist/state.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@divriots/jampack",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.4",
|
|
4
4
|
"description": "Packer for static websites",
|
|
5
5
|
"author": "Georges Gomes @georges-gomes",
|
|
6
6
|
"bin": {
|
|
@@ -18,13 +18,10 @@
|
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@swc/core": "^1.3.30",
|
|
20
20
|
"@types/cheerio": "^0.22.31",
|
|
21
|
-
"@types/commander": "^2.12.2",
|
|
22
21
|
"@types/csso": "^5.0.0",
|
|
23
22
|
"@types/html-minifier-terser": "^7.0.0",
|
|
24
|
-
"@types/ora": "^3.2.0",
|
|
25
23
|
"@types/sharp": "^0.31.1",
|
|
26
24
|
"@types/svgo": "^2.6.4",
|
|
27
|
-
"@types/table": "^6.3.2",
|
|
28
25
|
"cheerio": "0.22.0",
|
|
29
26
|
"commander": "^9.4.1",
|
|
30
27
|
"csso": "^5.0.5",
|
|
@@ -49,7 +46,7 @@
|
|
|
49
46
|
},
|
|
50
47
|
"scripts": {
|
|
51
48
|
"watch": "pnpm build --watch",
|
|
52
|
-
"try": "shx rm -fr demo && cp -R
|
|
49
|
+
"try": "shx rm -fr demo && cp -R demo_rf demo && node ./dist/index.js ./demo --nocache --onlyoptim",
|
|
53
50
|
"build": "shx rm -rf dist && tsc -b",
|
|
54
51
|
"lint": "eslint . --ext .ts --config .eslintrc"
|
|
55
52
|
},
|