Skip to content

Commit

Permalink
Disable webpacker stylesheet errors in production
Browse files Browse the repository at this point in the history
Webpacker has a nasty habit of not compiling css files for components and then causing an error in production when they are missing.
rails/webpacker#2342
rails/webpacker#2059 (comment)
This adds an override which causes no errors in production but still allows us to leave the stylesheet_pack_tag for when it is needed.
  • Loading branch information
Robert Clark committed Aug 17, 2021
1 parent 3a57b7c commit 39bd8d1
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions app/helpers/webpacker_overrides.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Webpacker has a nasty habit of not compiling css files for components and then
# causing an error in production when they are missing. This file silences
# the errors in production as well, making for a consistent experience across
# environments

# app/helpers/webpacker_overrides.rb
module WebpackerOverrides
private
def rescued_pack_tags
@rescued_pack_tags ||= {}
end

def sources_from_manifest_entries(names, type:)
names.map do |name|
unless (type == :stylesheet) && rescued_pack_tags[name]
current_webpacker_instance.manifest.lookup!(name, type: type)
end
rescue
raise unless type == :stylesheet
rescued_pack_tags[name] = true
nil
end.flatten.select(&:present?)
end
end

0 comments on commit 39bd8d1

Please sign in to comment.