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

前端 未结 9 1281
遇见更好的自我
遇见更好的自我 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条回答
  • 2020-12-02 15:15

    Using gulp-if helps me a lot.

    The gulp-if first argument. is the gulp-match second argument condition

    gulp-if can be found in gulp-if

    import {task, src, dest} from 'gulp';
    import VinylFile = require("vinyl");
    const gulpif = require('gulp-if');
    
    src(['foo/*/**/*.md', 'bar/*.md'])
        .pipe(gulpif((file: VinylFile) => /foo\/$/.test(file.base), dest('dist/docs/overview')))
        .pipe(gulpif((file: VinylFile) => /bar\/$/.test(file.base), dest('dist/docs/guides')))
    });
    
    0 讨论(0)
  • 2020-12-02 15:16

    I guess that the running tasks per folder recipe may help.

    Update

    Following the ideas in the recipe, and oversimplifying your sample just to give the idea, this can be a solution:

    var gulp = require('gulp'),
        path = require('path'),
        merge = require('merge-stream');
    
    var folders = ['httpdocs-site1', 'httpdocs-site2', 'httpdocs-site3'];
    
    gulp.task('default', function(){
    
        var tasks = folders.map(function(element){
            return gulp.src(element + '/media/sass/**/*.scss', {base: element + '/media/sass'})
                // ... other steps ...
                .pipe(gulp.dest(element + '/media/css'));
        });
    
        return merge(tasks);
    });
    
    0 讨论(0)
  • 2020-12-02 15:17

    The destination will have the same directory structure as the source.

    0 讨论(0)
提交回复
热议问题