Skip to content

Commit

Permalink
compress image option also used in pass 2
Browse files Browse the repository at this point in the history
  • Loading branch information
georges-gomes committed Apr 19, 2024
1 parent 7c8445b commit 7f92f3d
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/compress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Stats } from 'fs';
import * as fs from 'fs/promises';
import * as path from 'path';
import { formatBytes } from './utils.js';
import config from './config.js';
import $state, { ReportItem } from './state.js';
import { globby } from 'globby';
import ora from 'ora';
Expand All @@ -23,10 +24,12 @@ const processFile = async (file: string, stats: Stats): Promise<void> => {
case '.svg':
case '.webp':
case '.avif':
const imgData = await fs.readFile(file);
const newImage = await compressImage(imgData, {});
if (newImage?.data && newImage.data.length < stats.size) {
writeData = newImage.data;
if (config.image.compress) {
const imgData = await fs.readFile(file);
const newImage = await compressImage(imgData, {});
if (newImage?.data && newImage.data.length < stats.size) {
writeData = newImage.data;
}
}
break;
case '.html':
Expand Down

0 comments on commit 7f92f3d

Please sign in to comment.