我可以使用具有多个源和多个目标的 Gulp 任务吗?

Can I use a Gulp task with multiple sources and multiple destinations?(我可以使用具有多个源和多个目标的 Gulp 任务吗?)
本文介绍了我可以使用具有多个源和多个目标的 Gulp 任务吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我的 gulpfile.js 中有以下内容:

I have the following in my gulpfile.js:

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

gulp.task('sass', function() {
    return gulp.src(sass_paths)
        .pipe(sass({errLogToConsole: true}))
        .pipe(autoprefixer('last 4 version'))
        .pipe(minifyCSS({keepBreaks:true}))
        .pipe(rename({ suffix: '.min'}))
        .pipe(gulp.dest(???));
});

我想将缩小的 css 文件输出到以下路径:

I'm wanting to output my minified css files to the following paths:

./httpdocs-site1/media/css
./httpdocs-site2/media/css
./httpdocs-site3/media/css

我是否误解了如何使用来源/目的地?还是我试图在一项任务中完成太多?

Am I misunderstanding how to use sources/destinations? Or am I trying to accomplish too much in a single task?

更新了对应站点目录的输出路径.

Updated output paths to corresponding site directories.

推荐答案

我猜 为每个文件夹运行任务 配方可能会有所帮助.

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

更新

遵循配方中的想法,并为了给出想法而过度简化您的示例,这可能是一个解决方案:

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);
});

这篇关于我可以使用具有多个源和多个目标的 Gulp 任务吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

How do I can get a text of all the cells of the table using testcafe(如何使用 testcafe 获取表格中所有单元格的文本)
node_modules is not recognized as an internal or external command(node_modules 未被识别为内部或外部命令)
How can I create conditional test cases using Protractor?(如何使用 Protractor 创建条件测试用例?)
PhantomJS and clicking a form button(PhantomJS 并单击表单按钮)
Clicking #39;OK#39; on alert or confirm dialog through jquery/javascript?(在警报上单击“确定或通过 jquery/javascript 确认对话框?)
QunitJS-Tests don#39;t start: PhantomJS timed out, possibly due to a missing QUnit start() call(QunitJS-Tests 不启动:PhantomJS 超时,可能是由于缺少 QUnit start() 调用)