gulp-uglify
    Overview
    Alternatives
    Playground
    Insights & Analysis
    Issues
    Versions
    Documentation
    Find an Expert
    Dependencies
    Career Opportunities
    Code

gulp-uglify

Minify files with UglifyJS.

3.0.2  •  Published 6 months ago  •  by Terin Stock  •  MIT License

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

Tags

gulpplugin
Get a weekly digest of your favorite packages
We track new versions of your favorite packages, read the changelogs, and summarize them - so you dont have to
Just $5/month per user

Popularity

Weekly Downloads
407.1K
Stars
1.2K

Issues and PRs

Activity

Last ver 6 months ago
Created 6 years ago
Last commit 6 months ago
10 days between commits

Sustainability

23 contributors

Technology

Node version: 11.10.0
12.8K unpacked

Legal and Compliance

MIT License
OSI Approved
0 vulnerabilities

Top Experts

Terin Stock
Maintainer, 156 commits, 31 merges, 4 PRs
Works at cloudflare
greenkeeperio-bot
19 commits, 46 PRs
Works at greenkeeperio
Florian Reiterer
2 commits, 2 PRs
Ziad EL KHOURY HANNA
2 commits, 2 PRs
Jeff Escalante
2 commits
Blaine Bublitz
1 commits, 1 PRs
Works at Paying the maintainers Tidelift