Skip to content

Commit

Permalink
Fixes #37353 - always read cached webpack manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeni committed Apr 15, 2024
1 parent f87b1a2 commit 6924b15
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions app/helpers/reactjs_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,23 @@ def webpacked_plugins_css_for(*plugin_names)
end

def read_webpack_manifest
JSON.parse(Rails.root.join('public/webpack/manifest.json').read)
Rails.cache.fetch('webpack_foreman_manifest', expires_in: 1.minute) do
JSON.parse(Rails.root.join('public/webpack/manifest.json').read)
end
end

def get_webpack_chunk(name, extension)
data = read_webpack_manifest
data['assetsByChunkName'][name].find { |value| value.end_with?(".#{extension}") }
end

def get_webpack_foreman_vendor_js
Rails.cache.fetch('webpack_foreman_vendor_js', expires_in: 1.minute) do
data = read_webpack_manifest
foreman_vendor_js = data['assetsByChunkName']['foreman-vendor'].find { |value| value.end_with?('.js') }
javascript_include_tag("/webpack/#{foreman_vendor_js}")
end
foreman_vendor_js = get_webpack_chunk('foreman-vendor', 'js')
javascript_include_tag("/webpack/#{foreman_vendor_js}")
end

def get_webpack_foreman_vendor_css
data = read_webpack_manifest
foreman_vendor_css = data['assetsByChunkName']['foreman-vendor'].find { |value| value.end_with?('.css') }
foreman_vendor_css = get_webpack_chunk('foreman-vendor', 'css')
stylesheet_link_tag("/webpack/#{foreman_vendor_css}")
end

Expand Down

0 comments on commit 6924b15

Please sign in to comment.