Gulp - 根据数组制作文件的多个副本

时间:2018-01-11 15:18:10

标签: javascript node.js gulp

我有一个字符串数组(["red", "green", "blue"]),我希望我的Gulp流可以根据字符串单独处理和将文件克隆到文件夹中。

./src/stylus/中的源文件树如下所示:

style.styl
util.styl
themes/basic.styl
themes/advanced.styl

在Gulp完成其魔法之后,我希望我的构建目标(./build/css/)看起来像这样:

style.css
util.css
themes/basic.css
themes/advanced.css
themes/red/basic.css
themes/red/advanced.css
themes/green/basic.css
themes/green/advanced.css
themes/blue/basic.css
themes/blue/advanced.css

我的Gulpfile目前看起来像这样;

import gulp from 'gulp';
import stylus from 'gulp-stylus';
import flatmap from 'gulp-flatmap';
import postcss from 'gulp-postcss';

var filters = ["red", "green", "blue"];

// ...

gulp.src([
    './src/stylus/**/*.styl',
    '!./src/stylus/**/_*.styl'
])
    .pipe(stylus())
    .pipe(flatmap(function(stream, file) {
        if(file.relative.split("/")[0] == "themes") {
            for(var i = 0; i < filters.length; i++) {
                gulp.src(['./src/stylus/' + file.relative])
                    .pipe(postcss()) /* Some filters[i] specific processing here */
                    .pipe(gulp.dest('./build/css/themes/' + filters[i] + "/"));
            }
        }

        return stream;
    }))
    .pipe(gulp.dest('./build/css'))
    .on("end", cb);

上述内容似乎没有任何错误,但它也没有在构建目标中创建/themes文件夹。

我怎样才能做到这一点?

0 个答案:

没有答案
相关问题