Can I use a Gulp task with multiple sources and multiple destinations?

前端 未结 9 1337
遇见更好的自我
遇见更好的自我 2020-12-02 14:19

I have the following in my gulpfile.js:

   var sass_paths = [
        \'./httpdocs-site1/media/sass/**/*.scss\',
        \'./httpdocs-site2/media/sass/**/*         


        
9条回答
  •  -上瘾入骨i
    2020-12-02 15:03

    you are going to want to use merge streams if you would like to use multiple srcs but you can have multiple destinations inside of the same one. Here is an example.

    var merge = require('merge-stream');
    
    
    gulp.task('sass', function() {
       var firstPath = gulp.src(sass_paths[0])
                   .pipe(sass({errLogToConsole: true}))
                   .pipe(autoprefixer('last 4 version'))
                   .pipe(minifyCSS({keepBreaks:true}))
                   .pipe(rename({ suffix: '.min'}))
                   .pipe(gulp.dest('./httpdocs-site1/media/css'))
                   .pipe(gulp.dest('./httpdocs-site2/media/css'));
       var secondPath = gulp.src(sass_paths[1])
                   .pipe(sass({errLogToConsole: true}))
                   .pipe(autoprefixer('last 4 version'))
                   .pipe(minifyCSS({keepBreaks:true}))
                   .pipe(rename({ suffix: '.min'}))
                   .pipe(gulp.dest('./httpdocs-site1/media/css'))
                   .pipe(gulp.dest('./httpdocs-site2/media/css'));
       return merge(firstPath, secondPath);
    });
    

    I assumed you wanted different paths piped here so there is site1 and site2, but you can do this to as many places as needed. Also you can specify a dest prior to any of the steps if, for example, you wanted to have one dest that had the .min file and one that didn't.

提交回复
热议问题