本文介绍了我可以使用具有多个源和多个目标的 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 任务吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!