pug-site-core 2.0.13 → 2.0.15
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/index.js +2 -2
- package/lib/imagemin.js +18 -1
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { startDevServer } from "./lib/devServer.js";
|
|
2
2
|
import { translateLanguageData } from "./lib/translate.js";
|
|
3
|
-
import {
|
|
3
|
+
import { processImagemin } from "./lib/imagemin.js";
|
|
4
4
|
import {
|
|
5
5
|
generateGetDataFn,
|
|
6
6
|
compilePagesPugToFn,
|
|
@@ -17,7 +17,7 @@ export const pugSiteCore = {
|
|
|
17
17
|
buildFn,
|
|
18
18
|
buildStatic,
|
|
19
19
|
translateLanguageData,
|
|
20
|
-
|
|
20
|
+
processImagemin,
|
|
21
21
|
};
|
|
22
22
|
|
|
23
23
|
let curCmd = process.env.npm_lifecycle_event;
|
package/lib/imagemin.js
CHANGED
|
@@ -74,6 +74,11 @@ export async function compressImages(inputPath, quality = 0.7) {
|
|
|
74
74
|
return acc;
|
|
75
75
|
}, {});
|
|
76
76
|
|
|
77
|
+
// 统计所有图片压缩前后的总大小
|
|
78
|
+
let totalAllOriginalSize = 0;
|
|
79
|
+
let totalAllCompressedSize = 0;
|
|
80
|
+
let totalProcessedFiles = 0;
|
|
81
|
+
|
|
77
82
|
// 处理每个目录中的图片
|
|
78
83
|
for (const [dir, files] of Object.entries(filesByDir)) {
|
|
79
84
|
const relativeDir = path.relative(stats.isFile() ? path.dirname(targetPath) : targetPath, dir);
|
|
@@ -94,7 +99,8 @@ export async function compressImages(inputPath, quality = 0.7) {
|
|
|
94
99
|
continue;
|
|
95
100
|
}
|
|
96
101
|
|
|
97
|
-
|
|
102
|
+
// 显示当前处理的目录的绝对路径
|
|
103
|
+
console.log(`处理目录: ${dir}`);
|
|
98
104
|
|
|
99
105
|
// 压缩图片
|
|
100
106
|
await imagemin(validFiles, {
|
|
@@ -133,7 +139,10 @@ export async function compressImages(inputPath, quality = 0.7) {
|
|
|
133
139
|
if (originalSize > 0 && compressedSize > 0) {
|
|
134
140
|
totalOriginalSize += originalSize;
|
|
135
141
|
totalCompressedSize += compressedSize;
|
|
142
|
+
totalAllOriginalSize += originalSize;
|
|
143
|
+
totalAllCompressedSize += compressedSize;
|
|
136
144
|
processedFiles++;
|
|
145
|
+
totalProcessedFiles++;
|
|
137
146
|
|
|
138
147
|
const savingPercent = ((originalSize - compressedSize) / originalSize * 100).toFixed(2);
|
|
139
148
|
console.log(` ${path.basename(file)}: ${formatBytes(originalSize)} → ${formatBytes(compressedSize)} (节省 ${savingPercent}%)`);
|
|
@@ -149,6 +158,14 @@ export async function compressImages(inputPath, quality = 0.7) {
|
|
|
149
158
|
|
|
150
159
|
const endTime = Date.now();
|
|
151
160
|
console.log(`图片压缩完成,共处理 ${imageFiles.length} 个文件,耗时 ${(endTime - startTime) / 1000} 秒`);
|
|
161
|
+
|
|
162
|
+
// 输出所有图片的总体压缩情况
|
|
163
|
+
if (totalProcessedFiles > 0) {
|
|
164
|
+
const totalAllSavingPercent = ((totalAllOriginalSize - totalAllCompressedSize) / totalAllOriginalSize * 100).toFixed(2);
|
|
165
|
+
const savedSize = formatBytes(Math.abs(totalAllOriginalSize - totalAllCompressedSize));
|
|
166
|
+
console.log(`总体压缩情况: ${formatBytes(totalAllOriginalSize)} → ${formatBytes(totalAllCompressedSize)}`);
|
|
167
|
+
console.log(`共节省: ${savedSize} (${totalAllSavingPercent}%)`);
|
|
168
|
+
}
|
|
152
169
|
} catch (error) {
|
|
153
170
|
console.error('图片压缩失败:', error);
|
|
154
171
|
throw error;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pug-site-core",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.15",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"imagemin-svgo": "^10.0.1"
|
|
46
46
|
},
|
|
47
47
|
"license": "ISC",
|
|
48
|
-
"description": "
|
|
48
|
+
"description": "图片压缩优化",
|
|
49
49
|
"files": [
|
|
50
50
|
"lib/",
|
|
51
51
|
"index.js"
|