It is the Sixth part of the gulp for beginners series which deals in introducing gulp.js and then making you familiar with some basic gulp plugins. This article talks about 4 gulp plugins which are as follows :
This is a very basc gulp plugin which is used to change , append or crop the extension of the file. The snippet is given below :
var gulp = require('gulp');
var ext = require('gulp-ext');
gulp.task('default', function () {
return gulp.src('source/first.js')
.pipe(ext.append('on'))
.pipe(gulp.dest('dist'));
});
Run it at bash or command line using the following command :
$gulp
This plugin is used to stop the breaking of pipeline due to some error in any of the plugin. The snippet is given below :
var gulp = require('gulp');
var plumber = require('gulp-plumber');
var uglify = require('gulp-uglify');
gulp.task('default', function () {
gulp.src('source/*.js')
.pipe(plumber())
.pipe(uglify())
.pipe(gulp.dest('/destination'));
});
Run it at bash or command line using the following command :
$gulp
This gulp plugin along with many other functionalities is used to generate logs . Snippet is given below :
var gulp = require('gulp');
var util = require('gulp-util');
var uglify = require('gulp-uglify');
gulp.task('ut' , function() {
gulp.src('source/*.js')
.pipe(util.log('got some files'))
.pipe(uglify())
.pipe(util.log('uglified them'))
.pipe(gulp.dest('destination'));
.pipe(util.log('sent in destination folder'))
});
Run it at bash or command line using the following command :
$ gulp ut
This gulp plugin is used when we want to run a task only iff certain condition is met. The snippet is given below :
var gulp = require('gulp');
var gif = require('gulp-if');
var uglify = require('gulp-uglify');
var value = true;
gulp.task('abc', function() {
gulp.src('source/*.js')
.pipe(gif(value, uglify()))
.pipe(gulp.dest('destination'));
});
Run it at bash or command line using the following command :
$ gulp abc