~cytrogen/masto-fe

ref: 3ca94f6d4a99cdf7f99eefd7d26a18a82c3c6f78 masto-fe/lib/webpacker/helper_extensions.rb -rw-r--r-- 1.2 KiB
3ca94f6d — Claire Merge commit '93d051e47d27b5bd10be922a81d4d4eb6c306330' into glitch-soc/merge-upstream 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# frozen_string_literal: true

module Webpacker::HelperExtensions
  def javascript_pack_tag(name, **options)
    src, integrity = current_webpacker_instance.manifest.lookup!(name, type: :javascript, with_integrity: true)
    javascript_include_tag(src, options.merge(integrity: integrity))
  end

  def stylesheet_pack_tag(name, **options)
    src, integrity = current_webpacker_instance.manifest.lookup!(name, type: :stylesheet, with_integrity: true)
    stylesheet_link_tag(src, options.merge(integrity: integrity))
  end

  def preload_pack_asset(name, **options)
    src, integrity = current_webpacker_instance.manifest.lookup!(name, with_integrity: true)

    # This attribute will only work if the assets are on a different domain.
    # And Webpack will (correctly) only add it in this case, so we need to conditionally set it here
    # otherwise the preloaded request and the real request will have different crossorigin values
    # and the preloaded file wont be loaded
    crossorigin = 'anonymous' if Rails.configuration.action_controller.asset_host.present?

    preload_link_tag(src, options.merge(integrity: integrity, crossorigin: crossorigin))
  end
end

Webpacker::Helper.prepend(Webpacker::HelperExtensions)