Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Ruby wrapper for UglifyJS JavaScript compressor.
JavaScript Ruby

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
spec
vendor
.document
.gitignore
.gitmodules
.rspec
Gemfile
LICENSE.txt
README.rdoc
Rakefile
VERSION
build.js
uglifier.gemspec

README.rdoc

Uglifier

Ruby wrapper for UglifyJS JavaScript compressor.

Installation

Uglifier is available as ruby gem.

$ gem install uglifier

Ensure that your environment has a JavaScript interpreter supported by ExecJS. Usually, installing therubyracer gem is the best alternative.

Usage

require 'uglifier'

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

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)

Defaults are

{
  :mangle => true, # Mangle variables names
  :toplevel => false, # Mangle top-level variable names
  :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)
  :beautify => false, # Ouput indented code
  :beautify_options => {
    :indent_level => 4,
    :indent_start => 0,
    :quote_keys => false,
    :space_colon => 0
  }
}

Contributing to uglifier

  • Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet

  • Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it

  • Fork the project

  • Start a feature/bugfix branch

  • Commit and push until you are happy with your contribution

  • Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.

  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

Copyright

Copyright © 2010 Ville Lautanala. See LICENSE.txt for further details.

Something went wrong with that request. Please try again.