gulp-html icon indicating copy to clipboard operation
gulp-html copied to clipboard

False errors in files, compiled with partials

Open kpobococ opened this issue 8 years ago • 4 comments

I'm using gulp-file-include to move repetitive parts of my html pages (like page header and footer) to outside files. However, gulp-html does not seem to use the compiled version for its validation, because it gives me errors about missing title element within head (which is inside one of the partials).

Here's a shortened version of my gulpfile.js:

var gulp            = require('gulp');
var gulpFileInclude = require('gulp-file-include');
var gulpHtml        = require('gulp-html');

gulp.task('html', function () {
    return gulp.src('src/*.html')

        // Include partials
        .pipe(gulpFileInclude({
            prefix:   '<!-- partial:',
            suffix:   ' -->',
            basepath: 'src/partials/',
            context:  {
                'compileJs': false
            }
        }))

        // Validate
        .pipe(gulpHtml())
        .pipe(gulp.dest('dist/'));
});

Am I missing something or is it a bug?

kpobococ avatar Jul 07 '16 12:07 kpobococ

It's not supported. PRs welcome.

XhmikosR avatar Jan 18 '19 13:01 XhmikosR

However, gulp-html does not seem to use the compiled version for its validation, because it gives me errors about missing title element within head (which is inside one of the partials).

@kpobococ I know this is an old issue, but I ran into it today while using gulp-html for the first time. I solved it by moving validation to a separate task.

gulp.task('html', function () {
    return gulp.src('src/*.html')
        // Build HTML here using something like a static site generator
        .pipe(gulp.dest('dist/'));
});

gulp.task('validate', function () {
    return gulp.src('dist/*.html')
        .pipe(validator())
        .pipe(gulp.dest('dist/'));
});

To me it seems like this defeats the purpose of Gulp streams... you should just be able to .pipe the compiled HTML into the validator(). For whatever reason, it seems to only work in a separate task.

paulshryock avatar Apr 30 '20 20:04 paulshryock

For whatever reason, it seems to only work in a separate task.

I think he doesn't have a job, nor does he have a job in a separate task, sometimes it only reports running errors. I tried to change the checked html code to a mess, and he didn't give any hints. @XhmikosR

ZhangChengLin avatar Jun 17 '21 01:06 ZhangChengLin

True. Most projects I've used this on, I ended up turning it off later when it threw random errors and blocked deployments. Hasn't been super useful.

paulshryock avatar Jun 17 '21 20:06 paulshryock