Class: DiscourseSourcemappingUrlProcessor

Inherits:
Sprockets::Rails::SourcemappingUrlProcessor
  • Object
show all
Defined in:
lib/discourse_sourcemapping_url_processor.rb

Overview

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 Method Summary collapse

Class Method Details

.sourcemap_asset_path(sourcemap_logical_path, context:) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/discourse_sourcemapping_url_processor.rb', line 7

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) ||
       sourcemap_logical_path.start_with?("plugins/")
    # If the original sourcemap reference is relative, keep it relative
    result = File.basename(result)
  end
  result
end