copying files with gulp

后端 未结 2 1981
清歌不尽
清歌不尽 2021-01-17 18:11

I have an app. My app source code is structured like this:

./
  gulpfile.js
  src
    img
      bg.png
      logo.png
    data
      list.json
    favicon.ic         


        
相关标签:
2条回答
  • 2021-01-17 18:52

    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']);
    
    0 讨论(0)
  • 2021-01-17 19:06

    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'))
      ]);
    });
    
    0 讨论(0)
提交回复
热议问题