Bud Assets Hashing/Versioning

I have several assets that aren’t referenced in CSS or JS, but are used inside some Blade template files.

I’m attempting to set up my Bud config so these assets are copied and versioned/hashed the same way as the files that are referenced in CSS/JS are. I’ve tried various combinations, but none of them work exactly as intended. The two most noteworthy attempts are below.

  1. The below code results in all images being copied over, but without hashing/versioning. The images referenced in CSS/JS are then copied a second time with a hash. However, the manifest.json file ends up not referencing any of those hashed versions.
app
    .entry({
      app: ['@scripts/app', '@styles/app'],
    })
    .assets([
      [app.path('@src/images'), app.path('@dist')],
    ])
  1. The below code avoids the image duplication, but obviously results in zero hashing/versioning. Setting the hash parameter to true has the same outcome as in #1 above.
app
    .hash(false)
    .entry({
      app: ['@scripts/app', '@styles/app'],
    })
    .assets([
      [app.path('@src/images'), app.path('@dist')],
    ])

How do I properly configure this so that all images are only brought over once and they are all properly versioned/hashed and added to the manifest.json?

I noticed this as well a few days ago. It will be addressed in an update. Maybe surprisingly, bud.assets is one of the more complex functions in all of bud.

For now the best way to do it is to use object syntax along with the @file shorthand:

    .assets([
      {
        from: app.path("@src/images"),
        to: app.path("@dist/@file"),
      },
    ])

Just now realizing there is a need for documenting this, but the @file path handle will be replaced with the hashed filename if hashing is enabled, and the normal filename otherwise.

1 Like

That works like a charm. Thanks so much!

Bud v5.8.6 includes a fix for the issue which necessitated this workaround :relieved: