Reputation: 2086
I've got a Rails application that is using webpacker to serve the styles and the javascript. I'm using serviceworker-rails
gem to have a service worker.
Externally from the service worker installation I need to add the cache the css and js produced by webpack. How can i achieve this?
I've tried serving the file with the asset pipeline an using the webpacker helpers but when it's compiled I get:
ActionView::Template::Error (undefined method `javascript_pack_tag' for #<#<Class:0x00007f8cb663fcf0>:0x00007f8cb777f6a0>):
A portion of the file where I use the webpacker helpers is this:
return cache.addAll(window.location.pathname, "<%= javascript_pack_tag 'application' %>",
"<%= stylesheet_pack_tag 'application' %>")
Upvotes: 2
Views: 866
Reputation: 2086
Accessing webpacker helpers in a file that will be part of applicaition.js produced by webpack is impossible (change my mind if you know how to do it)
Instead I've used the asset pipeline to serve this file and inside use:
<%= Webpacker.manifest.lookup 'application.css' %>
to get the application styles, and will return something like:
/packs/application-d85a17a26660e00c18a4d4f9535ee7d7.css
The same applies for application.js
Upvotes: 4