Gulp-The streaming build system

参考 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
344444.jpg

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.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 2月28日晚,百度客户端、移动端百度搜索出现大面积访问故障,搜索页面出现“很抱歉,您要访问的页面不存在!”的提示。...
    dsfsd545阅读 2,241评论 0 1
  • 推荐指数,五星。值得反复读的经典。 德罗海达的一家,最终剩了什么? 他们的悲剧源于什么? 故事当中有两个关键人物菲...
    编辑王阅读 3,459评论 0 1
  • (一) 深深浅浅的烙印, 明明灭灭的暗涌。 隐隐约约的不安, 断断续续的惆怅。 宁愿孤独的徜徉, 不为寂寞的狂欢。...
    肖像以北阅读 1,369评论 0 0

友情链接更多精彩内容