gulp打印/logging文件的内容

例如,我正在处理一个想要debugging某个文件的gulp任务,并且想在控制台中读取它。

无论是通过stream还是通过简单的任务都无关紧要。 我尝试打印乙烯基物体的内容…但没有任何好的结果

gulp.task('task', function(){ console.log( gulp.src('path/to/file.txt').content.toString() ); }); 

或通过节点

 function sendTo(res) { return through( function write(data) { // this will be called once for each file res.write(data.contents); }, function end() { // this will be called when there are no more files res.end() } ); } gulp.task('task', function(res){ gulp.src('path/to/file.txt') .pipe(sendTo(res)); }); 

或尝试使用fs节点模块做到这一点,具有相同的结果…

 fs.readFile('path/to/file.txt', {encoding: 'utf-8', flag: 'rs'}, function(e, data) { if (e) return console.log(e); console.log(data); }); 

任何想法打印文件的内容?

这是我的其他答案的确切问题,asynchronous的gulp /节点尝试读取文件之前,可以创build文件…

简单的forms是节点(是的,我是对的:P)

 fs.readFile('path/to/file.txt', {encoding: 'utf-8', flag: 'rs'}, function(e, data) { if (e) return console.log(e); console.log(data); });