私はgulpソースコードについて学び、gulpプラグインを作成しようとしました。gulpによって放出されたvinylファイルのvinyl.isVinyl()がfalseを返すのはなぜですか?
今、私は何かについて混乱しています。
これは、以下の私のプラグインのコードです:
module.exports = function(){
return through2.obj(function(file,encode,callback){
console.log(vinyl.isVinyl(file));//false
console.log(file._isVinyl) // undefined
// the reason ? file is not Object of vinyl ? file's property of '_isVinyl' is undefine ?
if(file.isNull()){
callback(null,file);
}
if(file.isStream()){
file.contents = file.contents.pipe(through2(function(chuck,encode,callback){
if(util.isNull(chuck)){
callback(null, chuck);
}
if(util.isBuffer(chuck)){
chuck = new Buffer(String(chuck)
.replace(commentReg, '')
.replace(blankSpaceReg,''))
}
callback(null,chuck);
}));
}
if(file.isBuffer()){
file.contents = new Buffer(String(file.contents)
.replace(commentReg, '')
.replace(blankSpaceReg,''));
}
callback(null,file);
})
}
これはvinyl
ファイルが作成されて一気のソースコードの一部です:
https://github.com/gulpjs/vinyl-fs/blob/master/lib/src/wrap-with-vinyl-file.js
MY CONFUSION:
transformFunction
に登録済みthough2.obj()
はvinyl
ファイルであるfile
オブジェクトを受け取ります。
なぜですかvinyl.isVinyl()
返信false
?
file
オブジェクトにはなぜ_isVinyl
プロパティがありません。