Grunt Uglify Plugin

5.2.2 · active · verified Sun Apr 19

grunt-contrib-uglify is a Grunt plugin designed to minify JavaScript files efficiently using the UglifyJS library. As of its current stable version, 5.2.2, it provides a crucial build step for optimizing frontend assets by reducing file sizes. The package typically sees releases driven by updates to its underlying dependencies, particularly UglifyJS, or to maintain compatibility with newer Node.js and Grunt versions, rather than a fixed release cadence. Its primary differentiator is its deep integration into the Grunt task runner ecosystem, allowing developers to configure JavaScript minification directly within their Gruntfiles with fine-grained control over UglifyJS options like mangling, compression, and source map generation. This makes it a go-to solution for projects that leverage Grunt for their build automation, abstracting the complexities of direct UglifyJS CLI usage into a declarative task configuration.

Common errors

Warnings

Install

Imports

Quickstart

This Gruntfile.js example configures the `uglify` task to minify and concatenate two JavaScript files into one, adding a banner and generating a source map. It then defines a default task to run `uglify`.

module.exports = function(grunt) {
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    uglify: {
      options: {
        banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n',
        sourceMap: true,
        sourceMapName: 'dist/app.min.js.map'
      },
      my_target: {
        files: {
          'dist/app.min.js': ['src/js/module1.js', 'src/js/module2.js']
        }
      }
    }
  });

  // Load the plugin that provides the "uglify" task.
  grunt.loadNpmTasks('grunt-contrib-uglify');

  // Default task(s).
  grunt.registerTask('default', ['uglify']);
};

view raw JSON →