上一节,以less为例,入门了gulp,并为任务结构做了抽离。

前端们,gulp该用起来了,简单的demo入门——gulp系列(一)

本节学习下gulp-notify,官方这样解释的:

gulp-notify :

gulp plugin to send messages based on Vinyl Files or Errors to Mac OS X, Linux or Windows using the node-notifier module. Fallbacks to Growl or simply logging

目的:

我们用notify的功能主要有两点,显示报错信息和报错后不终止当前gulp任务。

拿系列(一)来说,less如果出现编译错误,就会报错然后终止任务,这时less修改正确后,你还得手动重启gulp任务。

开始:

现在,我们在系列(一)的基础上,新建(检出)一个分支,添加notify功能

1.安装gulp-notify: npm install --save-dev gulp-notify

2.在gulp文件夹里新建一个目录,名叫util,目录里新建文件handleErrors.js用来配置notify

handleError.js代码如下:

var notify = require("gulp-notify");

module.exports = function(){

    var args = Array.prototype.slice.call(arguments);

    notify.onError({
title: 'compile error',
message: '<%=error.message %>'
}).apply(this, args);//替换为当前对象 this.emit();//提交
}

3.在less中引用,现在将less.js修改为如下:

var gulp = require('gulp');
var less = require('gulp-less');
var config = require('../config').less;
var handleErrors = require('../util/handleErrors'); gulp.task('less', function(){
return gulp.src(config.src) //less源文件
.pipe(less(config.settings)) //执行编译
.on('error', handleErrors) //交给notify处理错误
.pipe(gulp.dest(config.dest)) //输出目录
});

最终:

如果出现less错误,便会输出错误信息并继续gulp任务

还是那句话多看官方文档。

>>> github 地址,请选择  notify  分支<<<

gulp-notify处理报错----gulp系列(二)的更多相关文章

  1. semantic-ui使用gulp执行build-css报错

    1.执行gulp build-css报错 [09:40:49] Starting 'build-css'... Building CSS Potentially unhandled rejection ...

  2. gulp run 报错 gulp[3192]: src\node_contextify.cc:628: Assertion `args[1]->IsString()' failed.

    由于把node升级到了10以上的版本 执行gulp rjs打包文件报错,错误如下: gulp[3192]: src\node_contextify.cc:628: Assertion `args[1] ...

  3. gulp 压缩 uglify报错GulpUglifyError: unable to minify JavaScript

    引:https://www.cnblogs.com/vellemo/p/6898125.html 在压缩的时候报错:GulpUglifyError: unable to minify JavaScri ...

  4. gulp更新4.0后的报错(gulp报Did you forget to signal async completion?)

    本文首发于青云工作室 原文链接为 https://qystudio.ltd/posts/55153.html 缘起 今天我升级了gulp到4.0,在git三件套之后,网站并没有更新,我便登录了gith ...

  5. Android8 以上使用 UIautomator Viewer提示Unexpected error while obtaining UI hierarchy报错(方法二)

    一:最常见的一个问题就是:Android8及以上的系统无法获取到页面,提示报下面的错误 二:解决办法 1.下载新的tools,在下面链接里找到SDK tools下载 http://www.androi ...

  6. freemarker报错之十二

    1.错误描述 六月 04, 2014 10:31:47 下午 freemarker.log.JDK14LoggerFactory$JDK14Logger error 严重: Template proc ...

  7. freemarker写select组件报错总结(二)

    1.错误描述 六月 25, 2014 11:32:49 下午 freemarker.log.JDK14LoggerFactory$JDK14Logger error 严重: Template proc ...

  8. VueX中直接修改数据报错,修改一维数组,二维数组,报错的原因

    直接修改state中的的数据是不被允许的,会报错 这个时候可以使用三种种方式处理 第一种:使用拓展运算符,深拷贝一维数组或对象var arrA = [1,2,3,4]var a = [...arr]| ...

  9. sql server 2008 创建新数据库报错、创建表报错、更改表的设计报错

    一:创建数据库报错如下: 二:解决,将软件以管理员身份运行 三:创建表报错如下图: 四:解决办法,在你创建的数据库下面的安全里,找到你创建的用户,属性,添加权限,红色标注,然后确定: 五:更改表的设计 ...

随机推荐

  1. python查询

    #coding=utf-8 import MySQLdb conn = MySQLdb.Connect(host = '127.0.0.1',port=3306,user='root',passwd= ...

  2. Inno Setup 卸载前关闭进程或服务 x86 x64

    1.32位程序的PSVince.dll插件方法. [Setup] AppName=PSVince AppVerName=PSVince 1.0 DisableProgramGroupPage=true ...

  3. 用Task代替TheadPool

    TheadPool的问题 不支持线程的取消.完成.失败通知等交互性操作 不支持线程执行先后次序 using System; using System.Diagnostics; using System ...

  4. Python LDAP中的时间戳转换为Linux下时间

    (Get-ADUser zhangsan -Properties badpasswordtime).badpasswordtime返回值为:131172610187388712131172610187 ...

  5. ios取证

    摘录自:<IOS取证实战> Andrew Hoog著 viaForensics公司,今年已经募集到1600万创业基金 2007-2011年初,AT&T是在美国唯一为iphone提供 ...

  6. LeetCode:Spiral Matrix I II

    Spiral Matrix Given a matrix of m x n elements (m rows, n columns), return all elements of the matri ...

  7. Android SDK下载和更新失败的解决方法【转】

    启动 Android SDK Manager ,打开主界面,依次选择「Tools」.「Options...」,弹出『Android SDK Manager - Settings』窗口:在『Androi ...

  8. iPhone私有API

    一.基本知识 iPhone中的API除了公开的API:Published API外(或者叫文档中记录的API:Documented API),还有两类API:私有API:Private API和未公开 ...

  9. WWDC2016-session401-CodeSign大改版

    自动签名机制和手动签名都明显看起来很好用. 自动签名有log 手动签名有具体的错误提示信息. session401 Xcode Signing. 亲,你的眼睛好大 相声演员吗? Yeah,You ar ...

  10. android 九宫加密记事本

    自己写的超级安全记事本,用PBEWithMD5AndDES加密sqlite内容几乎无法破解, 九宫点密码登录, 支持备份到SDcard,email,network drivers etc. 附件Apk ...