Java Reference
In-Depth Information
Gulp uses a package.json file and a Gulp file (which is always saved as gulpfile.js) to create
tasks, but it uses a different notation to the Grunt file. Gulp uses code to accomplish tasks,
rather than configuration as Grunt does. Gulp works by using the concept of streams of data
provided from files that are piped from one plugin to the next, where the end result is piped
to a given destination. For example, the minification plugin will take a stream of files from
the src folder and pipe them into the minifier, which will then pipe the minified code into a
folder called js. This means it can run faster than Grunt, as intermediary files don't need to
be created.
Gulp tries to keep its plugins streamlined so that they only complete a single task. As a res-
ult more plugins are often needed to accomplish a set of tasks. Gulp also has the ability to
watch files using the method. This will watch a file or collection of files
and run a function whenever a file changes. This can be useful if you want to, for example,
automatically run tests as soon as any file changes to quickly spot any errors.
The following is an example of a Gulp file that can be used to minify a group of files. It
uses the gulp-minify plugin, which uses UglifyJS to minify any JavaScript files that
are in the src directory:
var gulp = require('gulp'), // requires gulp
minify = require('gulp-minify'); // loads the minify
source = 'src/*', // this specifies where the source
files are
dest = 'js/'; // this specifies the destination of the
gulp.task('default', function(){
gulp.src(source) // the stream to read
.pipe(minify()) // pipe the stream to the minify plugin
.pipe(gulp.dest('./js/')); // where the stream is
written to
To run this default task, enter the following command in a terminal:
Search WWH ::

Custom Search