我正在为Gulp编写插件,为了处理文件,我需要获取它的完整路径。我使用了 through2 包,然后准备processFile(file)
了函数,但作为 through2 的参数,它以奇怪的类似 XML 的格式接收文件,而不是类似的对象file.path
,file.encoding
等等。
当 through2 以以下格式返回每个文件时,我如何接收 file.path:
<File "relative/path/to/file/aaa.js" ...
完整代码:
var through = require('through2');
module.exports = function() {
return through.obj(function(file, encoding, callback) {
function processFile(file){
console.log(file); // returns <File "relative/path/to/file/aaa.js" ...
}
callback(null, processFile(file));
});
};