I
I
IIIu6ko2020-10-13 10:19:16
JavaScript
IIIu6ko, 2020-10-13 10:19:16

How to exclude files from stream depending on path?

Good afternoon. I ran into a problem with ikludes in nunjucks.

There is a project structure like this:

- build
  - index.html
- src
  - blocks
    - block1
      - block1.njk
    - block2
      - block2.njk
  - index.njk

If you include block1.njk or block2.njk in index.njk, then everything is fine, but if block2.njk is in block1.njk and then block1.njk in index.njk, then the blocks/block2/block2.html folder appears in build.
Please help exclude files with path blocks/**/*.njk from the stream so that they are not unloaded in build.

task:
// html.
const htmlhint = require('gulp-htmlhint');
const prettyHtml = require('gulp-pretty-html'); // Добавляет индентацию.
const nunjucks = require('gulp-nunjucks-render');
const nunjucksInheritance = require('gulp-nunjucks-inheritance');


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(distRev, revReplace({
      manifest: src('manifest/manifest.json', { allowEmpty: true }),
    }))))

    // Выгрузка.
    .pipe(dest(buildHtml))

    // browserSync.
    .pipe(gulpif(!dist, browserSync.stream())); // Если нет флага --dist.
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question