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

Fix: check environment Gzip option #260

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions lib/tasks/requirejs-rails_tasks.rake
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ OS X Homebrew users can use 'brew install node'.
built_asset_path = requirejs.config.build_dir.join(asset_name)

# Compute the digest based on the contents of the compiled file, *not* on the contents of the RequireJS module.
file_digest = ::Rails.application.assets.file_digest(built_asset_path.to_s)
file_digest = requirejs.env.file_digest(built_asset_path.to_s)
hex_digest = file_digest.unpack("H*").first
digest_name = asset.logical_path.gsub(path_extension_pattern) { |ext| "-#{hex_digest}#{ext}" }

Expand All @@ -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