mariocasciaro / gulp-concat-css

Concatenates css files, bubbling up import statements (as per the standard), and optionally rebasing urls and inlining local import statements.
MIT License
78 stars 19 forks source link

Add support for dynamic targetFiles #34

Closed kingkool68 closed 8 years ago

kingkool68 commented 8 years ago

I have a pretty simple Gulp task to concat CSS files in a directory. The problem is I'm not combining them all in to one file but instead processing each CSS file in a directory and saving a new minified version of that file.

I want to be able to reference the current file being processed via gulp.src('css/*.css') Here is my gulpfile.js. How can I define the currentFileName variable instead of hardcoding a string?

var gulp = require('gulp');
var del = require('del');
var concatCSS = require('gulp-concat-css');
var cssnano = require('gulp-cssnano');

gulp.task('clean:min-css', function () {
    // Delete all *.min.css files in the CSS directory so we don't get duplicates
    return del([
        'css/*.min.css'
    ]);
});

gulp.task('default', ['clean:min-css'], function() {
    gulp.src('css/*.css')
        // Munge contents of @import statements into one file
        .pipe( concatCSS( currentFileName + '.min.css' ) )

        // minify CSS
        .pipe( cssnano() )

        // Save out the new file
        .pipe( gulp.dest('css/') );
});
mariocasciaro commented 8 years ago

Hi, please take a look a this https://github.com/gulpjs/gulp/blob/master/docs/recipes/running-task-steps-per-folder.md

kingkool68 commented 8 years ago

Ah thanks for that. I managed to figure it out using the gul-foreach plugin

My gulpfile looks like this now. https://gist.github.com/kingkool68/db0b153bddb08e2c1107