Cleaning your build

If you ran the previous sample, you might have noticed that when you ran it without the source files, your minified scripts were updated, but your copied source files were not removed from the prod folder. It is best practice to clean up any build folders before you create a new build. This assures that your build works from scratch and that you do not have any cached files. There used to be a plugin for this, but there is a Node.js module that already does what we need. As I said earlier, Gulp plugins should work on input and produce some output. Deleting files and folders does not fit that description though, so this is not really a Gulp plugin task anyway. So, we are going to use the Node.js del module (https://www.npmjs.com/package/del):

npm install del --save-dev

You can now just use del in a Gulp task:

var gulp = require('gulp');
var del = require('del');

gulp.task('clean', function () {
del(['prod/*']);
});

Easy as that. Also, do not forget to configure your minify job, so it will run the new clean task before it does any minifying. You can pass in an array of task names that have to be executed (asynchronously) before the current task executes:

gulp.task('minify', ['clean'], function () {

If you now run gulp or gulp minify, you will find that it first deleted the prod folder and then put your newly minified scripts in it.

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

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