###gulp.js学习笔记
gulp.js 是类似grunt的一个自动化工具,相对比于grunt的config文件的复杂,gulp.js只需要5个函数即可。(参考地址:http://www.codersgrid.com/2014/01/11/gulp-js-streaming-build-tool-beats-grunt-js/)
####gulp的一个demo
//gulpfile
var gulp = require(‘gulp’); gulp.task('default’,function(){ //register a task //some code })
gulp中的方法很有意思的一点在于支持pipe管道,这个方法比grunt的命令更加清晰,下面我们看下用法
代码就不更多解释了,太清晰了...完全不用注释.../* gulpfile for my Ros project 2014/02/23 */ var gulp = require('gulp') ,uglify = require('gulp-uglify') ,concat = require('gulp-concat') ,size = require('gulp-size');
var filePath = { appScriptPath:{ src:’app/scripts/*/.js’, dest:’app/build/js’ } } gulp.task('default’,function(){ return gulp.src(filePath.appScriptPath.src) .pipe(uglify()) .pipe(concat(‘main.js’)) .pipe(gulp.dest(filePath.appScriptPath.dest)); });
####实际项目中需要的module #####增量编译 gulp-changed gulp-cached gulp-changed
这两个模块有点问题,尚在研究,还没有跑起来增量编译,不过从速度上来讲,确实很不错,而且代码很易懂var gulp = require('gulp'); var changed = require('gulp-changed'); var ngmin = require('gulp-ngmin'); // just as an example
var SRC = 'src/*.js’; var DEST = 'dist’;
gulp.task('default’, function () { gulp.src(SRC) .pipe(changed(DEST)) //配置DEST目录 // ngmin will only get the files that // changed since the last time it was run .pipe(ngmin()) .pipe(gulp.dest(DEST)); });