Skip to content

Conversation

@jagthedrummer
Copy link
Contributor

@jagthedrummer jagthedrummer commented Sep 10, 2020

Since we store the optimization manifest in the build directory, and since it doesn't have a counterpart in the source directory the ManifestResource needs to behave a little differently than your average resource. Instead of reading a file from source and writing it to build we want to read from build if the file already exists, so that we preserve the contents of that file through the first stage of the build.

In one of my projects this PR takes a 22 minute build down to 2 minutes.

Fixes #60
Fixes #41, Closes #58 (Specifying the manifest path shouldn't be needed if we don't overwrite it, and storing it outside the build directory doesn't exactly make sense since it is an artifact of a particular build, or sequence of builds. To say it another way, if you used an existing manifest with an empty build directory you'd end up skipping optimization of images that would need to be optimized.)

Copy link

@KevinBongart KevinBongart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for looking into this! I authored à related bug fix but looks like yours is a better soltion

def manifest_content
if @source_file.nil?
path = File.join(@app.config[:build_dir], @destination_path)
if !File.exist?(path)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick but this would be generally easier to understand using the positive form:

if File.exists?(path)
  do B
else
  do A
end

Instead of if !x do A else do B

@johnvuko
Copy link

johnvuko commented Jan 4, 2022

Any news on merging this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Imageoptim taking much longer with Middleman > 4.3 Specify manifest file path

3 participants