David Taylor 476bd1d237
DEV: Fix production sourcemaps with Ember CLI ()
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
2022-05-11 10:23:32 +01:00

54 lines
1.4 KiB
Ruby

# frozen_string_literal: true
module EmberCli
ASSETS = %w(
discourse.js
admin.js
ember_jquery.js
pretty-text-bundle.js
start-discourse.js
vendor.js
)
ALIASES ||= {
"application" => "discourse",
"discourse/tests/test-support-rails" => "test-support",
"discourse/tests/test-helpers-rails" => "test-helpers"
}
def self.enabled?
ENV["EMBER_CLI_PROD_ASSETS"] != "0"
end
def self.script_chunks
return @@chunk_infos if defined? @@chunk_infos
raw_chunk_infos = JSON.parse(File.read("#{Rails.configuration.root}/app/assets/javascripts/discourse/dist/chunks.json"))
chunk_infos = raw_chunk_infos["scripts"].map do |info|
logical_name = info["afterFile"][/\Aassets\/(.*)\.js\z/, 1]
chunks = info["scriptChunks"].map { |filename| filename[/\Aassets\/(.*)\.js\z/, 1] }
[logical_name, chunks]
end.to_h
@@chunk_infos = chunk_infos if Rails.env.production?
chunk_infos
rescue Errno::ENOENT
{}
end
# Some assets have changed name following the switch
# to ember-cli. When the switch is complete, we can
# drop this method and update all the references
# to use the new names
def self.transform_name(name)
return name if !enabled?
ALIASES[name] || name
end
def self.is_ember_cli_asset?(name)
return false if !enabled?
ASSETS.include?(name) || name.start_with?("chunk.")
end
end