mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 20:16:19 +08:00
476bd1d237
22a7905f
restructured how we load Ember CLI assets in production. Unfortunately, it also broke sourcemaps for those assets. This commit fixes that regression via a couple of changes:
- It adds the necessary `.map` paths to `config.assets.precompile`
- It swaps Sprockets' default `SourcemappingUrlProcessor` with an extended version which maintains relative URLs of maps
16 lines
827 B
Ruby
16 lines
827 B
Ruby
# 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
|