Good day, StackOverflow community. Most recently, I started to deal with gulp and ran into a problem: when adding the same file to src, it starts to be ignored after the first processing.

For example,

gulp.src(['file1.html', 'file2.html', 'file1.html']) .pipe(concat('all.html')) .pipe(gulp.dest('/dir')); 

Unfortunately, after running the script in all.html, only the following structure is obtained:

  • file1.html
  • file2.html

And that is all. Has anyone encountered a similar problem? Do not tell me how to solve it?

    2 answers 2

    This is the expected behavior. You probably want to use one html file as a template and paste it several times into your layout? If so, use gulp-rigger

    Installation:

     npm install gulp-rigger --save-dev 

    in gulpfile.js

     rigger = require('gulp-rigger'), //использование шаблонов gulp.task('html', function() { gulp.src(path.watch.html) .pipe(rigger()) .pipe(gulp.dest(path.build.html)); }); 

    And now you can combine html like this. For example in all.html:

     <div class="content"> //= templates/file1.html //= templates/file2.html //= templates/file1.html </div> 

      Also, if for some reason, gulp-rigger does not suit you, you can use gulp-add-src .

      In your cases, something like this:

       gulp.task('html', function() { return gulp.src([ 'file1.html', 'file2.html', ]) .pipe(addsrc.append('file1.html')) .pipe(concat('all.html')) .pipe(gulp.dest('/dir')); });