mirror of
https://github.com/codeninjasllc/discourse.git
synced 2025-02-25 07:54:11 -05:00
PERF: Uglify and gzip assets concurrently.
This commit is contained in:
parent
51b0b5f2f8
commit
b744306654
1 changed files with 34 additions and 20 deletions
|
@ -116,6 +116,16 @@ def compress(from,to)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def concurrent?
|
||||||
|
if ENV["CONCURRENT"] == "1"
|
||||||
|
concurrent_compressors = []
|
||||||
|
yield(Proc.new { |&block| concurrent_compressors << Concurrent::Future.execute { block.call } })
|
||||||
|
concurrent_compressors.each(&:wait!)
|
||||||
|
else
|
||||||
|
yield(Proc.new { |&block| block.call })
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
task 'assets:precompile' => 'assets:precompile:before' do
|
task 'assets:precompile' => 'assets:precompile:before' do
|
||||||
# Run after assets:precompile
|
# Run after assets:precompile
|
||||||
Rake::Task["assets:precompile:css"].invoke
|
Rake::Task["assets:precompile:css"].invoke
|
||||||
|
@ -124,30 +134,34 @@ task 'assets:precompile' => 'assets:precompile:before' do
|
||||||
puts "Compressing Javascript and Generating Source Maps"
|
puts "Compressing Javascript and Generating Source Maps"
|
||||||
manifest = Sprockets::Manifest.new(assets_path)
|
manifest = Sprockets::Manifest.new(assets_path)
|
||||||
|
|
||||||
to_skip = Rails.configuration.assets.skip_minification || []
|
concurrent? do |proc|
|
||||||
manifest.files
|
to_skip = Rails.configuration.assets.skip_minification || []
|
||||||
.select{|k,v| k =~ /\.js$/}
|
manifest.files
|
||||||
.each do |file, info|
|
.select{|k,v| k =~ /\.js$/}
|
||||||
|
.each do |file, info|
|
||||||
|
|
||||||
path = "#{assets_path}/#{file}"
|
path = "#{assets_path}/#{file}"
|
||||||
_file = (d = File.dirname(file)) == "." ? "_#{file}" : "#{d}/_#{File.basename(file)}"
|
_file = (d = File.dirname(file)) == "." ? "_#{file}" : "#{d}/_#{File.basename(file)}"
|
||||||
_path = "#{assets_path}/#{_file}"
|
_path = "#{assets_path}/#{_file}"
|
||||||
|
|
||||||
if File.exists?(_path)
|
if File.exists?(_path)
|
||||||
STDERR.puts "Skipping: #{file} already compressed"
|
STDERR.puts "Skipping: #{file} already compressed"
|
||||||
else
|
else
|
||||||
STDERR.puts "Compressing: #{file}"
|
STDERR.puts "Compressing: #{file}"
|
||||||
|
|
||||||
# We can specify some files to never minify
|
proc.call do
|
||||||
unless (ENV["DONT_MINIFY"] == "1") || to_skip.include?(info['logical_path'])
|
# We can specify some files to never minify
|
||||||
FileUtils.mv(path, _path)
|
unless (ENV["DONT_MINIFY"] == "1") || to_skip.include?(info['logical_path'])
|
||||||
compress(_file,file)
|
FileUtils.mv(path, _path)
|
||||||
|
compress(_file,file)
|
||||||
|
end
|
||||||
|
|
||||||
|
info["size"] = File.size(path)
|
||||||
|
info["mtime"] = File.mtime(path).iso8601
|
||||||
|
gzip(path)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
info["size"] = File.size(path)
|
|
||||||
info["mtime"] = File.mtime(path).iso8601
|
|
||||||
gzip(path)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# protected
|
# protected
|
||||||
|
|
Loading…
Reference in a new issue