jonschlinkert / gulp-htmlmin

Minify HTML
https://github.com/jonschlinkert
MIT License
727 stars 57 forks source link

gulp watch loop #81

Closed rzb closed 7 years ago

rzb commented 7 years ago

After implementing gulp-htmlmin, gulp watch goes into an endless loop for me.

I'm on Laravel (elixir sits on top of gulp).

elixir.extend('compress', function() {
    new elixir.Task('compress', function() {
        return gulp.src('./storage/framework/views/*')
            .pipe(htmlmin({
                collapseWhitespace          : true,
                collapseInlineTagWhitespace : true,
                removeAttributeQuotes       : true,
                removeComments              : true,
                minifyJS                    : true,
                minifyCSS                   : true,
            }))
            .pipe(gulp.dest('./storage/framework/views/'));
    })
    .watch('./storage/framework/views/*');
});
shinnn commented 7 years ago
  1. Try some other HTML processor plugins inside watch task. If you can reproduce infinite loop even when you don't use gulp-htmlmin, this is an issue with elixir.Task#watch.
  2. If you cannot reproduce infinite loop with other plugins, pinpoint the HTML file that causes neverending process and open a new issue on https://github.com/kangax/html-minifier/issues with full content of the HTML file.
doowb commented 7 years ago

@rzb also it looks like your src and dest paths are the same. Since gulp-htmlmin changes the files, watch will trigger.

rzb commented 7 years ago

@doowb Yeah, I noticed that in the following morning with some coffee and have procrastinated since then.

I had copied that snippet directly from this laravel package repo, which is a server side solution to the same problem. So for those who end up here for the same reason:

Replace

.watch('./storage/framework/views/*');

With

.watch('./resources/views/**/*.blade.php');