1

I'm trying to create a gulp task that creates (in this case minifies) a css file for every project css there is. So for Project A it should combine and minify the following files:

global.projecta.css tool1.projecta.css tool2.projecta.css 

It needs a kind of loop or something...? If there is a new Project D, it should build it too. If i need to add something like "projectd" to an array, that would be ok too.

This is the directory structure for the css

./global.projecta.css ./global.projectb.css ./global.projectc.css ./addons/tool1.projecta.css ./addons/tool2.projecta.css ./addons/tool1.projectb.css ./addons/tool2.projectb.css ./addons/tool1.projectc.css ./addons/tool2.projectc.css 

This is the not working task

// not working.... gulp.task('css', function() { return gulp.src(['global.*.css', 'addons/tool*.css', '!*.min.css']) .pipe(concat('build.css')) .pipe(rename({suffix: '.min'})) .pipe(minifycss()) .pipe(gulp.dest('build/css')); }); 

2 Answers 2

1

You could try something like this, although it requires manually entering an array of your projects.

gulp.task('css', function() { var projects = ['a','b','c']; projects.forEach( function(proj) { gulp.src(['global.' + proj + '.css', 'addons/tool*.' + proj + '.css', '!*.min.css']) ... }); }); 
Sign up to request clarification or add additional context in comments.

1 Comment

had to write forEach but thanks for the simple and working tip
0

This outputs different files for each global project. For each global.project*.css will output global.project*.min.css:

var gulp = require('gulp'); var css = require('gulp-minify-css'); var concat = require('gulp-concat'); var rename = require('gulp-rename'); var glob = require('glob'); gulp.task('css', function() { glob('global.\*.css', {}, function (er, files) { for(var i = 0, cnt = files.length; i < cnt; i++){ var fileName = files[i].replace('.css', ''); gulp.src(['global.\*.css', 'addons/tool\*.css', '!*.min.css']) .pipe(concat('build.css')) .pipe(rename({basename: fileName, suffix: '.min'})) .pipe(css()) .pipe(gulp.dest('build/css')); } }); }); gulp.task('default', ['css']); 

1 Comment

but that will build only one file build.css containing all css. my question was about one build file per project.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.