上一节,以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  分支<<<

转载于:https://www.cnblogs.com/1wen/p/4552485.html

gulp-notify处理报错----gulp系列(二)相关推荐

  1. Debezium报错处理系列之二十九:Make sure that an instance of SQL Server is running on the host and accepting TCP

    Debezium报错处理系列之二十九:Make sure that an instance of SQL Server is running on the host and accepting TCP ...

  2. Debezium报错处理系列之三十六:Task threw an uncaught and unrecoverable exception. Task is being killed and will

    Debezium报错处理系列之三十六:Task threw an uncaught and unrecoverable exception. Task is being killed and will ...

  3. Debezium报错处理系列九:“ddl“ : “# Dummy event replacing event type 160 that slave cannot handle.“

    Debezium报错处理系列九:"ddl" : "# Dummy event replacing event type 160 that slave cannot han ...

  4. Debezium报错处理系列十一:Data row is smaller than a column index, internal schema representation is probabl

    Debezium报错处理系列十一:Data row is smaller than a column index, internal schema representation is probably ...

  5. Debezium报错处理系列之三十三:Unexpected error while connecting to MySQL and looking at BINLOG_FORMAT

    Debezium报错处理系列之三十三:Unexpected error while connecting to MySQL and looking at BINLOG_FORMAT mode: Cau ...

  6. Debezium报错处理系列之三十八:Timeout expired while fetching topic metadata

    Debezium报错处理系列之三十八:'trace': 'org.apache.kafka.common.errors.TimeoutException: Timeout expired while ...

  7. pycharm安装pytorch报错 提示系列问题 torch 包找不到因为pip版本低,结果升级了pip从19.3到20.2 4又提示高版不支持torch安装

    pycharm安装pytorch报错 提示系列问题  torch 包找不到因为pip版本低,结果升级了pip从19.3到20.2 4又提示高版不支持torch安装 DEPRECATION: The - ...

  8. 报错锦集二“nginx: [emerg] unknown directive “set_real_ip_from“ in /usr/local/nginx/conf/nginx.conf:50 ngi

    报错锦集二"nginx: [emerg] unknown directive "set_real_ip_from" in /usr/local/nginx/conf/ng ...

  9. gulp启动项目报错

    有一个需要gulp启动的项目,在启动过程中出现错误,用来记录一下. 直接到包含gulpfile.js的项目目录下用gulp启动报错,查看node版本是14.15.3版本,gulp是3.9.1版本,可能 ...

最新文章

  1. 做 Java 工程师,挺!好!
  2. 一 如何检查oracle的归档日志及空间占用率,清除归档日志、Oracle归档日志使用情况查询、查看oracle数据库一周产生的归档日志
  3. Native C++ _isnan()函数的应用
  4. jvm Classload method介绍
  5. OpenCV中图像轮廓检测
  6. js获取后端传过来的数据
  7. 深度:企业为什么需要一个平台级的OA产品?
  8. 考研计算机320分什么水平,考研320分算什么水平,能上211、985吗?很多人都答不上...
  9. nan null underfined的区别
  10. 车载网络基础——预备篇
  11. R语言第十讲 逻辑斯蒂回归
  12. 远端WWW服务支持TRACE请求
  13. 让子盒子水平和垂直居中的五种方法
  14. 湖北智禾教育:淘宝店铺详情页提高转化率该怎么做
  15. 方程sin平方x-x平方+1=0的有根区间?
  16. ASM 无法发现候选磁盘组----grid 11.2.0.3 asm 自检通不过 prvf-5184
  17. 推荐一些类似《纪念碑谷》这样接近艺术的游戏
  18. 伤寒杂病论.辨少阴病脉证并治
  19. 用上帝的恋爱公式讲线性回归-上
  20. 『2月特刊』伟大的朋友丨拿破仑(3)

热门文章

  1. 解决w3wp.exe内存占用问题[转载]
  2. 清华大学出品:罚梯度范数提高深度学习模型泛化性
  3. SimVLM:拒绝各种花里胡哨!CMUGoogle提出弱监督极简VLP模型,在多个多模态任务上性能SOTA...
  4. 开源库 | 监控视频中的目标检测与跟踪
  5. 数据太少怎么办?试试自监督学习,CV训练新利器,fast.ai新教程,LeCun点评
  6. 6 篇 2019 年最新模型剪枝技术合集
  7. FaceBoxes—官方开源CPU实时高精度人脸检测器
  8. 轻量化版本优于MobileNet系列 | Tokens-to-Token ViT: Training Vision Transformers from Scratch on ImageNet
  9. TCP、UDP(网络协议:传输层协议)
  10. 什么是嵌入式视觉、行业应用、目前挑战