Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

gulp-uglify

terinjokes922.5kMIT3.0.2TypeScript support: definitely-typed

Minify files with UglifyJS.

gulpplugin

readme

gulp-uglify

Minify JavaScript with UglifyJS3.

Installation

Install package with NPM and add it to your development dependencies:

npm install --save-dev gulp-uglify

Usage

var gulp = require('gulp');
var uglify = require('gulp-uglify');
var pipeline = require('readable-stream').pipeline;

gulp.task('compress', function () {
  return pipeline(
        gulp.src('lib/*.js'),
        uglify(),
        gulp.dest('dist')
  );
});

To help properly handle error conditions with Node streams, this project recommends the use of pipeline, from readable-stream.

Options

Most of the minify options from the UglifyJS API are supported. There are a few exceptions:

  1. The sourceMap option must not be set, as it will be automatically configured based on your Gulp configuration. See the documentation for Gulp sourcemaps.

Errors

gulp-uglify emits an 'error' event if it is unable to minify a specific file. The GulpUglifyError constructor is exported by this plugin for instanceof checks. It contains the following properties:

  • fileName: The full file path for the file being minified.
  • cause: The original UglifyJS error, if available.

Most UglifyJS error messages have the following properties:

  • message (or msg)
  • filename
  • line

To see useful error messages, see Why Use Pipeline?.

Using a Different UglifyJS

By default, gulp-uglify uses the version of UglifyJS installed as a dependency. It's possible to configure the use of a different version using the "composer" entry point.

var uglifyjs = require('uglify-js'); // can be a git checkout
                                     // or another module (such as `uglify-es` for ES6 support)
var composer = require('gulp-uglify/composer');
var pump = require('pump');

var minify = composer(uglifyjs, console);

gulp.task('compress', function (cb) {
  // the same options as described above
  var options = {};

  pump([
      gulp.src('lib/*.js'),
      minify(options),
      gulp.dest('dist')
    ],
    cb
  );
});

changelog

As of version 2.0.0, the CHANGELOG is maintained on GitHub Releases.

Change Log

1.5.4 (2016-06-22)

1.5.3

  • Updated UglifyJS to 2.6.2

1.5.2

  • Updated UglfiyJS to 2.6.1

1.5.0

  • Update UglifyJS to 2.6.0.
  • CI and dependencies chores.
  • Attempt to resolve issue #109 where "ghost" files would appear in generated sourcemaps.

1.4.2

  • Updated UglifyJS to 2.5.0.
  • CI and dependencies chores.

1.4.1

  • Detect if options is a non-Object and log a warning.

    Older versions of Node.js did not allow Strings to be passed to Object.keys leading to errors and confusion to users following certain tutorials.

1.4.0

  • Deprecated the preserveComments option of "some".
  • Added the preserveComments option of "license" that uses uglify-save-license.

1.3.0

  • Updated UglifyJS to 2.4.24.
  • Streams3 support via through2 dependency update.

1.2.0

  • Update dependencies, including UglifyJS to 2.4.19.

1.1.0

  • Fix sources path in source maps (thanks @floridoo)
  • Update UglifyJS to 2.4.16 (thanks @tschaub)

1.0.0

  • Handle cases where UglifyJS uses e.msg instead of e.message for error codes. Fixes #51.
  • Supplement UglifyJS’s source map merging with vinyl-sourcemap-apply to correct issues where sources and sourcesContent were different. Fixes #43.
  • Refactor option parsing and defaults, and calls to uglify-js, to reduce complexity of the main function.
  • Added tests for the previously forgotten preserveComments option.
  • Updated UglifyJS to 2.4.15.
  • Changed dependencies to explicit ranges to avoid node-semver issues.

0.3.2

  • Removed the PluginError factory wrapper
  • Removed test that was failing due to gulp-util issue.
  • Tests should end the streams they are writing to.
  • Update dependencies. Fixes #44. Fixes #42.

0.3.1

  • Fixed homepage URL in npm metadata
  • Removes UglifyJS-inserted sourceMappingURL comment [Fixes #39]
  • Don’t pass input source map to UglifyJS if there are no mappings
  • Added installation instructions

0.3.0

  • Removed support for old style source maps
  • Added support for gulp-sourcemap
  • Updated tape development dependency
  • Dropped support for Node 0.9
  • UglifyJS errors are no longer swallowed

0.2.1

  • Correct source map output
  • Remove gulp dependency by using vinyl in testing
  • Passthrough null files correctly
  • Report error if attempting to use a stream-backed file

0.2.0

  • Dropped support for Node versions less than 0.9
  • Switched to using Streams2
  • Add support for generating source maps
  • Add option for preserving comments