Gulp is a tool to run task automatically, Follwing are the task which we have to perform every time when we make any change in a project, after using gulp we don't have to worry about these task anymore gulp will perform thee tasks for us. tasks like -
-
Concatinating and minifying Javascripts and CSS files.
-
Removing console and debugger statements from scripts.
-
Compressing new and modified images.
.
. so on.
Gulp uses node.js for performing it's tasks, so first you need to install Node.js
Now You can install gulp globaly using npm.
$ sudo npm install -g gulp
npm install -g gulp
Grunt and Gulp both do the same things for us. Basically Grunt is a Node.js Based Task Runner while Gulp is a task runner which uses Node.js
-
Grunt plug-ins performs multiple tasks, while Gulp Plug-ins are designed to do one thing only.
-
Grunt uses Json like data configuration files, while Gulp uses lenear Javascript
cd Gulp-Introduction-Tutorials
src -
images - uncompressed images
scripts - multiple preprocessed script files
styles - multiple preprocessed css files
bulid -
images - compressed images
scripts - a single minified script file
styles - a silgle minified file
npm install --save-dev gulp.
Gulp don't do much on it's own. we need to install and configure plug-ins to perform specific tasks, In gulp there is sepertae plugin for each tasks. At this time, Gulp supports more then 2500 plugins, and this number will increase in future.
npm install --save-dev gulp-jshint
var gulp = require('gulp');
var jshint = require('gulp-jshint');
gulp.task('jshint', function() {
gulp.src('./src/scripts/*.js')
.pipe(jshint())
.pipe(jshint.reporter('default'));
});
This Plugin will check the performance of your javascript file, and will log the errors in any javascript file on console.
npm install gulp-changed --save-dev
npm install gulp-imagemin --save-dev
gulp.task('imagemin', function() {
var imgSrc = './src/images/**/*',
imgDst = './build/images';
gulp.src(imgSrc)
.pipe(changed(imgDst))
.pipe(imagemin())
.pipe(gulp.dest(imgDst));
});
This task will first change the src of image to the destination folder and will compress the image.
gulp.task('default', ['imagemin', 'jshint'], function() { });
Fot this you have to run only "gulp" from the command line.
For more information about gulp, there is one interesting article https://www.sitepoint.com/introduction-gulp-js/
There are several more plugins look the officail website of gulp for more plugins. http://gulpjs.com/plugins/