我正在处理一个gulp任务,需要调试一些文件并在控制台中读取它们。例如,我想要在控制台中输出它们的内容。
无论是通过流还是简单任务都可以。我试图打印vinyl对象的内容...但是没有任何好的结果。
或者尝试使用与fs节点模块相同的结果...来完成它。
有没有办法打印文件的内容?
gulp.task('task', function(){
console.log( gulp.src('path/to/file.txt').content.toString() );
});
或者通过Node
进行操作。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);
});
有没有办法打印文件的内容?