2022-05-11 17:23:32 +08:00
|
|
|
# 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)
|
2022-08-22 16:56:39 +08:00
|
|
|
if (File.basename(sourcemap_logical_path) === sourcemap_logical_path) ||
|
|
|
|
sourcemap_logical_path.start_with?("plugins/")
|
2022-05-11 17:23:32 +08:00
|
|
|
# If the original sourcemap reference is relative, keep it relative
|
|
|
|
result = File.basename(result)
|
|
|
|
end
|
|
|
|
result
|
|
|
|
end
|
|
|
|
end
|