Search code examples
ruby-on-railswebpackwebpackershakapacker

shakapacker: Webpacker can't find subdir/image.png in manifest.json


I am trying to upgrade my app to Rails 7 and decided to upgrade shakapacker (aka webpacker 6).

I like to have images in app/javascript/images organized into subdirectories but for some reason this whole structure gets flattened by skakapacker/webpack.

So <%= image_pack_tag "subdir/image.png" %> raises an error but <%= image_pack_tag "image.png" %> works.

My only clue so far is the doc for webpack-asset-manifest which says: will generate a JSON file that matches the original filename with the hashed version - emphasis on the filename. This might be a change since webpack days?

Also the manifest.json looks different now with shakapacker. Webpcker used to be:

"media/images/favicons/a/favicon.ico": "/packs/media/images/favicons/a/favicon-bdfbf38fd01fae2abb3e1ac7de9c3a12.ico",

now with shakapacker:

"static/image.png": "/packs-test/static/image-bd51daf42131d4298622.png"

You can find the minimal rails app replicating this on my github.


Solution

  • This was indeed a bug in webpacker6/shakapacker.

    https://github.com/shakacode/shakapacker/issues/44