From 8aeb2036e252f2217e6b5390f34222c70732ee59 Mon Sep 17 00:00:00 2001 From: ungvert Date: Fri, 26 Jun 2020 15:52:41 +0300 Subject: [PATCH 1/3] fix(gatsby-transformer-sharp): removed unnecessary conversion to webp --- packages/gatsby-plugin-sharp/src/process-file.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/packages/gatsby-plugin-sharp/src/process-file.js b/packages/gatsby-plugin-sharp/src/process-file.js index db595f828d716..f1c790b1d0d6d 100644 --- a/packages/gatsby-plugin-sharp/src/process-file.js +++ b/packages/gatsby-plugin-sharp/src/process-file.js @@ -116,10 +116,6 @@ exports.processFile = (file, transforms, options = {}) => { adaptiveFiltering: false, force: transformArgs.toFormat === `png`, }) - .webp({ - quality: transformArgs.webpQuality || transformArgs.quality, - force: transformArgs.toFormat === `webp`, - }) .tiff({ quality: transformArgs.quality, force: transformArgs.toFormat === `tiff`, From d8db0b3c426f476d0f404e71e573583a18af41b9 Mon Sep 17 00:00:00 2001 From: ungvert Date: Mon, 29 Jun 2020 21:08:32 +0300 Subject: [PATCH 2/3] Restore deleted code, which converts to webp with `sharp` and added condition to not convert to webp with `imagemin` second time in Windows. --- packages/gatsby-plugin-sharp/src/process-file.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/gatsby-plugin-sharp/src/process-file.js b/packages/gatsby-plugin-sharp/src/process-file.js index f1c790b1d0d6d..9469538333daa 100644 --- a/packages/gatsby-plugin-sharp/src/process-file.js +++ b/packages/gatsby-plugin-sharp/src/process-file.js @@ -116,6 +116,10 @@ exports.processFile = (file, transforms, options = {}) => { adaptiveFiltering: false, force: transformArgs.toFormat === `png`, }) + .webp({ + quality: transformArgs.webpQuality || transformArgs.quality, + force: transformArgs.toFormat === `webp`, + }) .tiff({ quality: transformArgs.quality, force: transformArgs.toFormat === `tiff`, @@ -225,8 +229,11 @@ const compressJpg = (pipeline, outputPath, options) => ) const compressWebP = (pipeline, outputPath, options) => - pipeline.toBuffer().then(sharpBuffer => - imagemin + pipeline.toBuffer().then(sharpBuffer => { + if (process.platform === `win32`) { + return fs.writeFile(outputPath, sharpBuffer) + } + return imagemin .buffer(sharpBuffer, { plugins: [ imageminWebp({ @@ -236,7 +243,7 @@ const compressWebP = (pipeline, outputPath, options) => ], }) .then(imageminBuffer => fs.writeFile(outputPath, imageminBuffer)) - ) + }) exports.createArgsDigest = args => { const argsDigest = createContentDigest(args) From 877e5778fca3514a254f7db32218dd379573b88c Mon Sep 17 00:00:00 2001 From: ungvert Date: Wed, 1 Jul 2020 14:09:46 +0300 Subject: [PATCH 3/3] Deleted everything related to imagemin-webp --- packages/gatsby-plugin-sharp/package.json | 1 - .../gatsby-plugin-sharp/src/process-file.js | 23 ------------------- .../__tests__/fixtures/kitchen-sink.json | 4 ---- 3 files changed, 28 deletions(-) diff --git a/packages/gatsby-plugin-sharp/package.json b/packages/gatsby-plugin-sharp/package.json index 7fd05814fc8b0..9add02791bb03 100644 --- a/packages/gatsby-plugin-sharp/package.json +++ b/packages/gatsby-plugin-sharp/package.json @@ -16,7 +16,6 @@ "imagemin": "^6.1.0", "imagemin-mozjpeg": "^8.0.0", "imagemin-pngquant": "^6.0.1", - "imagemin-webp": "^5.1.0", "lodash": "^4.17.15", "mini-svg-data-uri": "^1.2.3", "potrace": "^2.1.6", diff --git a/packages/gatsby-plugin-sharp/src/process-file.js b/packages/gatsby-plugin-sharp/src/process-file.js index 9469538333daa..e198466b13108 100644 --- a/packages/gatsby-plugin-sharp/src/process-file.js +++ b/packages/gatsby-plugin-sharp/src/process-file.js @@ -6,7 +6,6 @@ const duotone = require(`./duotone`) const imagemin = require(`imagemin`) const imageminMozjpeg = require(`imagemin-mozjpeg`) const imageminPngquant = require(`imagemin-pngquant`) -const imageminWebp = require(`imagemin-webp`) const { healOptions } = require(`./plugin-options`) const { SharpError } = require(`./sharp-error`) const { cpuCoreCount, createContentDigest } = require(`gatsby-core-utils`) @@ -169,11 +168,6 @@ exports.processFile = (file, transforms, options = {}) => { return transform } - if (transformArgs.toFormat === `webp`) { - await compressWebP(clonedPipeline, outputPath, transformArgs) - return transform - } - try { await clonedPipeline.toFile(outputPath) } catch (err) { @@ -228,23 +222,6 @@ const compressJpg = (pipeline, outputPath, options) => .then(imageminBuffer => fs.writeFile(outputPath, imageminBuffer)) ) -const compressWebP = (pipeline, outputPath, options) => - pipeline.toBuffer().then(sharpBuffer => { - if (process.platform === `win32`) { - return fs.writeFile(outputPath, sharpBuffer) - } - return imagemin - .buffer(sharpBuffer, { - plugins: [ - imageminWebp({ - quality: options.webpQuality || options.quality, - metadata: options.stripMetadata ? `none` : `all`, - }), - ], - }) - .then(imageminBuffer => fs.writeFile(outputPath, imageminBuffer)) - }) - exports.createArgsDigest = args => { const argsDigest = createContentDigest(args) diff --git a/packages/gatsby/src/schema/__tests__/fixtures/kitchen-sink.json b/packages/gatsby/src/schema/__tests__/fixtures/kitchen-sink.json index a412e7d84331e..183535aaf2f1c 100644 --- a/packages/gatsby/src/schema/__tests__/fixtures/kitchen-sink.json +++ b/packages/gatsby/src/schema/__tests__/fixtures/kitchen-sink.json @@ -380,10 +380,6 @@ "name": "imagemin-pngquant", "version": "^6.0.0" }, - { - "name": "imagemin-webp", - "version": "^5.0.0" - }, { "name": "lodash", "version": "^4.17.10"