Is there a way in Config to wait for Webpack to Complete

I want Webpack to complete before the Ready Do command is fired

Trouble is the Ready do command listed below completes before Webpack - and Webpack seems to then destroy the options set - running this without Webpack I can see the options are in place.

##
# External pipeline - Webpack
##
activate :external_pipeline do | i |

    i.name                         = :webpack
    i.command                      = build? ? './node_modules/webpack/bin/webpack.js --bail -p' : './node_modules/webpack/bin/webpack.js --watch -d'
    i.source                       = ".tmp/dist"
    i.latency                      = 0
    i.disable_background_execution = false

end


ready do

    # Loop through the locales
    locales.each_with_index do | locale, index |

        # Get all the french tags
        sitemap.resources.select{ | d | d.data.template }.each do | resource |

            if resource.path[ 0...2 ] === locale.to_s

                # Debug
                puts "Processing : #{ resource.path }"

                resource.add_metadata options: {
                    locale: locale,
                    lang:   locale
                }

            end

        end

    end

end

You could try running the code within a files.changed block, so the resource metadata is updated every time WebPack changes a file. Example:

files.changed do
  # your loops
end
2 Likes

Brilliant :slight_smile:

So webpack touches these files consistently, I was not aware

This technique works great now - thankyou.

NB// I did not see files_changed in the docs…

A lot of things aren’t in the docs. That’s why this forum is useful. :slight_smile:

I’m glad that this trick worked for you. Just keep in mind that, since it gets run every time a file is touched, it can potentially cause a performance issue. The block also provides the file that changed as an argument. So, based on what got changed, you might be able to optimize the callback a little better.

Hiya

So update on the above - this worked great in the server - but on build it failed unfortunately.

Maybe I need a combination of Ready Do also will implement this

Also why is it you think that the metadata set is cleared by the webpacking touching the files?
Is metadata only temporary?

            resource.add_metadata options: {
                locale: locale,
                lang:   locale
            }

I tried sifting through the source but could not really see what is happening.

Basically I came up with the notion of setting the options for language on the dynamic blog templates and seems to work but its unstable.

I believe that Middleman rebuilds or, at the very least, partially updates the metadata of resources when files.changed is fired, which is why the metadata set might be getting cleared. When you say it is unstable, what are the issues you are having?

For build, it seems that files.changed only gets called once in this mode. In addition, when the first time that files.changed is called, it seems that the list of sitemap.resources is not yet fully populated with resources from external pipelines. Therefore, please try and see if this hybrid approach works for you:

def update_locale_metadata(*args)
  # your loops to update metadata
end

files.changed(&method(:update_locale_metadata))
ready(&method(:update_locale_metadata))

Hope that helps.

Many thanks

This is all working now - nice hacks that I hope to workaround on the Blog

Do you use the Blog extension actively - looking to recruit some guys to help out also.

Glad to hear that it is working for you. I don’t used the blog extension very much, unfortunately. I only use it for my rarely updated personal blog. Most Middleman sites I have worked on used extensions that I built myself, and they usually didn’t require ones that were too complex.