imagemin-webp-webpack-plugin icon indicating copy to clipboard operation
imagemin-webp-webpack-plugin copied to clipboard

Add feature to skip unchanged images during refresh

Open nerikosans opened this issue 3 years ago • 11 comments

Hello, thank you for publishing this great plugin.

This pull request fixes #14 , adding skipUnchanged option.

Implementation Summary

When skipUnchanged is true, it stores the SHA-256 hash value of each images to be converted. Like below:

// ImageminWebpWebpackPlugin.sourceVersions
{
  'assets/bicycle_2.webp': 'e3ab38b7bea9e13f7ec748019a92e45b8c13dbafcb612cb07ef59f6dc346a866',
  'assets/cookie-monster.webp': 'ef8a7672e385b4ab734129baf16db2597b19547580c9a88f9a1c81b5faa54953',
  'assets/images/folder.with.dots/inner-folder/bicycle_1.webp': '93cc700fbf54c93c9503166343c9f3d2bfcbc98d2049bc38972e8501d8c26c20'
}

Then during refreshes, conversions are skipped if the target image's hash is already stored.

Note: This implementation is inspired by an official example from webpack for monitoring changed chunks. https://webpack.js.org/contribute/plugin-patterns/#changed-chunks

Experimental results

Experiments on test projects showed this change saves a considerable ratio of runtime. 🎉

Webpack 5: ~800ms → ~150ms

Original With skipUnchanged
screenshot 2022-03-14 16 46 18 screenshot 2022-03-14 16 45 46

It detects and converts newly added/modified images: screenshot 2022-03-14 17 48 49

Webpack 4: ~1300ms → ~350ms

Original With skipUnchanged
screenshot 2022-03-14 16 49 23 screenshot 2022-03-14 16 50 56

nerikosans avatar Mar 14 '22 08:03 nerikosans

Hi @iampava, would you kindly take a look at this? I would appreciate it so much!

nerikosans avatar Apr 14 '22 07:04 nerikosans

+1

georgi-vdimitrov avatar May 30 '22 12:05 georgi-vdimitrov

+1

XenBG avatar May 30 '22 12:05 XenBG

+1

vdzhorov avatar Jun 01 '22 12:06 vdzhorov

+1

lmarkov avatar Jun 01 '22 12:06 lmarkov

+1

gwustick avatar Jun 01 '22 12:06 gwustick

+1

deaniliev avatar Jun 01 '22 12:06 deaniliev

+1

mladen-venkov avatar Jun 01 '22 12:06 mladen-venkov

+1

Radnevec avatar Jun 01 '22 13:06 Radnevec

+1

PlamBG avatar Jun 02 '22 07:06 PlamBG

@iampava Please review this. Seems like a really amazing feature to have.

smisra3 avatar Dec 06 '22 07:12 smisra3