Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including gulp-uglify with all npm packages installed. Try it out:

var gulpUglify = require("gulp-uglify")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

gulp-uglify v3.0.2

Minify files with UglifyJS.


Minify JavaScript with UglifyJS3.


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

npm install --save-dev gulp-uglify


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

gulp.task('compress', function () {
  return pipeline(

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


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.


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 = {};

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free