You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, all images get recompressed whenever any single image changes.
Ideally, we could only compress any new files, but we also need to be mindful of deleting any files in lib that are deleted in src. Clearing out the lib folder takes care of this easily, but not intelligently.
onchange is watching the filesystem and does actually emit events. Sort of. It's built on top of chokidar and passes its events along, which gives us add, change, and unlink.
NPM scripts don't make parameters easy, but you can get there. So, if the change is add we can compress just one file. If the change is unlink we can rm that same file. But if the change is change we'll know the original file that changed, but not what it changed to and therefore we can't grab just that changed file for compression.
Okay, but add/unlink are already wins, so even if we clear the folder and recompress everything on the change event, that's still more efficient and somewhat smarter:
Unfortunately, this never really worked. I sporadically got zero-byte files in lib and it was just generally more flaky and unreliable than the nuclear option of just running imagemin on the whole directory every time--which is where we started and now where we've ended up. Ugh.
Leaving this open so no one has to throw quite as many hours into getting this far as I did and maybe someone can do this in a way that actually works one day....
The text was updated successfully, but these errors were encountered:
Currently, all images get recompressed whenever any single image changes.
Ideally, we could only compress any new files, but we also need to be mindful of deleting any files in
lib
that are deleted insrc
. Clearing out thelib
folder takes care of this easily, but not intelligently.onchange is watching the filesystem and does actually emit events. Sort of. It's built on top of chokidar and passes its events along, which gives us
add
,change
, andunlink
.NPM scripts don't make parameters easy, but you can get there. So, if the change is
add
we can compress just one file. If the change isunlink
we canrm
that same file. But if the change ischange
we'll know the original file that changed, but not what it changed to and therefore we can't grab just that changed file for compression.Okay, but
add
/unlink
are already wins, so even if we clear the folder and recompress everything on thechange
event, that's still more efficient and somewhat smarter:Unfortunately, this never really worked. I sporadically got zero-byte files in
lib
and it was just generally more flaky and unreliable than the nuclear option of just runningimagemin
on the whole directory every time--which is where we started and now where we've ended up. Ugh.Leaving this open so no one has to throw quite as many hours into getting this far as I did and maybe someone can do this in a way that actually works one day....
The text was updated successfully, but these errors were encountered: