Skip to content

Instantly share code, notes, and snippets.

@brenogazzola
Created October 30, 2023 21:00
Show Gist options
  • Save brenogazzola/3e29d380a26384a71adc0dc2fc8bce57 to your computer and use it in GitHub Desktop.
Save brenogazzola/3e29d380a26384a71adc0dc2fc8bce57 to your computer and use it in GitHub Desktop.
Enhance Propshaft to compress files during precompilation
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