2019-05-02 17:17:27 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-05-13 03:25:03 -05: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 05:08:28 -05:00
|
|
|
module FreedomPatches
|
|
|
|
module SprocketsPatches
|
2016-05-13 03:25:03 -05: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
|
|
|
|
|
2024-08-09 10:05:18 -05:00
|
|
|
if Rails.env.local?
|
2022-04-05 05:08:28 -05:00
|
|
|
Sprockets.register_bundle_metadata_reducer "application/javascript",
|
|
|
|
:data,
|
|
|
|
proc { +"" },
|
|
|
|
method(:concat_javascript_sources)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-05-13 03:25:03 -05:00
|
|
|
|
2024-08-09 10:05:18 -05:00
|
|
|
if Rails.env.local?
|
2022-04-05 05:08:28 -05:00
|
|
|
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 03:25:03 -05:00
|
|
|
end
|
2023-04-21 13:35:00 -05:00
|
|
|
|
|
|
|
# By default, the Sprockets DirectiveProcessor introduces a newline between possible 'header' comments
|
|
|
|
# and the rest of the JS file. (https://github.com/rails/sprockets/blob/f4d3dae71e/lib/sprockets/directive_processor.rb#L121)
|
|
|
|
# This causes sourcemaps to be offset by 1 line, and therefore breaks browser tooling.
|
|
|
|
# We know that Ember-Cli assets do not use Sprockets directives, so we can totally bypass the DirectiveProcessor for those files.
|
|
|
|
Sprockets::DirectiveProcessor.prepend(
|
|
|
|
Module.new do
|
|
|
|
def process_source(source)
|
|
|
|
return source, [] if EmberCli.is_ember_cli_asset?(File.basename(@filename))
|
|
|
|
super
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
)
|
2023-06-09 05:14:11 -05:00
|
|
|
|
2023-10-26 11:29:53 -05:00
|
|
|
# Skip sprockets fingerprinting for some assets
|
2023-06-09 05:14:11 -05:00
|
|
|
Sprockets::Asset.prepend(
|
|
|
|
Module.new do
|
|
|
|
def digest_path
|
2023-10-26 11:29:53 -05:00
|
|
|
# Webpack chunks are already named based on their contents
|
|
|
|
return logical_path if logical_path.start_with?("chunk.")
|
2023-06-09 05:14:11 -05:00
|
|
|
super
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
)
|