All Projects → lautis → Uglifier

lautis / Uglifier

Licence: mit
Ruby wrapper for UglifyJS JavaScript compressor.

Programming Languages

javascript
184084 projects - #8 most used programming language
ruby
36898 projects - #4 most used programming language

Labels

Projects that are alternatives of or similar to Uglifier

kirby-html-minifier
Minify the html output of a site built with Kirby CMS
Stars: ✭ 20 (-96.67%)
Mutual labels:  minify
imagemin-power-cli
Optimize (compress) images with power using imagemin 💪
Stars: ✭ 13 (-97.84%)
Mutual labels:  minify
Node Minify
Light Node.js module that compress javascript, css and html files
Stars: ✭ 404 (-32.78%)
Mutual labels:  minify
csso-webpack-plugin
CSSO full restructuring minification files to serve your webpack bundles
Stars: ✭ 104 (-82.7%)
Mutual labels:  minify
phaser-typescript-webpack
Another Phaser CE boilerplate using TypeScript and Webpack.
Stars: ✭ 17 (-97.17%)
Mutual labels:  minify
Badge Size
🍻 Displays the size of a given file in your repository.
Stars: ✭ 277 (-53.91%)
Mutual labels:  minify
web-minify-helper
Help web developer to make their js & css files minified easily!
Stars: ✭ 12 (-98%)
Mutual labels:  minify
Imagemin
[Unmaintained] Minify images seamlessly
Stars: ✭ 4,948 (+723.29%)
Mutual labels:  minify
kirby-blade
Enable Laravel Blade Template Engine for Kirby 3
Stars: ✭ 20 (-96.67%)
Mutual labels:  minify
Tinyify
a browserify plugin that runs various optimizations, so you don't have to install them all manually. makes your bundles tiny!
Stars: ✭ 392 (-34.78%)
Mutual labels:  minify
packtag
A JSP Taglib for delivering minified, combined and gzip-compressed resources (JavaScript and CSS).
Stars: ✭ 22 (-96.34%)
Mutual labels:  minify
DeveloperFolio
A DevFolio/Developer Portfolio built using ReactJs and Animation libraries.
Stars: ✭ 51 (-91.51%)
Mutual labels:  minify
Webmarkupmin
The Web Markup Minifier (abbreviated WebMarkupMin) - a .NET library that contains a set of markup minifiers. The objective of this project is to improve the performance of web applications by reducing the size of HTML, XHTML and XML code.
Stars: ✭ 312 (-48.09%)
Mutual labels:  minify
gatsby-plugin-optimize-svgs
A Gatsby Plugin to minify SVGs output to the filesystem during the build.
Stars: ✭ 39 (-93.51%)
Mutual labels:  minify
Intro.js
Lightweight, user-friendly onboarding tour library
Stars: ✭ 20,826 (+3365.22%)
Mutual labels:  minify
OpenBook-E-Commerce
An e-commerce progressive web application, built with mern stack. It has features like product buy, order management by admin, payment gateway, cart, checkout and lot more.
Stars: ✭ 53 (-91.18%)
Mutual labels:  minify
Uglifycss
Port of YUI CSS Compressor from Java to NodeJS
Stars: ✭ 259 (-56.91%)
Mutual labels:  minify
Packem
📦⚡ A precompiled JavaScript module bundler
Stars: ✭ 586 (-2.5%)
Mutual labels:  minify
Minify
✂️ An ES6+ aware minifier based on the Babel toolchain (beta)
Stars: ✭ 4,303 (+615.97%)
Mutual labels:  minify
Compress Images
Minify size your images. Image compression with extension: jpg/jpeg, svg, png, gif. NodeJs
Stars: ✭ 331 (-44.93%)
Mutual labels:  minify

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].