Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

64 lines (44 sloc) 2.913 kb

Uglifier Build Status Dependency Status

Ruby wrapper for UglifyJS JavaScript compressor.

Installation

Uglifier is available as a ruby gem.

$ gem install uglifier

Ensure that your environment has a JavaScript interpreter supported by ExecJS. Installing therubyracer gem is a safe choice and having node in PATH works too.

Usage

require 'uglifier'

Uglifier.new.compile(File.read("source.js"))
# => js file minified

# Or alternatively
Uglifier.compile(File.read("source.js"))

When initializing UglifyJS, you can tune the behavior of UglifyJS by passing options. For example, if you want top-level variable names to be mangled:

Uglifier.new(:toplevel => true).compile(source)

# Or
Uglifier.compile(source, :toplevel => true)

Available options and their defaults are

{
  :mangle => true, # Mangle variable and function names, use :variables to skip function mangling
  :toplevel => false, # Mangle top-level variable names
  :except => [], # Variable names to be excluded from mangling
  :max_line_length => 32 * 1024, # Maximum line length
  :squeeze => true, # Squeeze code resulting in smaller, but less-readable code
  :seqs => true, # Reduce consecutive statements in blocks into single statement
  :dead_code => true, # Remove dead code (e.g. after return)
  :lift_vars => false, # Lift all var declarations at the start of the scope
  :unsafe => false, # Optimizations known to be unsafe in some situations
  :copyright => true, # Show copyright message
  :ascii_only => false, # Encode non-ASCII characters as Unicode code points
  :inline_script => false, # Escape </script
  :quote_keys => false, # Quote keys in object literals
  :define => {}, # Define values for symbol replacement
  :beautify => false, # Ouput indented code
  :beautify_options => {
    :indent_level => 4,
    :indent_start => 0,
    :space_colon => false
  }
}

Development

Uglifier bundles its javascript dependencies using git submodules. If you want to rebuild the javascript you will first need to get the latest version of the code with git submodule update --init. After you have the git submodules at the desired versions, run rake js to recreate lib/uglify.js.

See CONTRIBUTING for details about contributing to Uglifier.

Copyright

© Ville Lautanala, Flowdock. Released under MIT license, see LICENSE.txt for more details.

Jump to Line
Something went wrong with that request. Please try again.