Class: Uglifier

### Home Classes Methods

### In Files

- lib/uglifier.rb
- lib/uglifier/version.rb

### Parent

Object

### Methods

- ::compile
- ::compile_with_map
- ::new
- #compile
- #compile_with_map
- #compress

### Files

- LICENSE.txt

### Class/Module Index

Quicksearch

- Uglifier

No matching classes.

# Uglifier

A wrapper around the UglifyJS interface

### Constants

DEFAULTS

  Default options for compilation

ES5FallbackPath

  ES5 shims source path

Error

  Error class for compilation errors.

JS

  JavaScript code to call UglifyJS

SourcePath

  UglifyJS source path

SplitFallbackPath

  String.split shim source path

VERSION

  Current version of Uglifier.

### Public Class Methods

compile(source, options = {}) click to toggle source

Minifies JavaScript code using implicit context.

@param source [IO, String] valid JS source code. @param options [Hash] optional overrides to +Uglifier::DEFAULTS+ @return [String] minified code.

    # File lib/uglifier.rb, line 149
    def self.compile(source, options = {})
      new(options).compile(source)
    end

compile_with_map(source, options = {}) click to toggle source

Minifies JavaScript code and generates a source map using implicit context.

@param source [IO, String] valid JS source code. @param options [Hash] optional overrides to +Uglifier::DEFAULTS+ @return [Array(String, String)] minified code and source map.

    # File lib/uglifier.rb, line 158
    def self.compile_with_map(source, options = {})
      new(options).compile_with_map(source)
    end

new(options = {}) click to toggle source

Initialize new context for Uglifier with given options

@param options [Hash] optional overrides to +Uglifier::DEFAULTS+

    # File lib/uglifier.rb, line 165
    def initialize(options = {})
      (options.keys - DEFAULTS.keys - [:comments, :squeeze, :copyright])[0..1].each do |missing|
        raise ArgumentError, "Invalid option: #{missing}"
      end
      @options = options
      @context = ExecJS.compile(uglifyjs_source)
    end

### Public Instance Methods

compile(source) click to toggle source

Minifies JavaScript code

@param source [IO, String] valid JS source code. @return [String] minified code.

    # File lib/uglifier.rb, line 177
    def compile(source)
      run_uglifyjs(source, false)
    end

Also aliased as: compress
compile_with_map(source) click to toggle source

Minifies JavaScript code and generates a source map

@param source [IO, String] valid JS source code. @return [Array(String, String)] minified code and source map.

    # File lib/uglifier.rb, line 186
    def compile_with_map(source)
      run_uglifyjs(source, true)
    end

compress(source) click to toggle source
Alias for: compile

[Validate]

Generated with the Darkfish Rdoc Generator 2.