Add subresource integrity for JS and CSS assets (#15096)

Fix #2744
This commit is contained in:
Eugen Rochko 2020-11-06 11:56:31 +01:00 committed by GitHub
parent 68d4b2b83e
commit 9b1f2a4b61
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
31 changed files with 79 additions and 39 deletions

View file

@ -0,0 +1,17 @@
# frozen_string_literal: true
module Webpacker::ManifestExtensions
def lookup(name, pack_type = {})
asset = super
if pack_type[:with_integrity] && asset.respond_to?(:dig)
[asset.dig('src'), asset.dig('integrity')]
elsif asset.respond_to?(:dig)
asset.dig('src')
else
asset
end
end
end
Webpacker::Manifest.prepend(Webpacker::ManifestExtensions)