Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为什么在gulp watch期间乙烯基file.contents无法更新?_Javascript_Node.js_Gulp_Gulp Watch - Fatal编程技术网

Javascript 为什么在gulp watch期间乙烯基file.contents无法更新?

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) => {

我想通过gulp(-watch)运行一个文件流,并使用“map stream”更改每个文件的内容。如果我自己运行任务
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
,因为缓冲区会按预期生成新的随机数。但我无法找出是什么干扰了这里,或者文件的旧版本来自何处