mirror of
https://github.com/LukeHagar/website.git
synced 2025-12-09 12:57:48 +00:00
Update optimize-assets.js
This commit is contained in:
@@ -8,7 +8,7 @@ const __dirname = fileURLToPath(new URL('.', import.meta.url));
|
||||
const config = {
|
||||
jpeg: { quality: 80 },
|
||||
webp: { quality: 80 },
|
||||
png: { compressionLevel: 8 },
|
||||
png: { compressionLevel: 9 },
|
||||
gif: { quality: 80 }
|
||||
};
|
||||
|
||||
@@ -39,8 +39,12 @@ async function main() {
|
||||
console.log(file);
|
||||
|
||||
const image = sharp(file);
|
||||
const size_before = (await image.toBuffer()).length;
|
||||
const meta = await image.metadata();
|
||||
const buffer = await image[meta.format](config[meta.format]).toBuffer();
|
||||
const size_after = buffer.length;
|
||||
if (size_after >= size_before) continue;
|
||||
|
||||
await sharp(buffer).toFile(file);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user