Gulp basics

In abstract terms, a task runner takes some input, works with that, and produces an output. That output could then be used for further processing. For example, a JavaScript file could be the input, a minifying job could be the process (that is making your JavaScript unreadable, but very compact), and the minified JavaScript would be the output. Now, the minified JavaScript could be input to a new test process, which would have some report as its output. Gulp does exactly this. Gulp is a little different from other task runners in a way that it keeps intermediate results in memory instead of writing them to disk.

Installing Gulp is as easy as doing npm install. We also want the Gulp CLI for easy use:

npm install gulp --save-dev
npm install gulp-cli -g

The next thing we need is a so-called gulpfile. In the root of your project, Chapter06, in the book's GitHub repository, create a new file and name it gulpfile.js. Gulp simply starts a Node.js process, so we can do whatever Node.js can do in the gulpfile. We start by requiring Gulp and setting a default task:

var gulp = require('gulp');

gulp.task('default', function() {
console.log("We're just running tasks...");
});

You can now run this from the command line by simply running the gulp command. Make sure your command line is in your project folder. You can, of course, also manually target your gulpfile:

gulp
[alternatively]
gulp --gulpfile path_to_your_gulpfilegulpfile.js

The output should be We're just running tasks.... If it was, you know you did it right and Gulp is working.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.37.20