Problems encountered by gulp

  node.js, question

I have only recently contacted gulp but have encountered some problems:

task
 src
 watch
 run
 start
 pipe
 What exactly do these methods mean? There has been some confusion.
 
 I have read some materials, but I am still very vague about some knowledge points. Please help me explain them. For example, thank you very much.

task

gulp.task('somename', function() {
 // Do stuff
 });

Such a thing is called onetask(Mission). You can specify a series of operations in it, such as writing onecopyThe mission, the goal is toabFiles in both directories are copied tocUnder the directory.

src

Since each task operates on some files, how do you select these files? It will be usedsrc, as follows:

gulp.src('client/templates/*.jade')
 ...
 ...;

Selectedclient/templates/All in the directoryjadeFiles, as for wildcards*How it is identified can be seenglob-syntax

watch

Still the same as above, since tasks are all operations on files, there must be a case where you want to trigger a task automatically when files change (you may have changed your code). For example, automatic compilationlesstocss, can be used like this:

gulp.watch('less/*.less', function(event) {
 //Automatically compile the modified less file to the target directory
 gulp.src(event.path)
 .pipe(less())
 . pipe(gulp.dest ('build directory');
 });

run

Usually the task we use is to pass at the command line inside.Gulp task nameTo complete, but sometimes also need to directly start a task in the code inside, can be usedGulp.run (task name)To perform the specified task.

I can’t remember this clearly, and I can’t find this API in the official website document. It should have been abandoned.

start

startIt should be an internal method. I always think you shouldn’t call it directly.

pipe

Pipelines are the essence of streaming coding, andgulpIt doesn’t matter much, but it isgulpIt only supports streaming writing. For details:pipe