Search code examples
javascriptgulp

Base path for src files in Gulp


How can I set the default path and don't write every time src/js/vendor/? Is it possible?

Note: I can't take all the files like src/js/vendor/**.js

gulp.task('js-vendor', function() {
    return gulp.src([
      'src/js/vendor/some_one.js',
      'src/js/vendor/some_two.js',
      'src/js/vendor/some_three.js'
    ])
      .pipe(concat('vendor.js'))
      .pipe(gulp.dest('public/js'));
});

Solution

  • If you are unable to make a suitable matching pattern then the paths are just an array of strings so you can easily build them. You could even use something like:

      gulp.task('js-vendor', function() {
         return gulp.src([
           'some_one.js',
           'some_two.js',
           'some_three.js'
          ].map( file => 'src/js/vendor/' + file ))
      .pipe(concat('vendor.js'))
      .pipe(gulp.dest('public/js'));
     })