Hey folks!I'm building a little gulp-plugin where I'd like to access the file's output directory, meaning where it will be gulp.dest(). While looking for the simplest way to do so, I've stumbled across something I can't really explain. It looks like, within a stream's transform function, pushing the file updates its path.For example, let's consider this gulpfile.js:var gulp = require('gulp'); var test = require('./index.js'); gulp.task('default', function () { return gulp .src('scripts.js') .pipe(test()) .pipe(gulp.dest('dist')); }); With this index.js:var Transform = require('stream').Transform; module.exports = function () { var stream = new Transform({ objectMode: true }); stream._transform = function transform (file, encoding, callback) { console.log(file.path); this.push(file); console.log(file.path); callback(); }; return stream; }; And the console output is:/scripts.js /dist/scripts.js So before it's pushed, the path refers to the actual file's path but then to its "future" path. That's what I'm looking for but I can't really understand what's going on and sometimes it's updating the path, sometimes not (I mean in other conditions, the example above works every time).
Submitted April 03, 2016 at 03:03PM by Zhouzi
No comments:
Post a Comment