I found out about the gulp source code and tried to write a gulp plugin.
Now I'm embarrassed by something.
This is my plugin code below:
module.exports = function(){
return through2.obj(function(file,encode,callback){
console.log(vinyl.isVinyl(file));
console.log(file._isVinyl)
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);
})
}
This is the part of the gulp source code where the files are created vinyl:
https://github.com/gulpjs/vinyl-fs/blob/master/lib/src/wrap-with-vinyl-file.js
MY ABBREVIATION:
transformFunctionregistered in though2.obj()gets the object filethat should be vinyl.
Why vinyl.isVinyl()returns false?
Why filedoes an object have no property _isVinyl?
source
share