diff --git a/packages/assetpack/src/image/mipmap.ts b/packages/assetpack/src/image/mipmap.ts index 1c1cbd4..2ef0cf5 100644 --- a/packages/assetpack/src/image/mipmap.ts +++ b/packages/assetpack/src/image/mipmap.ts @@ -51,30 +51,34 @@ export function mipmap(_options: MipmapOptions = {}): AssetPipe + || this.defaultOptions; + + const fixedResolutions = { + [fixedResolution]: resolutions[fixedResolution] + }; + + const largestResolution = Math.max(...Object.values(resolutions)); + try { if (shouldMipmap) { - const { resolutions, fixedResolution } = options as Required - || this.defaultOptions; - - const fixedResolutions: {[x: string]: number} = {}; - - fixedResolutions[fixedResolution] = resolutions[fixedResolution]; - const resolutionHash = asset.allMetaData[this.tags!.fix] ? fixedResolutions : resolutions; - const largestResolution = Math.max(...Object.values(resolutions)); - image.resolution = largestResolution; - processedImages = shouldMipmap ? await mipmapSharp(image, resolutionHash, largestResolution) : [image]; + processedImages = await mipmapSharp(image, resolutionHash, largestResolution); } else { - processedImages = [image]; + image.resolution = fixedResolutions[fixedResolution]; + + processedImages = image.resolution === 1 + ? [image] + : processedImages = await mipmapSharp(image, fixedResolutions, largestResolution); } } catch (error) diff --git a/packages/assetpack/test/image/Mipmap.test.ts b/packages/assetpack/test/image/Mipmap.test.ts index 39f9797..3b5de2e 100644 --- a/packages/assetpack/test/image/Mipmap.test.ts +++ b/packages/assetpack/test/image/Mipmap.test.ts @@ -77,7 +77,7 @@ describe('Mipmap', () => name: testName, files: [ { - name: 'testPng.png', + name: 'testPng{fix}.png', content: assetPath('image/png-1.png'), }, ], @@ -85,7 +85,7 @@ describe('Mipmap', () => }); const mipmapOpts = { - resolutions: { low: 0.5 }, + resolutions: { low: 0.5, default: 1 }, fixedResolution: 'low' }; @@ -147,7 +147,7 @@ describe('Mipmap', () => it('should prevent mipmaps on file when tagged with fix', async () => { - const testName = 'mip-fixed'; + const testName = 'mip-fixed-prevent'; const inputDir = getInputDir(pkg, testName); const outputDir = getOutputDir(pkg, testName);