2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-05-13 04:25:03 -04:00
|
|
|
# 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
|
|
|
|
|
2022-04-05 06:08:28 -04:00
|
|
|
module FreedomPatches
|
|
|
|
module SprocketsPatches
|
2016-05-13 04:25:03 -04:00
|
|
|
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
|
|
|
|
|
2022-04-05 06:08:28 -04:00
|
|
|
if Rails.env.development? || Rails.env.test?
|
|
|
|
Sprockets.register_bundle_metadata_reducer "application/javascript",
|
|
|
|
:data,
|
|
|
|
proc { +"" },
|
|
|
|
method(:concat_javascript_sources)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-05-13 04:25:03 -04:00
|
|
|
|
2022-04-05 06:08:28 -04:00
|
|
|
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
|
2016-05-13 04:25:03 -04:00
|
|
|
end
|