Search code examples
javascriptgulpgulp-concat

gulp-concat: how to ensure a file is concatenated last?


gulp.task('scripts', function() {
  return gulp.src(['!dev/js/vendor-list.js', 'dev/js/**/*.js'])
    .pipe(concat('all.min.js'))
    .pipe(gulp.dest('public'));
});

The above code is a sample of my gulp task using gulp-concat. Somewhere in the pile is my app.js file which I would like concatenated last. Is there a way to do it without having to list all the sub-folders in order? All other files are order agnostic. My app.js is the only one order sensitive that I need concatenated last. I thought about doing two streams in a single task and then merging the output, but I was hoping for a simpler solution. Any thoughts?


Solution

  • Try this (from this question):

    [
      '!dev/js/vendor-list.js', // can probably be included in the statement below.
      '/dev/js/!(app)*.js', // all files that end in .js EXCEPT app*.js
      '/dev/js/app.js', // this should be concatenated last
    ]