Log1x / blade-svg-sage

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

Hassed assets names on production #18

Closed aitormendez closed 5 years ago

aitormendez commented 5 years ago

I'm getting the File does not exist at path error when yarn build:production.

This is the warning:

File does not exist at path /srv/www/margenesdelarte.org/current/web/app/themes/mrg/dist/images/svg/flecha-aba-peq.svg

I've seen older issues with the same error that seems to be fixed but I'm getting this error with a fresh install of Sage and blade-svg-sage.

Log1x commented 5 years ago

Are you sure it's installing v2.0.0? The default path was changed to resources/svg is why I ask.

aitormendez commented 5 years ago

https://github.com/aitormendez/margenesdelarte/blob/c2e961db04213833210ef4a781e869a62b22780d/web/app/themes/mrg/composer.json#L40

aitormendez commented 5 years ago

I've changed the default path:

https://github.com/aitormendez/margenesdelarte/blob/c2e961db04213833210ef4a781e869a62b22780d/web/app/themes/mrg/app/filters.php#L98-L107

Log1x commented 5 years ago

Sorry about the delayed response.

The reason your path isn't working is due to how Sage's default webpack config hashes the filename. During compilation, flecha-aba-peq.svg would become flecha-aba-peq_[hash].svg which is ultimately why I moved away from using the dist directory as it's not necessary to hash (especially in the way Sage does it out of the box) something you're programmatically inlining in your markup.

When I get some time, I will look into implementing a config variable that you can set to true to make Blade SVG use the manifest (asset_path()) for retrieving the SVG– but I can't give an ETA or even a promise that it will happen due to how blade-svg handles pathing internally:

This ends up making it difficult to alter the icon/path and wrap it in asset_path() to make us able to return the value from the manifest.json.

But if I'm being honest, this all comes down to Sage's build system being way over the top in handling cache busting. It should instead do what Laravel Mix and every other build system does, and append an argument to the end of the filename inside of the manifest on each build such as icon.svg?id=[hash] so pulling an asset from the manifest isn't forcefully required.

So ultimately, your options as of right now are:

aitormendez commented 5 years ago

Understood. Thank you for your time and your excelent work.