参考 http://slides.com/contra/gulp#/
关于stream的概念可以参考node文集中的stream 手册
advantage
- With Gulp your bull file is code, not config
- You use standard libraries to do things
- plugins are simple and do one thing - most are a ~20 line function
- Task are executed with maximum concurrency
- I/O works the way you picture it below
sample
var gulp = require('gulp');
var pkg = require('./package.json');
var concat = require('gulp-concat');
var minify = require('gulp-minify');
var jshint = require('gulp-jshint');
var spawn = require('child_process').spawn;
var scriptFiles = './src/**/*.js';
var gulp.task('compile',function(){
//concat all script ,minify, and output
gulp.src(scriptFiles)
.pipe(concat({fileName: pkg.name+".js"}))
.pipe(minify())
.pipe(gulp.dest('./dist/'))
});
gulp.task('test',function(){
gulp.src(scriptFiles).pipe(jshint());
//run out tests
spawn('npm',['test'],{stdio:'inherit'});
});
gulp.task('default',function(){
gulp.run('test','compile');
gulp.watch(scriptFiles,function(){
gulp.run('test','compile');
})
});
1.run tests
2.lints code -检查代码
3.concats javascript
4.minifies it
5.run again if files are changed
Gulp does nothing but provide some streams and a basic task system
start
Gulp has only 5 function you need to learn
1.gulp.task(name,fn)
It registers the function with a name .You can optionally specify some dependencies if other tasks need to run first.
2.gulp.run(tasks...)
Run all tasks with maximum concurrency
3.gulp watch(glob,fn)
Runs a function when a file that matches the glob changes included in core for simplicity.
4.gulp.src(glob)
This returns a readable stream .Takes a file system glob (like grunt) and starts emitting files that match. This is piped to other streams.
5.gulp.dest(folder)
This returns a writable stream.File objects piped to this are saved to the file system.