Gulp
Gulp is a nodejs streaming build tool, the so-called streaming general meaning is to think of the construction process as a link pipe (pipe).
Why did you do it?
To explain why, you have to mention UNIX. UNIX itself provides only a relatively small number of commands, but you can perform powerful functions with a combination of commands. The connection between commands and commands is usually the pipe.
Similarly, with Gulp, you just need to remember 5 commands. These 5 commands are gulp provided to us by a set of streaming built shelves, it is equivalent to provide the pipe function in Unix. As for the function of each command in pipe, you can use the existing plugin or custom completion.
Installing Gulp
If the NPM version is older, you may experience installation Gulp failure
Update/install NPM:
Curl Https://www.npmjs.org/install.sh | sudo sh
Install NPM:
NPM Install-g Gulp
NPM Install--save-dev Gulp
After the installation is complete, you can try it correctly with Gulp-v.
[20:29:16] CLI version 3.8.5
[20:29:16] Local version 3.8.5
One of the simplest gulp scripts
Gulpfile.js
---
var gulp = require (' Gulp ')
Gulp.task (' Default ', function () {
Console.log (' This is the default task ')
})
Run: Gulp
[20:29:02] starting ' default ' ...
This is the default task
[20:29:02] finished ' default ' after 74μs
Gulp, like most of the build tools, are composed of task, in the example above, default is the task name, and it is the default task. You can also run with gulp default and perform the same task.
A second Simple gulp script (SRC, pipe)
Installing the Jasmine Plugin
NPM Install--save-dev Gulp-jasmine
Gulpfile.js
---
var gulp = require (' gulp ');
var jasmine = require (' Gulp-jasmine ');
Gulp.task (' Default ', function () {
Return gulp.src (' Spec/google.spec.js ')
. Pipe (Jasmine ());
});
Install superagent for easy testing
Spec/google.spec.js
---
var superagent = require (' superagent ')
Describe (' Google ', function () {
It ("Should return the Google homepage", function (done) {
Superagent.get (' http://www.google.com/')
. End (Function (e, res) {
Expect (e). ToBe (NULL)
Expect (Res.status). ToBe (200)
Done ();
})
})
})
Run Tests
[21:01:07] starting ' default ' ...
[21:01:07] finished ' default ' after MS
.
Finished in 0.41 seconds
1 Test, 2 assertions, 0 failures
Gulp have more plug-ins, such as the use of the above gulp-jasmine is one of them.
GULP.SRC (' Spec/google.spec.js ')
. Pipe (Jasmine ());
Interesting things come, what is src and pipe?
Let's look at a UNIX command first:
Cat Gulpfile.js | Wc-l
This is two separate commands, cat gulpfile.js used to get gulpfile.js file content, Wc-l used to count the number of lines in the file, they use "|" Connected. The output of the cat gulpfile.js as input to the wc-l. This is a more common Unix command.
Gulp This idea, the above Gulp command can be thought of as:
' Spec/google.spec.js ' | Jasmine ()
This should be a very good understanding of it.
5 Gulp commands you just need to know.
Gulp.task (name, FN) you should have seen this.
Gulp.run (Tasks ...) Run multiple tasks in parallel as much as possible
Gulp.watch (Glob, FN) executes FN When the glob content changes
GULP.SRC (glob) returns a readable stream
Gulp.dest (Glob) returns a writable stream
Knowing these, you look at the example of Https://github.com/gulpjs/gulp, it seems to be a lot easier
Resources:
http://www.sitepoint.com/introduction-gulp-js/
Http://slides.com/contra/gulp
Https://github.com/substack/stream-handbook