Skip to content

Commit

Permalink
Merge pull request #9245 from jrafanie/wrap_uglifier_to_allow_es6_and…
Browse files Browse the repository at this point in the history
…_avoid_loading_js_runtime

Wrap the uglifier compressor with harmony support
  • Loading branch information
Fryguy authored Aug 8, 2024
2 parents 1cd2e46 + c4c67f6 commit d906b9d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/manageiq/ui/classic/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,15 @@ class Engine < ::Rails::Engine
config.assets.paths << root.join('vendor', 'assets', 'stylesheets').to_s

if Rails.env.production? || Rails.env.test?
# Workaround rails 7 + es6 syntax in some js causing uglifier errors by running harmony mode
# See: https://www.github.com/lautis/uglifier/issues/127
require 'uglifier'
config.assets.js_compressor = Uglifier.new(:harmony => true)
config.assets.configure do |env|
# Workaround rails 7 + es6 syntax in some js causing uglifier errors by running harmony mode
# See: https://www.github.com/lautis/uglifier/issues/127
# Note, we're purposely using our own compressor to avoid requiring uglifier at application boot time
# since this require a js runtime such as node.
require 'manageiq/ui/classic/js_compressor'
env.register_compressor 'application/javascript', :manageiq_ui_classic_js_compressor, ManageIQ::UI::Classic::JsCompressor
end
config.assets.js_compressor = :manageiq_ui_classic_js_compressor
end

def self.vmdb_plugin?
Expand Down
13 changes: 13 additions & 0 deletions lib/manageiq/ui/classic/js_compressor.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module ManageIQ
module UI
module Classic
class JsCompressor < Sprockets::UglifierCompressor
def initialize(options = {})
warn "\e[33m** Using #{self.class.name} with Uglifier.new(:harmony => true) from: #{__FILE__}:#{__LINE__}\e[0m"
options[:harmony] = true
super(options)
end
end
end
end
end

0 comments on commit d906b9d

Please sign in to comment.