Log1x / blade-svg-sage

A simple package to add support for Blade SVG by Adam Wathan to Roots Sage.
MIT License
72 stars 13 forks source link

[Latest sage] Missing hash #8

Closed strarsis closed 7 years ago

strarsis commented 7 years ago

@Log1x: I updated the theme underlying sage to latest sage from master. Indeed, a lot has changed. However, @icon still doesn't add the hash to filename after yarn run build:production.

How can this be further debugged? I tried a lot and it is very frustrating that it still doesn't work. 😿

Log1x commented 7 years ago

Are the files in your manifest.json? If not, you need to address your webpack configuration. I'm not sure what you would need to do for Sage's default implementation as I haven't used it for some time and use Laravel Mix. Otherwise, \App\sage('assets')->get($asset) should be getting the file from your manifest.json assuming it exists using parse_asset_path() (which is a simple helper function that gets a file path instead of a URI using Sage's built in sage('assets')->get().).

strarsis commented 7 years ago

@Log1x: Thank you for your answer!

parse_asset_path(...) is called for the directories, but not for individual files: 'images/svg/icons'.

This is how I include a svg in blade template:

@icon('glasses', 'glasses-fx-svg')

Error in markup:

/srv/www/web/app/themes/the-site/dist/images/svg/icons not found.

In 'SvgFactory.php', getSvg(...) is called with 'glasses' as argument. It returns a path: '/srv/www/web/app/themes/the-site/dist/images/svg/icons/glasses.svg' However, this path would only work for non-production build (without the hash).

So getSvg(...) gets a $name without the hash resolved in the first place.

I tried to find a 'manifest.json', apparently this has been also changed now in latest sage, the paths are now located in 'config.json' instead. There is a key "entry" and sub-key "main", but apparently for the main scripts/styles.

How can I further debug / help finding the issue in my case?

Log1x commented 7 years ago

I will look into this more for you.

Can you verify that your manifest.json is in fact storing your *.svg's along with their hashes just to rule that out? You may be right though, parse_asset_path may need some minor tweaking. It could be as simple as a misplaced / making it not parse the json properly.

Log1x commented 7 years ago

Alright, I went ahead and did a rewrite. Hopefully it works as expected now. I tested it a little bit but I only use SVG's as inline thus client-side hashing is redundant.

The package should be a theme dependency now instead of a mu-plugin, so make sure when you composer update log1x/blade-svg-sage that it removes it from mu-plugins.

strarsis commented 7 years ago

Thanks! The issue resolved after redeploying and activating the theme again (https://discourse.roots.io/t/dev-vs-production-resources-dist-instead-dist/10277/3). I will update blade-svg-sage and hope this issue won't creep up again.