Skip to content
This repository has been archived by the owner on Mar 23, 2024. It is now read-only.

Commit

Permalink
Respect Rails assets env. for gzip compression
Browse files Browse the repository at this point in the history
Skip gzip compression if it's disabled in Rails env.
  • Loading branch information
Strech committed Mar 29, 2016
1 parent 9008038 commit def9cae
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/tasks/requirejs-rails_tasks.rake
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,15 @@ OS X Homebrew users can use 'brew install node'.
requirejs.manifest[module_script_name] = digest_name
FileUtils.cp built_asset_path, digest_asset_path

# Create the compressed versions
File.open("#{built_asset_path}.gz", 'wb') do |f|
zgw = Zlib::GzipWriter.new(f, Zlib::BEST_COMPRESSION)
zgw.write built_asset_path.read
zgw.close
# Create the compressed versions if gzip is not disabled
if !requirejs.env.respond_to?(:gzip?) || requirejs.env.gzip?
File.open("#{built_asset_path}.gz", 'wb') do |f|
zgw = Zlib::GzipWriter.new(f, Zlib::BEST_COMPRESSION)
zgw.write built_asset_path.read
zgw.close
end
FileUtils.cp "#{built_asset_path}.gz", "#{digest_asset_path}.gz"
end
FileUtils.cp "#{built_asset_path}.gz", "#{digest_asset_path}.gz"

requirejs.config.manifest_path.open('wb') do |f|
YAML.dump(requirejs.manifest, f)
Expand Down

0 comments on commit def9cae

Please sign in to comment.