diff --git a/lib/uglifier.rb b/lib/uglifier.rb index acb6e32..f244c5e 100644 --- a/lib/uglifier.rb +++ b/lib/uglifier.rb @@ -150,9 +150,6 @@ def initialize(options = {}) raise ArgumentError, "Invalid option: #{missing}" end @options = options - - source = harmony? ? source_with(HarmonySourcePath) : source_with(SourcePath) - @context = ExecJS.compile(source) end # Minifies JavaScript code @@ -181,6 +178,13 @@ def compile_with_map(source) private + def context + @context ||= begin + source = harmony? ? source_with(HarmonySourcePath) : source_with(SourcePath) + ExecJS.compile(source) + end + end + def source_map_comments return '' unless @options[:source_map].respond_to?(:[]) @@ -214,7 +218,7 @@ def run_uglifyjs(input, generate_map) :ie8 => ie8? } - parse_result(@context.call("uglifier", options), generate_map, options) + parse_result(context.call("uglifier", options), generate_map, options) end def harmony?