serviceworker-rails
serviceworker-rails copied to clipboard
undefined method `asset_pack_path' when referring to Webpacker entry packs
I'm trying to refer to my Webpacker entry packs (JS and CSS) in my serviceworker.js.erb
file, however it's throwing the following JS exception:
Uncaught Error: NoMethodError: undefined method `asset_pack_path' for #<#<Class:0x00007fa5b7856448>:0x00007fa5b89255d0>
Did you mean? asset_path
Here's my serviceworker.js.erb file:
<% helpers = ActionController::Base.helpers %>
var CACHE_NAME = 'v1-cached-assets';
function onInstall(event) {
event.waitUntil(
caches.open(CACHE_NAME).then(function prefill(cache) {
return cache.addAll([
'<%= asset_path "application.js" %>', // This works
'<%= asset_path "application.css" %>', // This works
'<%= asset_pack_path 'some_entry_pack.js' %>', // This explodes
]);
})
);
}
I ran into this problem also. I did try to use Webpacker.instance.manifest.lookup
, but I think because the Webpacker assets are compiled after this is compiled it'll always return nil :/