Last active
October 17, 2021 03:36
-
-
Save nicbet/774fddcc8ecc7bed2575e0f08b20e96e to your computer and use it in GitHub Desktop.
Rails 7 reference assets with CSS Bundler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/initializers/asset_url_processor.rb | |
# See https://github.com/rails/cssbundling-rails/issues/22 | |
class AssetUrlProcessor | |
def self.call(input) | |
context = input[:environment].context_class.new(input) | |
data = input[:data].gsub(/url\(\s*["']?(?!(?:\#|data|http))([^"'\s)]+)\s*["']?\)/) do |_match| | |
"url(#{context.asset_path($1)})" | |
end | |
{data: data} | |
end | |
end | |
Sprockets.register_postprocessor "text/css", AssetUrlProcessor |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment