From 1417261de6033570c9cecf103fb5cb05ba284ce1 Mon Sep 17 00:00:00 2001 From: okliv <884634+okliv@users.noreply.github.com> Date: Fri, 4 Oct 2024 02:42:25 +0300 Subject: [PATCH 1/3] implement 'terser' gem for js assets compilation https://github.com/ahorek/terser-ruby ES 6 support --- lib/roda/plugins/assets.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/roda/plugins/assets.rb b/lib/roda/plugins/assets.rb index b35d8a59..2565929a 100644 --- a/lib/roda/plugins/assets.rb +++ b/lib/roda/plugins/assets.rb @@ -570,7 +570,7 @@ def compress_asset(content, type) end compressors = if type == :js - [:yui, :closure, :uglifier, :minjs] + [:yui, :closure, :uglifier, :minjs, :terser] else [:yui] end @@ -623,6 +623,18 @@ def compress_js_uglifier(content) Uglifier.compile(content) end + def compress_js_terser(content) + begin + require 'terser' + rescue => e + # :nocov: + raise CompressorNotFound, "#{e.class}: #{e.message}", e.backtrace + # :nocov: + end + + Terser.compile(content) + end + # Compress the CSS using YUI Compressor, requires java runtime def compress_js_yui(content) compress_yui(content, :compress_js) From 2b918568fbd90721b24680ffaa5a5d89aabf885f Mon Sep 17 00:00:00 2001 From: okliv <884634+okliv@users.noreply.github.com> Date: Fri, 4 Oct 2024 02:54:00 +0300 Subject: [PATCH 2/3] Update assets.rb --- lib/roda/plugins/assets.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/roda/plugins/assets.rb b/lib/roda/plugins/assets.rb index 0319bc68..81d4cdb7 100644 --- a/lib/roda/plugins/assets.rb +++ b/lib/roda/plugins/assets.rb @@ -623,6 +623,7 @@ def compress_js_uglifier(content) Uglifier.compile(content) end + # Compress the JS using Terser, requires javascript runtime def compress_js_terser(content) begin require 'terser' From 7c8bc25b04a718c8331817c050874525b4d866e9 Mon Sep 17 00:00:00 2001 From: okliv <884634+okliv@users.noreply.github.com> Date: Sat, 5 Oct 2024 04:44:22 +0300 Subject: [PATCH 3/3] Update assets.rb --- lib/roda/plugins/assets.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/roda/plugins/assets.rb b/lib/roda/plugins/assets.rb index 81d4cdb7..36e302a3 100644 --- a/lib/roda/plugins/assets.rb +++ b/lib/roda/plugins/assets.rb @@ -633,7 +633,7 @@ def compress_js_terser(content) # :nocov: end - Terser.compile(content) + Terser.compile(content, compress: { drop_console: true }) end # Compress the CSS using YUI Compressor, requires java runtime