pugjs / pug

Pug – robust, elegant, feature rich template engine for Node.js
https://pugjs.org
21.66k stars 1.95k forks source link

pug under gulp #2591

Open Scorpovi4 opened 7 years ago

Scorpovi4 commented 7 years ago

How could I modify configuration of pug under gulp to exclude closing watch mode after every compile error?

gulp.task('pug', function(){
    return gulp.src('app/pug/**/*.pug')
    .pipe(pug({pretty: true}))
    .pipe(gulp.dest('app'))
});
PascaleBeier commented 7 years ago

Do you make use of the gulp.watch API?

gulp.watch('app/pug/**/*.pug', ['pug']);

Edit: Just tried it, see my example below:

import gulp from 'gulp';
import pug from 'gulp-pug';
import stylus from 'gulp-stylus';

gulp.task('build:html', () => {
    return gulp
        .src('./src/html/*.pug')
        .pipe(pug({
            pretty: true
        }))
        .pipe(gulp.dest('./public'));
});

gulp.task('build:css', () => {
    return gulp
        .src('./src/css/*.styl')
        .pipe(stylus({
            compress: true
        }))
        .pipe(gulp.dest('./public'));
});

gulp.task('watch:html', () => {
    return gulp
        .watch('./src/html/*.pug', ['build:html']);
});

gulp.task('watch:css', () => {
    return gulp
        .watch('../src/css/*.styl', ['build:css']);
});

gulp.task('default', ['build:html', 'build:css']);
gulp.task('build', ['build:html', 'build:css']);
gulp.task('watch', ['watch:html', 'watch:css']);
Scorpovi4 commented 7 years ago

Yes, I use gulp.watch API and it stop during compilation if I did mistake into *.pug file. Your config as mine: watch section

gulp.watch('app/pug/**/*.pug', ['pug']);

pug section

gulp.task('pug', function(){
    return gulp.src('app/pug/**/*.pug')
    .pipe(pug({pretty: true}))
    .pipe(gulp.dest('app'))
});

Tried to add render by .on method to main gulp method, but this give me nothing (:

.on('change', function(event) {
  console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
});

Why I upped this question? because SASS could decide this by .on('error', sass.logError))

strugee commented 7 years ago

@Scorpovi4 this is a Gulp problem, not a Pug problem. The fact that Pug throws upon encountering invalid syntax is a perfectly reasonable thing for a JS library to do. You should use gulp-plumber to fix this; Gulp 4 will also include much better error-handling out of the box, so this won't be a huge problem at that time.

I'll also note that while I think this issue should be closed as a WONTFIX in any case, it's filed under the wrong repository, anyway. See pugjs/gulp-pug