PERF: user mini racer to uglify assets

This commit is contained in:
Sam 2017-03-09 16:44:50 -05:00
parent c4e22a12f9
commit ab3faeb0f9
2 changed files with 15 additions and 9 deletions

View File

@ -138,7 +138,7 @@ GEM
json (1.8.6) json (1.8.6)
jwt (1.5.2) jwt (1.5.2)
kgio (2.10.0) kgio (2.10.0)
libv8 (5.3.332.38.3) libv8 (5.3.332.38.5)
listen (0.7.3) listen (0.7.3)
logster (1.2.7) logster (1.2.7)
loofah (2.0.3) loofah (2.0.3)
@ -153,7 +153,7 @@ GEM
method_source (0.8.2) method_source (0.8.2)
mime-types (2.99.2) mime-types (2.99.2)
mini_portile2 (2.1.0) mini_portile2 (2.1.0)
mini_racer (0.1.7) mini_racer (0.1.9)
libv8 (~> 5.3) libv8 (~> 5.3)
minitest (5.9.1) minitest (5.9.1)
mocha (1.1.0) mocha (1.1.0)
@ -477,4 +477,4 @@ DEPENDENCIES
unicorn unicorn
BUNDLED WITH BUNDLED WITH
1.14.4 1.14.6

View File

@ -11,10 +11,14 @@ 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 && !`which uglifyjs`.empty? && !ENV['SKIP_NODE_UGLIFY'] if Rails.configuration.assets.js_compressor == :uglifier && !`which uglifyjs`.empty? && ENV['FORCE_NODE_UGLIFY']
$node_uglify = true $node_uglify = true
end end
unless ENV['USE_SPROCKETS_UGLIFY']
$bypass_sprockets_uglify = true
end
puts "Bundling assets" puts "Bundling assets"
# in the past we applied a patch that removed asset postfixes, but it is terrible practice # in the past we applied a patch that removed asset postfixes, but it is terrible practice
@ -28,7 +32,7 @@ task 'assets:precompile:before' do
load "#{Rails.root}/lib/global_path.rb" load "#{Rails.root}/lib/global_path.rb"
include GlobalPath include GlobalPath
if $node_uglify if $bypass_sprockets_uglify
Rails.configuration.assets.js_compressor = nil Rails.configuration.assets.js_compressor = nil
Rails.configuration.assets.gzip = false Rails.configuration.assets.gzip = false
end end
@ -84,8 +88,10 @@ def compress_ruby(from,to)
uglified, map = Uglifier.new(comments: :none, uglified, map = Uglifier.new(comments: :none,
screw_ie8: true, screw_ie8: true,
source_filename: File.basename(from), source_map: {
output_filename: File.basename(to) filename: File.basename(from),
output_filename: File.basename(to)
}
) )
.compile_with_map(data) .compile_with_map(data)
dest = "#{assets_path}/#{to}" dest = "#{assets_path}/#{to}"
@ -108,7 +114,7 @@ def brotli(path)
end end
def compress(from,to) def compress(from,to)
if @has_uglifyjs ||= !`which uglifyjs`.empty? if $node_uglify
compress_node(from,to) compress_node(from,to)
else else
compress_ruby(from,to) compress_ruby(from,to)
@ -129,7 +135,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 $node_uglify if $bypass_sprockets_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)