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.
npm install grunt-contrib-uglifyVerified import paths — ran on the pinned version, not inferred.
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`.
Upgrade your Node.js installation to version 12 or newer (e.g., using nvm).
Refer to the `uglify-js` documentation for the equivalent options under `output`, `parse`, `mangle`, and `sourceMap` configurations. For example, `ASCIIOnly` is now `output.ascii_only` and `preserveComments` is `output.comments`.
Use the default `report: 'min'` for faster builds, or only enable `report: 'gzip'` when specific size analysis is required.
If encountering parsing errors with modern JavaScript syntax, integrate a transpilation step (e.g., using `grunt-babel`) into your Grunt workflow before the `uglify` task.
Ensure `npm install grunt-contrib-uglify --save-dev` has been run and `grunt.loadNpmTasks('grunt-contrib-uglify');` is present in your Gruntfile.js.Check the detailed error message for line numbers and specific syntax issues. If using modern JavaScript (ES6+), ensure it's properly transpiled before UglifyJS processes it, or verify that your `uglify-js` dependency (and thus `grunt-contrib-uglify`) is up-to-date enough to support the syntax.
Review all `devDependencies` for specific Node.js compatibility matrixes. Update Node.js to a version compatible with all project dependencies, or downgrade conflicting dependencies.