How to exclude files from the stream depending on the path?

  • 0
    Good day. I ran into a problem related to the ice in nunjucks.

    There is such a project structure:
    - 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.
    Help exclude files with the path blocks / ** / *. Njk from the stream so that they are not uploaded to 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.
    }
    JavaScript Everly Russell, Nov 29, 2020

  • 0 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!