Search code examples
gulpgulp-watch

gulp.watch does not pick up new files


I have an gulp client side build set up. Some steps are css/js/html minification/concatenation and etc. Standard stuff. I'm using gulp 3.9.0. The issue I'm struggling with is that gulp.watch does not pick up new files (changed/deleted events are triggering my callback, but added is not raised):

watchThis(
            "./src/main/client/app/agent/accounts/**/*.html",
            "app",
            "-markup");

        function watchThis(paths, key, suffix) {
            gulpUtil.log('Watching ' + gulpUtil.colors.cyan(paths + " as " + key + suffix));

            gulp.watch(paths, function(event) {
                gulpUtil.log("File event: " + gulpUtil.colors.cyan(path.basename(event.path) + ' ' + event.type));
                gulp.start(key + suffix);
            }).on('error', function(error) {
                gulpUtil.log(error);
            });
        }

I don't want to use gulp-watch plugin as I just dropped it - I had some other issues with it including it was too slow on large projects + it sometimes was hunging. gulp.watch it lightning fast and robust so far, but the only issue is that it does not detect when files are added.

How can I fix it?


Solution

  • Per this answer, there is a weird case with the path value.

    Removing ./ from glob fixes it.