// match ' client/js/somedir/somefile.js ' and resolve ' base ' to ' client/js/' . Pipe (Minify ()) . Pipe (Gulp.dest (' build ')); // write ' build/somedir/somefile.js ' gulp.src (' client/js/**/*.js ', {base: ' client ' }). pipe (Minify ()) . Pipe (Gulp.dest (' Build ')); // write ' build/js/somedir/somefile.js '
Gulp.src ('./client/templates/*.jade ') . Pipe (Jade ()) . Pipe (Gulp.dest ('./build/templates ')) . Pipe (Minify ()) . Pipe (Gulp.dest ('./build/minified_templates '));
Gulp.task (' Somename ',function() { //do some things}); Gulp.task (' MyTask ', [' array ', ' of ', ' task ', ' names '],function() { //do some things});//the task can be executed asynchronously if FN can do one of the following://1. Accept a callback//execute a command in the shellvarexec = require (' child_process '). Exec;gulp.task (' Jekyll ',function(CB) {//compiling JekyllEXEC (' Jekyll build ',function(err) {if(ERR)returnCB (ERR);//return errorCB ();//Complete Task });});//2. Return a streamGulp.task (' Somename ',function() { varstream = gulp.src (' client/**/*.js '). Pipe (Minify ()). Pipe (Gulp.dest (' Build ')); returnstream;});//Returns a PromisevarQ = require (' q ')); Gulp.task (' Somename ',function() { varDeferred =Q.defer (); //performing an asynchronous operationSetTimeout (function() {deferred.resolve (); }, 1); returndeferred.promise;});
var watcher = Gulp.watch (' js/**/*.js ', [' uglify ', ' Reload ']), Watcher.on (function( Event) { console.log (' File ' + Event.path + ' was ' + Event.type + ', running tasks ... ');}); Gulp.watch (function(event) { console.log (' File ' + Event.path + ' was ' + Event.type + ', Runni ng tasks ... ') ;
Reference:
http://www.ydcss.com/archives/424
https://www.gulpjs.com.cn/docs/api/
Gulp (b) Gulp Chinese API