Created
October 30, 2023 21:00
-
-
Save brenogazzola/3e29d380a26384a71adc0dc2fc8bce57 to your computer and use it in GitHub Desktop.
Enhance Propshaft to compress files during precompilation
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
require "rake" | |
Rake::Task["assets:precompile"].enhance do | |
assembly = Rails.application.assets | |
output_path = assembly.config.output_path | |
assembly.load_path.assets.each do |asset| | |
asset_path = output_path.join(asset.digested_path) | |
compressed_path = output_path.join(asset.digested_path.to_s + ".br") | |
unless compressed_path.exist? | |
Propshaft.logger.info "Compressing #{asset.digested_path}" | |
`brotli #{asset_path} -o #{compressed_path}` | |
end | |
end;nil | |
end if Rake::Task.task_defined?("assets:precompile") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment