discourse/lib/discourse_sourcemapping_url...

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

16 lines
827 B
Ruby
Raw Normal View History

# frozen_string_literal: true
# This postprocessor rewrites `//sourceMappingURL=` comments to include the hashed filename of the map.
# As a side effect, the default implementation also replaces relative sourcemap URLs with absolute URLs, including the CDN domain.
# We want to preserve the relative nature of the URLs, so that compiled JS is portable across sites with differing CDN configurations.
class DiscourseSourcemappingUrlProcessor < Sprockets::Rails::SourcemappingUrlProcessor
def self.sourcemap_asset_path(sourcemap_logical_path, context:)
result = super(sourcemap_logical_path, context: context)
if File.basename(sourcemap_logical_path) === sourcemap_logical_path
# If the original sourcemap reference is relative, keep it relative
result = File.basename(result)
end
result
end
end