mirror of
https://github.com/discourse/discourse.git
synced 2025-06-18 06:33:48 +08:00
Merge pull request #4184 from tgxworld/precompile_our_assets_concurrently
PERF: Uglify and gzip assets concurrently.
This commit is contained in:
@ -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,6 +134,7 @@ 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)
|
||||||
|
|
||||||
|
concurrent? do |proc|
|
||||||
to_skip = Rails.configuration.assets.skip_minification || []
|
to_skip = Rails.configuration.assets.skip_minification || []
|
||||||
manifest.files
|
manifest.files
|
||||||
.select{|k,v| k =~ /\.js$/}
|
.select{|k,v| k =~ /\.js$/}
|
||||||
@ -138,6 +149,7 @@ task 'assets:precompile' => 'assets:precompile:before' do
|
|||||||
else
|
else
|
||||||
STDERR.puts "Compressing: #{file}"
|
STDERR.puts "Compressing: #{file}"
|
||||||
|
|
||||||
|
proc.call do
|
||||||
# We can specify some files to never minify
|
# We can specify some files to never minify
|
||||||
unless (ENV["DONT_MINIFY"] == "1") || to_skip.include?(info['logical_path'])
|
unless (ENV["DONT_MINIFY"] == "1") || to_skip.include?(info['logical_path'])
|
||||||
FileUtils.mv(path, _path)
|
FileUtils.mv(path, _path)
|
||||||
@ -149,6 +161,8 @@ task 'assets:precompile' => 'assets:precompile:before' do
|
|||||||
gzip(path)
|
gzip(path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# protected
|
# protected
|
||||||
manifest.send :save
|
manifest.send :save
|
||||||
|
Reference in New Issue
Block a user