Skip to content
Ruby wrapper for UglifyJS JavaScript compressor.
Ruby JavaScript
Pull request Compare This branch is 239 commits behind lautis:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

Uglifier Build Status Dependency Status

Ruby wrapper for UglifyJS JavaScript compressor.

NOTICE: This documentation is for unreleased Uglifier 2.0, which is based on UglifyJS 2.0.


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.


require 'uglifier'"source.js"))
# => js file minified

# Or alternatively

Uglifier also supports generating source maps:

uglified, source_map =

When initializing UglifyJS, you can tune the behavior of UglifyJS by passing options. For example, if you want disable variable name mangling: => false).compile(source)

# Or
Uglifier.compile(source, :mangle => false)

Available options and their defaults are

  :output => {
    :ascii_only => false, # Escape non-ASCII characterss
    :comments => :copyright, # Preserve comments (:all, :jsdoc, :copyright, :none)
    :inline_script => false, # Escape occurrences of </script in strings
    :quote_keys => false, # Quote keys in object literals
    :max_line_len => 32 * 1024, # Maximum line length in minified code
    :ie_proof => true, # Output block brakcets around do-while loops
    :bracketize => false, # Bracketize if, for, do, while or with statements, even if their body is a single statement
    :semicolons => true, # Separate statements with semicolons
    :preserve_line => false, # Preserve line numbers in outputs
    :beautify => false, # Beautify output
    :indent_level => 4, # Indent level in spaces
    :indent_start => 0, # Starting indent level
    :space_colon => false, # Insert space before colons (only with beautifier)
    :width => 80 # Specify line width when beautifier is used (only with beautifier)
  :mangle => {
    :except => ["$super"] # Argument names to be excluded from mangling
  }, # Mangle variable and function names, set to false to skip mangling
  :compress => {
    :sequences => true, # Allow statements to be joined by commas
    :properties => true, # Rewrite property access using the dot notation
    :dead_code => true, # Remove unreachable code
    :drop_debugger => true, # Remove debugger; statements
    :unsafe => false, # Apply "unsafe" transformations
    :conditionals => true, # Optimize for if-s and conditional expressions
    :comparisons => true, # Apply binary node optimizations for comparisons
    :evaluate => true, # Attempt to evaluate constant expressions
    :booleans => true, # Various optimizations to boolean contexts
    :loops => true, # Optimize lops when condition can be statically determined
    :unused => true, # Drop unreferenced functions and variables
    :hoist_funs => true, # Hoist function declarations
    :hoist_vars => false, # Hoist var declarations
    :if_return => true, # Optimizations for if/return and if/continue
    :join_vars => true, # Join consecutive var statements
    :cascade => true # Cascade sequences
  }, # Apply transformations to code, set to false to skip
  :define => {}, # Define values for symbol replacement
  :source_filename => nil, # The filename of the input file
  :source_root => nil, # The URL of the directory which contains :source_filename
  :output_filename => nil, # The filename or URL where the minified output can be found
  :input_source_map => nil # The contents of the source map describing the input


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.


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

Something went wrong with that request. Please try again.