【问题标题】:gulp print/log the content of a filegulp 打印/记录文件的内容
【发布时间】:2015-04-11 21:21:14
【问题描述】:

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

不管是通过流还是通过简单任务。 我尝试打印乙烯基对象的内容...但没有任何好的结果

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

through 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 node module 进行操作,结果相同...

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

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

【问题讨论】:

标签: javascript node.js gulp


【解决方案1】:

这正是我的另一个答案的问题,gulp/node 的异步尝试在创建文件之前读取文件...

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

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

【讨论】:

    猜你喜欢
    • 2012-06-12
    • 2014-06-16
    • 1970-01-01
    • 1970-01-01
    • 2021-03-01
    • 2017-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多