I want to run a file stream through gulp(-watch) and change the contents of each file by using 'map-stream'. If I run the task gulp-js
on its own, the code works fine. If I gulp.watch
the files, it always saves some old version of the file that has nothing to do with the Buffer I attempt to write to file.contents
. Why?
My setup is as follows:
gulp.task('js-change-files', (done) => {
componentConfig = [];
gulp.src('src/**/*.js')
.pipe(map(function (file, done) {
file.contents = new Buffer.from(''+Math.random());
done(null, file);
}))
.pipe(gulp.dest(src.jsAssetsBuild + '/components/'))
.on('end', done);
});
I have another task that waits for the first one, just in case that matters:
gulp.task('js', ['js-change-files'], () => {
gulp.src('src/app.js')
// Do something with app.js
.pipe(gulp.dest(dirs.dist))
});
And the watch task:
gulp.task('watch', () => {
gulp.watch('src/**/*.js', ['js']);
});
I have narrowed the problem down to saving the buffer to file.contents
, since the buffer produces new random numbers as expected. But I cannot figure out what interferes here or where the old version of the file comes from.
via Kampfzwerg_Jana
No comments:
Post a Comment