Skip to content Skip to sidebar Skip to footer

Copying Files With Gulp

I have an app. My app source code is structured like this: ./ gulpfile.js src img bg.png logo.png data list.json favicon.ico web.config in

Solution 1:

You can create separate tasks for each target directory, and then combine them using a general "copy-resources" task.

gulp.task('copy-img', function() {
  return gulp.src('./src/img/*.png')
    .pipe(gulp.dest('./deploy/imgs'));
});

gulp.task('copy-data', function() {
  return gulp.src('./src/data/*.json')
    .pipe(gulp.dest('./deploy/data'));
});

gulp.task('copy-resources', ['copy-img', 'copy-data']);

Solution 2:

You could also use merge-stream

Install dependency:

npm i -D merge-stream

Load the depedency in your gulp file and use it:

const merge = require("merge-stream");

gulp.task('copy-resources', function() {
  return merge([
      gulp.src('./src/img/*.png').pipe(gulp.dest('./deploy/imgs')),
      gulp.src('./src/data/*.json').pipe(gulp.dest('./deploy/data'))
  ]);
});

Post a Comment for "Copying Files With Gulp"