class Terser::Compressor

A wrapper for Sprockets

Constants

VERSION

Attributes

cache_key[R]

Public Class Methods

cache_key() click to toggle source
# File lib/terser/compressor.rb, line 26
def self.cache_key
  instance.cache_key
end
call(input) click to toggle source
# File lib/terser/compressor.rb, line 22
def self.call(input)
  instance.call(input)
end
instance() click to toggle source
# File lib/terser/compressor.rb, line 18
def self.instance
  @instance ||= new
end
new(options = {}) click to toggle source
# File lib/terser/compressor.rb, line 11
def initialize(options = {})
  options[:comments] ||= :none
  @options = options.merge(Rails.application.config.assets.terser.to_h)
  @cache_key = -"Terser:#{::Terser::VERSION}:#{VERSION}:#{::Sprockets::DigestUtils.digest(options)}"
  @terser = ::Terser.new(@options)
end

Public Instance Methods

call(input) click to toggle source
# File lib/terser/compressor.rb, line 33
def call(input)
  input_options = { :source_map => { :filename => input[:filename] } }

  js, map = @terser.compile_with_map(input[:data], input_options)

  map = ::Sprockets::SourceMapUtils.format_source_map(JSON.parse(map), input)
  map = ::Sprockets::SourceMapUtils.combine_source_maps(input[:metadata][:map], map)

  { :data => js, :map => map }
end