@divriots/jampack 0.9.2 → 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 +42 -49
- package/dist/state.d.ts +0 -1
- package/dist/state.js +0 -1
- package/package.json +2 -5
package/dist/optimize.js
CHANGED
|
@@ -43,6 +43,15 @@ async function analyse(file) {
|
|
|
43
43
|
}
|
|
44
44
|
// Reset spinner
|
|
45
45
|
spinnerImg.text = kleur.dim(`<img> [${imgsArray.length}/${imgsArray.length}]`);
|
|
46
|
+
// Notify issues
|
|
47
|
+
const issues = $state.issues.get(file);
|
|
48
|
+
if (issues) {
|
|
49
|
+
spinnerImg.fail();
|
|
50
|
+
console.log(kleur.red(` ${issues.length} issue${issues.length > 1 ? 's' : ''}`));
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
spinnerImg.succeed();
|
|
54
|
+
}
|
|
46
55
|
const iframes = $('iframe');
|
|
47
56
|
const iframesArray = [];
|
|
48
57
|
iframes.each(async (index, ifElement) => {
|
|
@@ -67,15 +76,7 @@ async function analyse(file) {
|
|
|
67
76
|
}
|
|
68
77
|
// Reset spinner
|
|
69
78
|
spinnerIframe.text = kleur.dim(`<iframe> [${imgsArray.length}/${imgsArray.length}]`);
|
|
70
|
-
|
|
71
|
-
const issues = $state.issues.get(file);
|
|
72
|
-
if (issues) {
|
|
73
|
-
spinnerImg.fail();
|
|
74
|
-
console.log(kleur.red(` ${issues.length} issue${issues.length > 1 ? 's' : ''}`));
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
77
|
-
spinnerImg.succeed();
|
|
78
|
-
}
|
|
79
|
+
spinnerIframe.succeed();
|
|
79
80
|
// Remove the fold
|
|
80
81
|
if (theFold) {
|
|
81
82
|
$('the-fold').remove();
|
|
@@ -226,47 +227,39 @@ async function processImage(htmlfile, $, imgElement, isAboveTheFold) {
|
|
|
226
227
|
? 'unchanged'
|
|
227
228
|
: 'webp';
|
|
228
229
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
) {
|
|
239
|
-
|
|
240
|
-
const newExtension = `.${newImage.format}`;
|
|
241
|
-
const additionalExtension = path.extname(originalImage.filePathAbsolute) === newExtension
|
|
242
|
-
? ''
|
|
243
|
-
: newExtension;
|
|
244
|
-
const newFilename = originalImage.filePathAbsolute + additionalExtension;
|
|
245
|
-
if (!$state.args.nowrite) {
|
|
246
|
-
fs.writeFile(newFilename, newImage.data);
|
|
247
|
-
}
|
|
248
|
-
// Mark new file as optimized
|
|
249
|
-
$state.compressedFiles.add(newFilename);
|
|
250
|
-
// Report compression result
|
|
251
|
-
$state.reportSummary({
|
|
252
|
-
action: newFilename !== originalImage.filePathAbsolute
|
|
253
|
-
? `${await originalImage.getExt()}->${newImage.format}`
|
|
254
|
-
: path.extname(originalImage.filePathAbsolute),
|
|
255
|
-
originalSize: await originalImage.getLen(),
|
|
256
|
-
compressedSize: newImage.data.length,
|
|
257
|
-
});
|
|
258
|
-
img.attr('src', attrib_src + additionalExtension);
|
|
259
|
-
}
|
|
260
|
-
else {
|
|
261
|
-
// Drop new Image
|
|
262
|
-
newImage = undefined;
|
|
263
|
-
// Report non-compression
|
|
264
|
-
$state.reportSummary({
|
|
265
|
-
action: path.extname(originalImage.filePathAbsolute),
|
|
266
|
-
originalSize: await originalImage.getLen(),
|
|
267
|
-
compressedSize: await originalImage.getLen(),
|
|
268
|
-
});
|
|
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);
|
|
269
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
|
+
});
|
|
270
263
|
}
|
|
271
264
|
/*
|
|
272
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
|
},
|