javascript - Slow pug compiling to HTML -
i'm using gulp compile pug file html. takes average of 30 seconds each time make kind of change! maybe due in gulp config (listed below)?
var gulp = require('gulp') var pug = require('gulp-pug') gulp.task('pug', function () { return gulp.src('pug/**/*.pug') .pipe(pug({pretty:true, doctype:'html'})) .pipe(gulp.dest('views')) }) gulp.task('watch:pug', ['pug'], function () { gulp.watch('pug/**/*.pug', ['pug']) })
if pug compilation slows down, add caching.
var gulp = require('gulp'); var pug = require('gulp-pug'); var cached = require('gulp-cached'); var remember = require('gulp-remember'); gulp.task('pug', function () { return gulp.src('pug/**/*.pug', { since: gulp.lastrun('pug') })) .pipe(cached('pug')) .pipe(pug({pretty:true, doctype:'html'})) .pipe(remember('pug')) .pipe(gulp.dest('views')) }) gulp.task('watch', function(done) { gulp.watch('pug/**/*.pug', gulp.parallel('pug')); return done(); }); gulp.task('default', gulp.series('pug', 'watch')); the option gulp.lastrun return files changed since last run of given task. if use default task build files, pug need process files changed. because gulp process kept alive watch function, able cache previous unchanged files.
remark: work if use gulp v4, if not, should upgrade ;)
solution gulp < 4.0
there package called gulp-cache, { since: gulp.lastrun('pug') }. should able adjust snippet:
var gulp = require('gulp'); var pug = require('gulp-pug'); var cache = require('gulp-cache'); var cached = require('gulp-cached'); var remember = require('gulp-remember'); gulp.task('pug', function () { return gulp.src('pug/**/*.pug')) .pipe(cache('pug')) .pipe(cached('pug')) .pipe(pug({pretty:true, doctype:'html'})) .pipe(remember('pug')) .pipe(gulp.dest('views')) }) gulp.task('watch', function(done) { gulp.watch('pug/**/*.pug', ['pug']); return done(); }); gulp.task('default', ['pug', 'watch']); i not sure if need gulp-cached , gulp-remember. packages link input files converted output files. means gulp-remember output files processed. if file not updated, output cached version. if don't need files (e.g. because not concatenating them), remove lines.
even if package names similar, different:
the package gulp-cache forward files have changed since last build. same, option { sine: gulp.lastrun('pug') }.
so if need process files further down in pipe, need 3 packages, otherwise, package gulp-cache (without d) should sufficient.
Comments
Post a Comment