gulp watch不更新JSON文件

gulp watch不更新JSON文件,json,gulp,handlebars.js,watch,Json,Gulp,Handlebars.js,Watch,我正在使用gulp观看json文件,当它被编辑时,我需要查看浏览器中反映的更改,但只有当我停止观看并再次运行gulp时,它才会起作用: 我在这里关注json文件中的更改: gulp.task('watch', function() { gulp.watch('./src/layout.json', ['compileHandlebars']); }); 在任务中: gulp.task('compileHandlebars', function () { var buildSe

我正在使用gulp观看json文件,当它被编辑时,我需要查看浏览器中反映的更改,但只有当我停止观看并再次运行gulp时,它才会起作用:

我在这里关注json文件中的更改:

gulp.task('watch', function() {
     gulp.watch('./src/layout.json', ['compileHandlebars']);
});
在任务中:

gulp.task('compileHandlebars', function () {
    var buildSettings = require('./src/layout.json');
    var templateData = buildSettings,
    options = {
        batch : ['./src/assets/templates/'],
    }
    gulp.src('./src/index.handlebars')
        .pipe(handlebars(templateData, options))
        .pipe(rename('index.html'))
        //.pipe(gulp.dest('./src/compiled'));
        .pipe(gulp.dest('./dist'));
});

我明白了。为了从缓存中清除json文件,我需要在任务顶部添加以下内容:

delete require.cache[require.resolve('./src/layout.json')]
整个任务:

gulp.task('compileHandlebars', function () {
        delete require.cache[require.resolve('./src/layout.json')]
        var buildSettings = require('./src/layout.json');
        var templateData = buildSettings,
        options = {
            batch : ['./src/assets/templates/'],
        }

        gulp.src('./src/index.handlebars')
            .pipe(handlebars(templateData, options))
            .pipe(rename('index.html'))
            .pipe(htmlmin({collapseWhitespace: true}))
            .pipe(htmlmin({removeComments: true}))
            .pipe(gulp.dest('./dist'));
    });

我明白了。为了从缓存中清除json文件,我需要在任务顶部添加以下内容:

delete require.cache[require.resolve('./src/layout.json')]
整个任务:

gulp.task('compileHandlebars', function () {
        delete require.cache[require.resolve('./src/layout.json')]
        var buildSettings = require('./src/layout.json');
        var templateData = buildSettings,
        options = {
            batch : ['./src/assets/templates/'],
        }

        gulp.src('./src/index.handlebars')
            .pipe(handlebars(templateData, options))
            .pipe(rename('index.html'))
            .pipe(htmlmin({collapseWhitespace: true}))
            .pipe(htmlmin({removeComments: true}))
            .pipe(gulp.dest('./dist'));
    });