shannonmoeller / gulp-hb

A sane Gulp plugin to compile Handlebars templates. Useful as a static site generator.
http://npm.im/gulp-hb
MIT License
147 stars 14 forks source link

handlebars partials do not reload in combination with gulp watch #15

Closed elisechant closed 9 years ago

elisechant commented 9 years ago

With the following gulp-hb configuration:

gulp.task('templates', function() {
    return gulp.src(paths.src.templates + '/**/*.html')
        .pipe(hb({
            partials: [
                paths.src.templates + '/**/*.hbs'
            ]
        }))
        .pipe(gulp.dest(paths.dest.root));
});

And the following watch task:

gulp.task('watch',  function() {
    gulp.watch(paths.src.templates + '/**/*', ['templates', function() {
        return browserSync.reload();
    }]);
});

Although this watch task triggers the 'templates' task to rerun on all template file changes, only changes to Handlebars Templates (.html) update and never Handlebars Partials. Handlebars Partials appear to become cached by gulp-hb. Is it possible to force the partials to update or could this be a bug?

shannonmoeller commented 9 years ago

Oh, good call. gulp-hb uses require-glob and handlebars-registrar behind the scenes. Fortunately I also own those modules. I'll need to add an option to require-glob to allow forcing a reload, then pass the option through from here.

I'll add a reload boolean option to this plugin.

backflip commented 9 years ago

I have been successfully using https://www.npmjs.com/package/require-new in similar situations, might be an option.

shannonmoeller commented 9 years ago

I've added bustCache and debug options and released them as v2.4.0. See README.md for details.

admbtlr commented 9 years ago

Thanks! Was just trying to work around this yesterday...

elisechant commented 9 years ago

@shannonmoeller awesome stuff, confirming bustCache works as expected. And liking the debug flag.

shannonmoeller commented 9 years ago

@elisechant Thanks for confirming!

jensbambauer commented 5 years ago

Interesting, I just came across a similiar issue:

function compileHandlebars() {
    return gulp
        .src('./*.html')
        .pipe(
            hb({ debug: true, bustCache: true })
                .partials('./src/components/threesixty/threesixty.hbs')
                .helpers({
                    JSONString: object => JSON.stringify(object),
                })
                .data({ assetPath: `/${paths.assets}` })
                .data(handlebarData),
        )
        .pipe(gulp.dest(path.resolve(__dirname, paths.tmp)));
}
gulp.watch(
        [`./${paths.src}/**/*.hbs`, './*.html', `./${paths.src}/**/*.json`],
        gulp.series(compileHandlebars, js, reload),
    );

Changing something in my html file works fine. But when changing the threesixty.hbs partial the changes are not visible until I edit the html file or restart gulp.

I'm using gulp 4 and gulp-hb 8 Any ideas?

shannonmoeller commented 5 years ago

@jensbambauer That’s odd. I’d expect that to work fine based on your setup. Mind opening a new issue for this?

jensbambauer commented 5 years ago

Sure, I will open a new issue. My workaround now is to have a watcher for the hbs files which just update the html file date :)

jensbambauer commented 5 years ago

https://github.com/shannonmoeller/gulp-hb/issues/67