console.log to stdout on gulp events(console.log 到标准输出的 gulp 事件)
问题描述
我想在 gulp 任务正在运行或已经运行时登录到标准输出(配置环境).
I want to log to stdout (the config environment) when a gulp task is running or has run.
类似这样的:
gulp.task('scripts', function () {
var enviroment = argv.env || 'development';
var config = gulp.src('config/' + enviroment + '.json')
.pipe(ngConstant({name: 'app.config'}));
var scripts = gulp.src('js/*');
return es.merge(config, scripts)
.pipe(concat('app.js'))
.pipe(gulp.dest('app/dist'))
.on('success', function() {
console.log('Configured environment: ' + environment);
});
});
我不确定我应该响应什么事件或在哪里可以找到这些事件的列表.任何指针?非常感谢.
I am not sure what event I should be responding to or where to find a list of these. Any pointers? Many thanks.
推荐答案
(2017 年 12 月,提供日志记录的 gulp-util
模块,已弃用.Gulp 团队建议开发人员将此功能替换为 fancy-log
模块.此答案已更新以反映这一点.)
(In December 2017, the gulp-util
module, which provided logging, was deprecated. The Gulp team recommended that developers replace this functionality with the fancy-log
module. This answer has been updated to reflect that.)
fancy-log
提供日志记录,最初构建由 Gulp 团队提供.
fancy-log
provides logging and was originally built by the Gulp team.
var log = require('fancy-log');
log('Hello world!');
要添加日志记录,Gulp 的 API 文档告诉我们.src
返回:
To add logging, Gulp's API documentation tell us that .src
returns:
返回可以通过管道传输到插件的 Vinyl 文件流.
Returns a stream of Vinyl files that can be piped to plugins.
Node.js 的 Stream
文档提供了事件列表.放在一起,这里有一个例子:
Node.js's Stream
documentation provides a list of events. Put together, here's an example:
gulp.task('default', function() {
return gulp.src('main.scss')
.pipe(sass({ style: 'expanded' }))
.on('end', function(){ log('Almost there...'); })
.pipe(minifycss())
.pipe(gulp.dest('.'))
.on('end', function(){ log('Done!'); });
});
注意:end
事件可能会在插件完成之前被调用(并且已经发送了它自己的所有输出),因为当所有数据都已刷新到底层系统"时会调用该事件".
Note: The end
event may be called before the plugin is complete (and has sent all of its own output), because the event is called when "all data has been flushed to the underlying system".
这篇关于console.log 到标准输出的 gulp 事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:console.log 到标准输出的 gulp 事件


- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- 400或500级别的HTTP响应 2022-01-01
- 失败的 Canvas 360 jquery 插件 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01