Using Gulp
In previous article I blog about some gulp plugins that I use in my project. Now I want to share what is gulp and how to use it.
Gulp is a streaming build system, what I mean by streaming is it uses file stream for all of it file manipulation. It will not write file in disk unless you tell it.
The gulp api is ridiculously light and simple. It contain only 4 functions.
- gulp.task
- gulp.src
- gulp.dest
- gulp.watch
gulp.task is for defining your tasks.
If your task have dependencies, you can specify it in array and your task will be executed after all dependencies are done
In console or terminal windows you can type gulp taskname To execute your task or if your task is named as default you just can type gulp to execute the task
gulp.src will grab your files and convert it to stream. It uses .pipe for chaining it’s output into other gulp plugins.
gulp.dest will convert your stream into file and write it to disk.
Below is a sample task that copy+paste files into other directory.
gulp.watch is uses to watch files. when any files are changes, it will perform tasks described
Sample above will watch all .js files in source/javascript and execute jshint if any of that files are changes.