FIX: reduce verboseness of uglify command

PERF: do not generate source maps in ruby mode
This commit is contained in:
Sam 2014-12-18 04:14:12 +11:00
parent b06cb26f7f
commit b279b1daa0
1 changed files with 41 additions and 35 deletions

View File

@ -11,8 +11,8 @@ task 'assets:precompile:before' do
puts "Purging temp files" puts "Purging temp files"
`rm -fr #{Rails.root}/tmp/cache` `rm -fr #{Rails.root}/tmp/cache`
if Rails.configuration.assets.js_compressor == :uglifier if Rails.configuration.assets.js_compressor == :uglifier && !`which uglifyjs`.empty? && !ENV['SKIP_NODE_UGLIFY']
ENV["UGLIFY"] = "1" $node_uglify = true
end end
puts "Bundling assets" puts "Bundling assets"
@ -21,50 +21,51 @@ task 'assets:precompile:before' do
# leaving very complicated build issues # leaving very complicated build issues
# https://github.com/rails/sprockets-rails/issues/49 # https://github.com/rails/sprockets-rails/issues/49
# let's make precompile faster using redis magic
require 'sprockets' require 'sprockets'
require 'digest/sha1' require 'digest/sha1'
# monkey patch asset pipeline not to gzip, compress: false is broken if $node_uglify
class ::Sprockets::Asset # monkey patch asset pipeline not to gzip, compress: false is broken
# Save asset to disk. class ::Sprockets::Asset
def write_to(filename, options = {}) # Save asset to disk.
# Gzip contents if filename has '.gz' def write_to(filename, options = {})
return if File.extname(filename) == '.gz' # Gzip contents if filename has '.gz'
return if File.extname(filename) == '.gz'
begin begin
FileUtils.mkdir_p File.dirname(filename) FileUtils.mkdir_p File.dirname(filename)
File.open("#{filename}+", 'wb') do |f| File.open("#{filename}+", 'wb') do |f|
f.write to_s f.write to_s
end
# Atomic write
FileUtils.mv("#{filename}+", filename)
# Set mtime correctly
File.utime(mtime, mtime, filename)
nil
ensure
# Ensure tmp file gets cleaned up
FileUtils.rm("#{filename}+") if File.exist?("#{filename}+")
end end
# Atomic write
FileUtils.mv("#{filename}+", filename)
# Set mtime correctly
File.utime(mtime, mtime, filename)
nil
ensure
# Ensure tmp file gets cleaned up
FileUtils.rm("#{filename}+") if File.exist?("#{filename}+")
end end
end end
module ::Sprockets
end class UglifierCompressor
module ::Sprockets def evaluate(context, locals, &block)
# monkey patch cause we do this later, no idea how to cleanly disable
data
end
class UglifierCompressor
def evaluate(context, locals, &block)
# monkey patch cause we do this later, no idea how to cleanly disable
data
end end
end end
end end
@ -92,7 +93,12 @@ def compress_node(from,to)
source_map_root = (d=File.dirname(from)) == "." ? "/assets" : "/assets/#{d}" source_map_root = (d=File.dirname(from)) == "." ? "/assets" : "/assets/#{d}"
STDERR.puts `uglifyjs '#{assets_path}/#{from}' -p relative -c -m -o '#{to_path}' --source-map-root '#{source_map_root}' --source-map '#{assets_path}/#{to}.map' --source-map-url '/assets/#{to}.map'` cmd = "uglifyjs '#{assets_path}/#{from}' -p relative -c -m -o '#{to_path}' --source-map-root '#{source_map_root}' --source-map '#{assets_path}/#{to}.map' --source-map-url '/assets/#{to}.map'"
STDERR.puts cmd
`#{cmd} 2>&1`
end end
def compress_ruby(from,to) def compress_ruby(from,to)
@ -127,7 +133,7 @@ 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
if ENV["UGLIFY"] if $node_uglify
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)
manifest.files manifest.files
@ -154,6 +160,6 @@ task 'assets:precompile' => 'assets:precompile:before' do
# protected # protected
manifest.send :save manifest.send :save
end end
end end