gulp some tips
来源:互联网 发布:linux 绘制流程图工具 编辑:程序博客网 时间:2024/06/06 00:46
gulp作为替代grunt的task runner后起之秀,基于nodejs的stream操作模型,大大减少了对磁盘的操作因此大大提高了性能。
gulp error handling
var gulp = require('gulp');var coffee = require('gulp-coffee');var concat = require('gulp-concat');function handleError(error){ console.log(error); this.emit('end'); }gulp.task('coffee',function(){ return gulp.src('src/*.coffee') .pipe(coffee()) .on('error',handleError) .pipe(concat('all.js').pipe(gulp.dest('dist/'));}); gulp.task('watch', ['coffee'], function(){ gulp.watch('src/*.coffee',['coffee']);});
对于gulp.src这类的对glob文件系统的操作,如果文件或者文件夹不存在,后续的gulp stream操作默认也不会有任何错误抛出,有时很让人困惑。
其中的解决方案就是使用gulp-expect-file
var coffee = require('gulp-coffee');var expect = require('gulp-expect-file');gulp.task('mytask', function() { var files = ['idontexist.html']; return gulp.src(files) .pipe(expect(files)) .pipe(coffee());});
http://stackoverflow.com/questions/22343591/gulp-silently-failing-no-errors-printed-to-console
下面通过重载gulp.src的方法实现默认将plumber放到gulp stream errorhandlering中
var gulp = require('gulp');var plumber = require('gulp-plumber');var gutil = require('gulp-util'); var gulp_src = gulp.src;gulp.src = function() { return gulp_src.apply(gulp, arguments) .pipe(plumber(function(error) { // Output an error message gutil.log(gutil.colors.red('Error (' + error.plugin + '): ' + error.message)); // emit the end event, to properly end the task this.emit('end'); }) );};
https://www.timroes.de/2015/01/06/proper-error-handling-in-gulp-js/
阅读全文
0 0
- gulp some tips
- some tips
- some tips
- some tips
- some tips
- some java tips
- some vim tips
- Some Tips about Interbase
- Some MATLAB tips (一)
- Some MATLAB tips (二)
- Some MATLAB tips (三)
- Some PowerPoint VBA Tips
- Some Rtsp Tips-
- Some tips of Transcation
- some userful tips
- some tips about jsp
- some tips about jdbc
- Some useful DQL tips
- PHP的模板引擎这点事儿
- Hadoop 资源调度架构和实现
- laravel, Composer和autoloading
- struts2前台后台逻辑串联
- PHPStorm/webstorm tips
- gulp some tips
- mysql数据库导入外键约束问题
- git大文件管理
- rsync常用命令及格式
- PHP开发调优clockwork工具
- laravel中的$request对象构造及请求生命周期
- ORB算法解读
- laravel小抄
- laravel创建新model数据的两种方法