I've used Gulp a number of times but this problem has me totally stumped. I have a render
task to save an HTML template piped through gulp-swig
. It works perfectly fine when invoked manually via gulp render
but will not save when the task is triggered by gulp.watch
. So, to clarify, the watcher does trigger the task but the rendered file doesn't actually get saved to its destination.
I've boiled the problem down to the following, removing all other tasks from my gulpfile, axed plumber, context data, etc. Any help appreciated!
var gulp = require( 'gulp' ),
browserSync = require( 'browser-sync' ).create(),
rename = require( 'gulp-rename' ),
swig = require( 'gulp-swig' ),
reload = browserSync.reload;
gulp.task( 'render', function() {
return gulp.src( './dev/template.html' )
.pipe( swig() )
.pipe( rename( 'index.html' ) )
.pipe( gulp.dest( './preview' ) )
.on( 'end', reload );
});
gulp.task( 'serve', function() {
browserSync.init( { server: './preview' } );
gulp.watch( './dev/*.html', [ 'render' ] );
});
gulp.task( 'default', [ 'serve' ] );