Sha256: a61a3ca5c9b4862c8ccf4fb677fd16c96920b501861030c0b385d41892294028
Contents?: true
Size: 1.33 KB
Versions: 1
Compression:
Stored size: 1.33 KB
Contents
# frozen_string_literal: true require 'sprockets/digest_utils' require 'sprockets/source_map_utils' if Gem::Version.new(::Sprockets::VERSION) >= Gem::Version.new('4.x') class Terser # A wrapper for Sprockets class Compressor VERSION = '1' def initialize(options = {}) options[:comments] ||= :none @options = options @cache_key = -"Terser:#{::Terser::VERSION}:#{VERSION}:#{::Sprockets::DigestUtils.digest(options)}" end def self.instance @instance ||= new end def self.call(input) instance.call(input) end def self.cache_key instance.cache_key end attr_reader :cache_key if Gem::Version.new(::Sprockets::VERSION) >= Gem::Version.new('4.x') def call(input) input_options = { :source_map => { :filename => input[:filename] } } terser = ::Terser.new(@options.merge(input_options)) js, map = terser.compile_with_map(input[:data]) 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 else def call(input) terser = ::Terser.new(@options) terser.compile(input[:data]) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
terser-1.0.0 | lib/terser/compressor.rb |