class Sprockets::UglifierCompressor

Public: Uglifier/Uglify compressor.

To accept the default options

environment.register_bundle_processor 'application/javascript',
  Sprockets::UglifierCompressor

Or to pass options to the Uglifier class.

environment.register_bundle_processor 'application/javascript',
  Sprockets::UglifierCompressor.new(comments: :copyright)

Constants

VERSION

Attributes

cache_key[R]

Public Class Methods

cache_key() click to toggle source
# File lib/sprockets/uglifier_compressor.rb, line 31
def self.cache_key
  instance.cache_key
end
call(input) click to toggle source
# File lib/sprockets/uglifier_compressor.rb, line 27
def self.call(input)
  instance.call(input)
end
instance() click to toggle source

Public: Return singleton instance with default options.

Returns UglifierCompressor object.

# File lib/sprockets/uglifier_compressor.rb, line 23
def self.instance
  @instance ||= new
end
new(options = {}) click to toggle source
# File lib/sprockets/uglifier_compressor.rb, line 37
def initialize(options = {})
  # Feature detect Uglifier 2.0 option support
  if Autoload::Uglifier::DEFAULTS[:copyright]
    # Uglifier < 2.x
    options[:copyright] ||= false
  else
    # Uglifier >= 2.x
    options[:comments] ||= :none
  end

  @options = options
  @cache_key = "#{self.class.name}:#{Autoload::Uglifier::VERSION}:#{VERSION}:#{DigestUtils.digest(options)}".freeze
end

Public Instance Methods

call(input) click to toggle source
# File lib/sprockets/uglifier_compressor.rb, line 51
def call(input)
  @uglifier ||= Autoload::Uglifier.new(@options)
  @uglifier.compile(input[:data])
end