Javascript 为什么在gulp watch期间乙烯基file.contents无法更新?
我想通过gulp(-watch)运行一个文件流,并使用“map stream”更改每个文件的内容。如果我自己运行任务Javascript 为什么在gulp watch期间乙烯基file.contents无法更新?,javascript,node.js,gulp,gulp-watch,Javascript,Node.js,Gulp,Gulp Watch,我想通过gulp(-watch)运行一个文件流,并使用“map stream”更改每个文件的内容。如果我自己运行任务gulpjs,代码工作正常。如果我gulp watch文件,它总是保存一些与我试图写入file.contents的缓冲区无关的文件的旧版本。为什么? 我的设置如下: const gulp = require('gulp'), map = require('map-stream'); gulp.task('js-change-files', (done) => {
gulpjs
,代码工作正常。如果我gulp watch
文件,它总是保存一些与我试图写入file.contents的缓冲区无关的文件的旧版本。为什么?
我的设置如下:
const gulp = require('gulp'),
map = require('map-stream');
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('dist/'))
.on('end', done);
});
我还有一个任务等待第一个任务,以防万一:
gulp.task('js', ['js-change-files'], () => {
gulp.src('src/app.js')
// Do something with app.js
.pipe(gulp.dest('dist/'))
});
观察任务:
gulp.task('watch', () => {
gulp.watch('src/**/*.js', ['js']);
});
我已将问题缩小到将缓冲区保存到file.contents
,因为缓冲区会按预期生成新的随机数。但我无法找出是什么干扰了这里,或者文件的旧版本来自何处