Gulp Writing Task
In last tutorial we have learnt about basics of Gulp and How to setting up small project for testing Gulp. In this chapter we will be learning -
- How to declare Gulp Dependencies ?
- How to create Gulp task ?
- How to run Gulp task ?
How to declare Gulp Dependencies ?
While creating an application we need to install different plugins required for the project activities. Once the plugin is installed, we need to include these plugins in our configuration files. Usually package managers (i.e Gulp, bower) handles this task of loading dependencies
Suppose we need to minify the content of HTML file then we need to install gulp-htmlmin
plugin in our application.
npm i gulp-htmlmin --save-dev
Upon installation we need to define dependencies for it in the configuration file like -
var htmlmin = require('gulp-htmlmin');
How to create Gulp task ?
var gulp = require('gulp');
var htmlmin = require('gulp-htmlmin');
gulp.task('minify', function() {
return gulp.src('src/*.html')
.pipe(htmlmin({collapseWhitespace: true}))
.pipe(gulp.dest('dist'))
});
Leave a comment