Ognjen Regoje bio photo

MY NAME IS
Ognjen Regoje
BUT YOU CAN CALL ME OGGY


I make things that run on the web (mostly).
More /ABOUT me.

me@ognjen.io Twitter LinkedIn Instagram Github

How to get the direct path to a Webpacker pack

If you are making use of a serviceworker to cache JS or CSS or you’re rendering some JS server-side you have to have the full path to the file.

If, at the same time, you’re using Webpacker to generate your assets, it’s not obvious how to get the full path to the pack

After some searching through the docs I found that it’s like this:

<%= Webpacker.manifest.lookup('application.js')%>

It seems that this API changed recently so most of the previous search results refer to the previous API. Hopefully this gets picked up and saves others from experimentation and googling that I had to go through.

#rails #webpacker