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

View File

@ -11,10 +11,14 @@ task 'assets:precompile:before' do
puts "Purging temp files"
`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
end
unless ENV['USE_SPROCKETS_UGLIFY']
$bypass_sprockets_uglify = true
end
puts "Bundling assets"
# 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"
include GlobalPath
if $node_uglify
if $bypass_sprockets_uglify
Rails.configuration.assets.js_compressor = nil
Rails.configuration.assets.gzip = false
end
@ -84,8 +88,10 @@ def compress_ruby(from,to)
uglified, map = Uglifier.new(comments: :none,
screw_ie8: true,
source_filename: File.basename(from),
output_filename: File.basename(to)
source_map: {
filename: File.basename(from),
output_filename: File.basename(to)
}
)
.compile_with_map(data)
dest = "#{assets_path}/#{to}"
@ -108,7 +114,7 @@ def brotli(path)
end
def compress(from,to)
if @has_uglifyjs ||= !`which uglifyjs`.empty?
if $node_uglify
compress_node(from,to)
else
compress_ruby(from,to)
@ -129,7 +135,7 @@ task 'assets:precompile' => 'assets:precompile:before' do
# Run after assets:precompile
Rake::Task["assets:precompile:css"].invoke
if $node_uglify
if $bypass_sprockets_uglify
puts "Compressing Javascript and Generating Source Maps"
manifest = Sprockets::Manifest.new(assets_path)