discourse/lib/freedom_patches/sprockets_patches.rb
Loïc Guitaut 357011eb3b DEV: Clean up freedom patches
This patch removes some of our freedom patches that have been deprecated
for some time now.
Some of them have been updated so we’re not shipping code based on an
old version of Rails.
2022-04-06 10:07:14 +02:00

36 lines
1.1 KiB
Ruby

# frozen_string_literal: true
# This contains two patches to make sprockets more tolerable in dev
#
# 1. Stop computing asset paths which triggers sprockets to do mountains of work
# All our assets in dev are in the /assets folder anyway
#
# 2. Stop using a concatenator that does tons of work checking for semicolons when
# when rebuilding an asset
module FreedomPatches
module SprocketsPatches
def self.concat_javascript_sources(buf, source)
if buf.bytesize > 0
# CODE REMOVED HERE
buf << ";" # unless string_end_with_semicolon?(buf)
buf << "\n" # unless buf.end_with?("\n")
end
buf << source
end
if Rails.env.development? || Rails.env.test?
Sprockets.register_bundle_metadata_reducer 'application/javascript', :data, proc { +"" }, method(:concat_javascript_sources)
end
end
end
if Rails.env.development? || Rails.env.test?
ActiveSupport.on_load(:action_view) do
def compute_asset_path(source, _options = {})
"/assets/#{source}"
end
alias_method :public_compute_asset_path, :compute_asset_path
end
end