Skip to content

Commit

Permalink
fix: compress plugin not outputting original image
Browse files Browse the repository at this point in the history
  • Loading branch information
Zyie committed Aug 6, 2024
1 parent c428b74 commit 8073c76
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 7 additions & 1 deletion packages/assetpack/src/image/compress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export function compress(options: CompressOptions = {}): AssetPipe<CompressOptio
},
test(asset: Asset, options)
{
return options && checkExt(asset.path, '.png', '.jpg', '.jpeg') && !asset.allMetaData[this.tags!.nc];
return compress && options && checkExt(asset.path, '.png', '.jpg', '.jpeg') && !asset.allMetaData[this.tags!.nc];
},
async transform(asset: Asset, options)
{
Expand Down Expand Up @@ -98,6 +98,12 @@ export function compress(options: CompressOptions = {}): AssetPipe<CompressOptio
return newAsset;
});

// ensure that the original image is passed through if it is not compressed by png/jpg options
if ((image.format === '.png' && !options.png) || (((image.format === '.jpg') || (image.format === '.jpeg')) && !options.jpg))
{
newAssets.push(asset);
}

const promises = processedImages.map((image, i) => image.sharpImage.toBuffer().then((buffer) =>
{
newAssets[i].buffer = buffer;
Expand Down
4 changes: 2 additions & 2 deletions packages/assetpack/test/image/Compress.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ describe('Compress', () =>
cache: false,
pipes: [
compress({
png: true,
png: false,
webp: true,
jpg: true,
jpg: false,
avif: true,
}),
],
Expand Down

0 comments on commit 8073c76

Please sign in to comment.