https://github.com/lautis/uglifier
Ruby wrapper for UglifyJS JavaScript compressor.
https://github.com/lautis/uglifier
Keywords
javascript minify ruby uglifyjs
Keywords from Contributors
rubygems activerecord activejob mvc rack rspec sinatra reflection pry irb
Last synced: about 3 hours ago
JSON representation
Repository metadata
Ruby wrapper for UglifyJS JavaScript compressor.
- Host: GitHub
- URL: https://github.com/lautis/uglifier
- Owner: lautis
- License: mit
- Created: 2010-11-03T20:56:15.000Z (about 15 years ago)
- Default Branch: master
- Last Pushed: 2024-09-22T10:00:25.000Z (about 1 year ago)
- Last Synced: 2025-11-17T11:05:02.398Z (about 1 month ago)
- Topics: javascript, minify, ruby, uglifyjs
- Language: JavaScript
- Homepage: http://www.rubydoc.info/gems/uglifier
- Size: 1.74 MB
- Stars: 619
- Watchers: 12
- Forks: 85
- Open Issues: 48
- Releases: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.txt
README.md
Uglifier
Ruby wrapper for UglifyJS JavaScript
compressor.
UglifyJS only works with ES5. If you need to compress ES6, ruby-terser is a better option.
Rails
When used in Rails, replace
config.assets.js_compressor = :uglifier
with
config.assets.js_compressor = Uglifier.new(harmony: true)
in config/environments/production.rb.
Installation
Uglifier is available as a ruby gem.
$ gem install uglifier
Ensure that your environment has a JavaScript interpreter supported by
ExecJS. Using therubyracer gem
is a safe choice if a runtime isn't already present. Note that while JScript built-in Windows 7 and older works, it is extremely slow.
Usage
require 'uglifier'
Uglifier.new.compile(File.read("source.js"))
# => js file minified
# Or alternatively
Uglifier.compile(File.read("source.js"))
Uglifier also supports generating source maps:
uglified, source_map = Uglifier.new.compile_with_map(source)
When initializing UglifyJS, you can tune the behavior of UglifyJS by passing options. For example, if you want disable variable name mangling:
Uglifier.new(:mangle => false).compile(source)
# Or
Uglifier.compile(source, :mangle => false)
Available options and their defaults are
{
:output => {
:ascii_only => true, # Escape non-ASCII characters
:comments => :copyright, # Preserve comments (:all, :jsdoc, :copyright, :none, Regexp (see below))
: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
: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
:width => 80, # Specify line width when beautifier is used (only with beautifier)
:preamble => nil, # Preamble for the generated JS file. Can be used to insert any code or comment.
:wrap_iife => false, # Wrap IIFEs in parenthesis. Note: this disables the negate_iife compression option.
:shebang => true, # Preserve shebang (#!) in preamble (shell scripts)
:quote_style => 0, # Quote style, possible values :auto (default), :single, :double, :original
:keep_quoted_props => false # Keep quotes property names
},
:mangle => {
:eval => false, # Mangle names when eval of when is used in scope
:reserved => ["$super"], # Argument names to be excluded from mangling
:sort => false, # Assign shorter names to most frequently used variables. Often results in bigger output after gzip.
:toplevel => false, # Mangle names declared in the toplevel scope
:properties => false, # Mangle property names
:keep_fnames => false # Do not modify function names
}, # Mangle variable and function names, set to false to skip mangling
:mangle_properties => {
:regex => nil, # A regular expression to filter property names to be mangled
:ignore_quoted => false, # Only mangle unquoted property names
:debug => false, # Mangle names with the original name still present
}, # Mangle property names, disabled by default
: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
:unsafe_comps => false, # Reverse < and <= to > and >= to allow improved compression. This might be unsafe when an at least one of two operands is an object with computed values due the use of methods like get, or valueOf. This could cause change in execution order after operands in the comparison are switching. Compression only works if both comparisons and unsafe_comps are both set to true.
:unsafe_math => false, # Optimize numerical expressions like 2 * x * 3 into 6 * x, which may give imprecise floating point results.
:unsafe_proto => false, # Optimize expressions like Array.prototype.slice.call(a) into [].slice.call(a)
: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 loops when condition can be statically determined
:unused => true, # Drop unreferenced functions and variables
:toplevel => false, # Drop unreferenced top-level functions and variables
:top_retain => [], # prevent specific toplevel functions and variables from `unused` removal
: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
:collapse_vars => false, # Collapse single-use var and const definitions when possible.
:reduce_funcs => false, # Inline single-use functions as function expressions. Depends on reduce_vars.
:reduce_vars => false, # Collapse variables assigned with and used as constant values.
:negate_iife => true, # Negate immediately invoked function expressions to avoid extra parens
:pure_getters => false, # Assume that object property access does not have any side-effects
:pure_funcs => nil, # List of functions without side-effects. Can safely discard function calls when the result value is not used
:drop_console => false, # Drop calls to console.* functions
:keep_fargs => false, # Preserve unused function arguments
:keep_fnames => false, # Do not drop names in function definitions
:passes => 1, # Number of times to run compress. Raising the number of passes will increase compress time, but can produce slightly smaller code.
:keep_infinity => false, # Prevent compression of Infinity to 1/0
:side_effects => true, # Pass false to disable potentially dropping functions marked as "pure" using pure comment annotation. See UglifyJS documentation for details.
:switches => true, # de-duplicate and remove unreachable switch branches
}, # Apply transformations to code, set to false to skip
:parse => {
:bare_returns => false, # Allow top-level return statements.
:expression => false, # Parse a single expression, rather than a program (for parsing JSON).
:html5_comments => true, # Ignore HTML5 comments in input
:shebang => true, # support #!command as the first line
:strict => false
},
:define => {}, # Define values for symbol replacement
:enclose => false, # Enclose in output function wrapper, define replacements as key-value pairs
:keep_fnames => false, # Generate code safe for the poor souls relying on Function.prototype.name at run-time. Sets both compress and mangle keep_fanems to true.
:source_map => {
:map_url => false, # Url for source mapping to be appended in minified source
:url => false, # Url for original source to be appended in minified source
:sources_content => false, # Include original source content in map
:filename => nil, # The filename of the input file
:root => nil, # The URL of the directory which contains :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
},
:error_context_lines => 8, # How many context lines surrounding the error line. Env var ERROR_CONTEXT_LINES overrides this option
:harmony => false # Enable ES6/Harmony mode (experimental). Disabling mangling and compressing is recommended with Harmony mode.
}
When passing a regular expression to the output => comments option, be sure to pass a valid Ruby Regexp.
The beginning and ending of comments are removed and cannot be matched (/*, */, //). For example:
When matching
/*!
* comment
*/
use Uglifier.new(output: {comments: /^!/}).
Development
Tests are run using
bundle exec rake
See CONTRIBUTING for details about working on and contributing to Uglifier.
Copyright
© Ville Lautanala. Released under MIT license, see LICENSE for details.
Owner metadata
- Name: Ville Lautanala
- Login: lautis
- Email:
- Kind: user
- Description:
- Website:
- Location: Helsinki, Finland
- Twitter: lautis
- Company:
- Icon url: https://avatars.githubusercontent.com/u/19264?v=4
- Repositories: 136
- Last ynced at: 2024-04-16T00:23:10.324Z
- Profile URL: https://github.com/lautis
GitHub Events
Total
- Issues event: 1
- Watch event: 8
- Issue comment event: 4
- Fork event: 3
Last Year
- Issues event: 1
- Watch event: 8
- Fork event: 1
Committers metadata
Last synced: about 11 hours ago
Total Commits: 616
Total Committers: 35
Avg Commits per committer: 17.6
Development Distribution Score (DDS): 0.102
Commits in past year: 0
Committers in past year: 0
Avg Commits per committer in past year: 0.0
Development Distribution Score (DDS) in past year: 0.0
| Name | Commits | |
|---|---|---|
| Ville Lautanala | l****s@g****m | 553 |
| Joshua Peek | j****h@j****m | 13 |
| Jun Aruga | j****a@r****m | 7 |
| Conrad Irwin | c****n@g****m | 5 |
| sanemat | o****n@g****m | 3 |
| Jon Bardin | d****s@g****m | 2 |
| Matt Kirk | m****t@m****m | 2 |
| Reed Loden | r****d@r****m | 2 |
| Rory Hardy | g****k@g****m | 2 |
| pavel | p****y@e****z | 2 |
| Erik Michaels-Ober | s****k@g****m | 1 |
| Edward Anderson | n****s@n****m | 1 |
| Antonio Terceiro | t****o@s****g | 1 |
| Andreas Banholzer | A****r@M****m | 1 |
| Akira Matsuda | r****e@d****p | 1 |
| adamjonas | j****s@f****m | 1 |
| Sylvester Keil | sk@s****t | 1 |
| Markus Amalthea Magnuson | m****n@g****m | 1 |
| vfrride | j****f@j****t | 1 |
| randoum | r****m@g****m | 1 |
| gmarik | g****k@g****m | 1 |
| eGust | e****c@g****m | 1 |
| Zach Morek | z****k@g****m | 1 |
| Tim Branyen | t****m@t****m | 1 |
| Sylvester Keil | s****r@k****t | 1 |
| Simen Bekkhus | s****1@g****m | 1 |
| Sean Linsley | x****v@g****m | 1 |
| Salimane Adjao Moustapha | me@s****m | 1 |
| Ryunosuke Sato | t****s@g****m | 1 |
| Ryan Shaw | r****w@g****m | 1 |
| and 5 more... | ||
Committer domains:
- causes.com: 1
- cpan.org: 1
- braingourmets.com: 1
- salimane.com: 1
- keil.or.at: 1
- tabdeveloper.com: 1
- jpcutler.net: 1
- semicolon.at: 1
- flatironschool.com: 1
- dio.jp: 1
- me.com: 1
- softwarelivre.org: 1
- nilbus.com: 1
- easy.cz: 1
- reedloden.com: 1
- matthewkirk.com: 1
- redhat.com: 1
- joshpeek.com: 1
Issue and Pull Request metadata
Last synced: 6 days ago
Total issues: 79
Total pull requests: 27
Average time to close issues: 4 months
Average time to close pull requests: 5 months
Total issue authors: 73
Total pull request authors: 17
Average comments per issue: 3.06
Average comments per pull request: 0.89
Merged pull request: 19
Bot issues: 0
Bot pull requests: 0
Past year issues: 1
Past year pull requests: 2
Past year average time to close issues: N/A
Past year average time to close pull requests: about 11 hours
Past year issue authors: 1
Past year pull request authors: 2
Past year average comments per issue: 0.0
Past year average comments per pull request: 0.5
Past year merged pull request: 2
Past year bot issues: 0
Past year bot pull requests: 0
Top Issue Authors
- ndvbd (3)
- ghost (3)
- junaruga (2)
- yivo (2)
- vemarav (1)
- chris-geelhoed (1)
- goldenstar999 (1)
- neyp (1)
- blovato (1)
- cykerway (1)
- Tenari (1)
- pickhardt (1)
- dcalixto (1)
- tansaku (1)
- joker-777 (1)
Top Pull Request Authors
- junaruga (6)
- lautis (5)
- ahorek (3)
- tricknotes (2)
- kianmeng (2)
- SimenB (2)
- francois (1)
- a6b8 (1)
- greysteil (1)
- JRaspass (1)
- pedrofurtado (1)
- amatsuda (1)
- mdnorman (1)
- yhirano55 (1)
- EdwardBetts (1)
Top Issue Labels
- UglifyJS bug (1)
Top Pull Request Labels
Package metadata
- Total packages: 3
-
Total downloads:
- rubygems: 559,385,336 total
- Total docker downloads: 1,159,958,132
- Total dependent packages: 468 (may contain duplicates)
- Total dependent repositories: 674,411 (may contain duplicates)
- Total versions: 278
- Total maintainers: 1
- Total advisories: 2
gem.coop: uglifier
Uglifier minifies JavaScript files by wrapping UglifyJS to be accessible in Ruby
- Homepage: http://github.com/lautis/uglifier
- Documentation: http://www.rubydoc.info/gems/uglifier/
- Licenses: MIT
- Latest release: 4.2.1 (published about 1 year ago)
- Last Synced: 2025-12-16T15:32:48.884Z (about 22 hours ago)
- Versions: 93
- Dependent Packages: 0
- Dependent Repositories: 0
- Downloads: 279,684,201 Total
- Docker Downloads: 579,979,066
-
Rankings:
- Dependent repos count: 0.0%
- Dependent packages count: 0.0%
- Average: 0.029%
- Downloads: 0.086%
- Maintainers (1)
- Advisories:
rubygems.org: uglifier
Uglifier minifies JavaScript files by wrapping UglifyJS to be accessible in Ruby
- Homepage: http://github.com/lautis/uglifier
- Documentation: http://www.rubydoc.info/gems/uglifier/
- Licenses: MIT
- Latest release: 4.2.1 (published about 1 year ago)
- Last Synced: 2025-12-16T21:16:11.146Z (about 16 hours ago)
- Versions: 93
- Dependent Packages: 468
- Dependent Repositories: 674,411
- Downloads: 279,701,135 Total
- Docker Downloads: 579,979,066
-
Rankings:
- Dependent repos count: 0.021%
- Downloads: 0.066%
- Dependent packages count: 0.099%
- Docker downloads count: 0.243%
- Average: 0.93%
- Stargazers count: 2.303%
- Forks count: 2.851%
- Maintainers (1)
- Advisories:
proxy.golang.org: github.com/lautis/uglifier
- Homepage:
- Documentation: https://pkg.go.dev/github.com/lautis/uglifier#section-documentation
- Licenses: mit
- Latest release: v4.2.1+incompatible (published about 1 year ago)
- Last Synced: 2025-12-15T10:10:43.511Z (2 days ago)
- Versions: 92
- Dependent Packages: 0
- Dependent Repositories: 0
-
Rankings:
- Stargazers count: 2.407%
- Forks count: 2.746%
- Average: 6.383%
- Dependent packages count: 9.576%
- Dependent repos count: 10.802%
Dependencies
- bundler >= 1.3 development
- rake ~> 12.0 development
- rspec ~> 3.0 development
- sourcemap ~> 0.1.1 development
- execjs >= 0.3.0, < 3
- actions/checkout v2 composite
- ruby/setup-ruby v1 composite
Score: 31.32374020952372