Answer the question
In order to leave comments, you need to log in
Gulp.lastRun and gulp-nunjucks, options?
Good evening. There is an index.njk page and it includes footer.njk. Changing footer.njk doesn't update index.njk.
I realized that the problem is in gulp.lastRun, but without it, working with large projects is not very comfortable. The duration of the task can reach several seconds.
I found a similar problem with imports in SASS, but they already wrote a special gulp-dependents package for this. I'm wondering if someone uses a similar package, mb, or it would be even better if someone knows how to solve the issue without additional packages.
TASK
function html() {
return src('src/*.{html,njk}', { base: 'src', since: lastRun('html') })
.pipe(nunjucks({
path: 'src',
}))
// HTML-валидатор.
.pipe(htmlhint('.htmlhintrc'))
.pipe(htmlhint.reporter())
// Манифест.
// Если флаг --dist без --norev.
.pipe(gulpif(dist, gulpif(!norev, revReplace({
manifest: src('manifest/manifest.json', { allowEmpty: true }),
}))))
// Добавляет индентацию для заинклюженных блоков.
.pipe(gulpif(dist, prettyHtml({
indent_size: 2,
})))
// Выгрузка.
.pipe(dest(buildHtml))
// browserSync.
.pipe(gulpif(!dist, browserSync.stream())); // Если нет флага --dist.
}
Answer the question
In order to leave comments, you need to log in
Found package gulp-nunjucks-inheritance
Task now looks like this
function html() {
return src('src/**/*.{html,njk}', { base: 'src', since: lastRun('html') })
// Nunjucks
.pipe(nunjucksInheritance({ base: 'src' })) // Ищем изменения в зависимостях
.pipe(nunjucks({ path: 'src' })) // Компилируем в HTML
// Добавляет индентацию для заинклюженных блоков.
.pipe(prettyHtml({ indent_size: 2 }))
// HTML-валидатор.
.pipe(htmlhint('.htmlhintrc'))
.pipe(htmlhint.reporter())
// Манифест.
// Если флаг --dist без --norev.
.pipe(gulpif(dist, gulpif(!norev, revReplace({
manifest: src('manifest/manifest.json', { allowEmpty: true }),
}))))
// Выгрузка.
.pipe(dest(buildHtml))
// browserSync.
.pipe(gulpif(!dist, browserSync.stream())); // Если нет флага --dist.
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question