Minify files with UglifyJs (evacuated from NSA/Microsoft Github)

Rob Palmer 27b26d4f8f fix(composer): invoke callback only once vor 6 Jahren
docs 14f1d7190f docs(pump): correct grammar vor 7 Jahren
lib b2492c4a15 fix: create safe-buffers vor 6 Jahren
test 27b26d4f8f fix(composer): invoke callback only once vor 6 Jahren
.gitignore 5d4c4c6968 chore(all): refactor unit tests vor 7 Jahren
.travis.yml b2492c4a15 fix: create safe-buffers vor 6 Jahren
CHANGELOG.md 2d4c9fced7 chore(pkg): redirect CHANGELOG vor 8 Jahren
LICENSE.md 845ae0fb1e chore(license): remove blockquote from license vor 7 Jahren
README.md 9c7b1aea2f docs(README): update links vor 7 Jahren
appveyor.yml 1a1325d84d chore(CI): add AppVeyor configuration vor 9 Jahren
composer.js 27b26d4f8f fix(composer): invoke callback only once vor 6 Jahren
index.js e2462fa5fe chore(travis): update test matrix vor 6 Jahren
package.json b2492c4a15 fix: create safe-buffers vor 6 Jahren

README.md

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 pump = require('pump');

gulp.task('compress', function (cb) {
  pump([
        gulp.src('lib/*.js'),
        uglify(),
        gulp.dest('dist')
    ],
    cb
  );
});

To help properly handle error conditions with Node streams, this project recommends the use of pump. For more information, see Why Use Pump?.

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 Pump?.

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
  );
});