Cool Grunt Plugins for Modern Web
Nice Grunt Plugins
JavaScript task runners such as Grunt have become extremely popular with front-end developers. This is because they help to do the one thing which we all want to do in our jobs – save time!. With more than 5,000 (and counting) Grunt plugins now available, it can be hard for developers to find those ‘diamonds in the rough’. So here are listed top grunt plugins one may use.
I recommend using Jekyll asset plugin for the task as this is straight solution.
PLUGIN | DESCRIPTION |
---|---|
jshint | Validate files using jshint |
uglify | Minify JS files using UglifyJS |
watch | Run tasks whenever watched files are changed |
clean | Clean up files and folders |
copy | Copy files and folders |
concat | Combine files into a single file |
cssmin | Compress CSS files |
less | Compile LESS files to CSS |
imagemin | Minify PNG, JPG, and GIFs |
compass | Compile SASS to CSS using Compass |
htmlmin | Minify HTML files |
.
Few Notable Plugins
Uglify [JS Parsing, Magling, Minification, Compression & Beautification]
- This tasks delegates to UglifyJS2, so consider UglifyJS2 Documentation for advanced task configurations
- Uglify performs JavaScript
parsing
,magling
,minification
,compression
andbeautification
via UglifyJS2 - This plugin can also add a
banner or header text
to each javascript file and minifies them usinggrunt uglify
- Install plugin to project folder by executing from shell in root folder of project
npm install grunt-contrib-uglify --save
command. - This will add an entory to package.json file. Now inside gruntfile.js add following lines
//Load plugin
grunt.loadNpmTasks('grunt-contrib-uglify');
//Plugin configuration
uglify: {
options: {
banner: '/*\nPKG: <%= pkg.name %>\nVER: <%= pkg.version %>\nREPO: <%= pkg.repository.url %>\nAUTHOR: <%= pkg.author %>\nUGLIFIED: <%= grunt.template.today("dd-mm-yyyy") %> \n*/\n'
},
build: {
files: {
'js/image-dialog.min.js': ['js/image-dialog.js']
}
}
}
jshint
- JShint is a JavaScript code quality tool, see DEMO
- JShint documentation is availaible here
- Execute
grunt jshint
and you’ll see code quality errors in your JavaScript files - You’ve to place this file in repository root for same as ‘.jsintrc’ for this to work
{
"node": true,
"esnext": true,
"bitwise": true,
"camelcase": true,
"curly": true,
"eqeqeq": true,
"immed": true,
"indent": 2,
"latedef": true,
"newcap": true,
"noarg": true,
"quotmark": "single",
"regexp": true,
"undef": true,
"unused": true,
"strict": true,
"trailing": true,
"smarttabs": true,
"white": true
}
- Install plugin to project folder by executing
npm install grunt-contrib-jshint --save
command. - This will add an entory to package.json file. Now inside gruntfile.js add following lines
//Load plugin
grunt.loadNpmTasks('grunt-contrib-jshint');
//Plugin configuration
jshint: {
all: ['assets/languages/*.js']
},
Many more cool GRUNT PLUGIN compilation at:
https://gitlab.com/refgits/essential-grunt-plugins.git