DEV: Use Terser for JS minification/compression if available (#12656)

This commit is contained in:
Penar Musaraj 2021-04-09 08:51:49 -04:00 committed by GitHub
parent b7dad91f2f
commit e77b9dfd45
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -97,8 +97,11 @@ def compress_node(from, to)
source_map_url = cdn_path "/assets/#{to}.map"
base_source_map = assets_path + assets_additional_path
# TODO: Remove uglifyjs when base image only includes terser
js_compressor = `which terser`.empty? ? 'uglifyjs' : 'terser'
cmd = <<~EOS
uglifyjs '#{assets_path}/#{from}' -m -c -o '#{to_path}' --source-map "base='#{base_source_map}',root='#{source_map_root}',url='#{source_map_url}'"
#{js_compressor} '#{assets_path}/#{from}' -m -c -o '#{to_path}' --source-map "base='#{base_source_map}',root='#{source_map_root}',url='#{source_map_url}'"
EOS
STDERR.puts cmd