A platform for community discussion. Free, open, simple.
DEV: Restore propshaft sourcemap middleware (#38415)
Jarek Radosz3c5e4146f7a1
diff --git a/config/initializers/assets.rb b/config/initializers/assets.rbindex 9140fa5837d..cd6b61af002 100644--- a/config/initializers/assets.rb+++ b/config/initializers/assets.rb@@ -25,4 +25,7 @@ Rails.application.config.assets.excluded_paths.push("#{Rails.root}/app/assets/stylesheets",)-Rails.application.config.assets.compilers = []+# We don't need/want most of Propshaft's preprocessing. Only keep the JS sourcemap handler+Rails.application.config.assets.compilers.filter! do |type, compiler|+ type == "text/javascript" && compiler == Propshaft::Compiler::SourceMappingUrls+enddiff --git a/lib/freedom_patches/propshaft_patches.rb b/lib/freedom_patches/propshaft_patches.rbindex c95349a779e..24203874656 100644--- a/lib/freedom_patches/propshaft_patches.rb+++ b/lib/freedom_patches/propshaft_patches.rb@@ -30,3 +30,22 @@ Propshaft::Helper.prepend(endend,)++Propshaft::Compiler::SourceMappingUrls.prepend(+ Module.new do+ def compile(asset, input)+ if asset.logical_path.to_s.include?(".digested.")+ input+ else+ super+ end+ end++ def source_mapping_url(*args)+ # Propshaft insists on converting sourcemap URLs to absolute paths. We want to keep+ # relative paths so that we can serve assets from different subdirectories without needing+ # to recompile them+ super.gsub(%r{sourceMappingURL=\S+/([^/]+\.map)}, 'sourceMappingURL=\1')+ end+ end,+)