Last active
March 7, 2016 19:06
-
-
Save kingkool68/db0b153bddb08e2c1107 to your computer and use it in GitHub Desktop.
Using filenames as variables in gulp.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var gulp = require('gulp'); | |
var del = require('del'); | |
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' | |
]); | |
}); | |
var foreach = require('gulp-foreach'); | |
var path = require('path'); | |
var concatCSS = require('gulp-concat-css'); | |
var autoprefixer = require('gulp-autoprefixer'); | |
var cssnano = require('gulp-cssnano'); | |
gulp.task('default', ['clean:min-css'], function() { | |
gulp.src('css/*.css') | |
.pipe( | |
// Loop over each stream, figure out the filename, and run the stream through concatCSS() passing along the dynamic filename | |
foreach(function(stream, file) { | |
// Get the filename without the extension... | |
var filename = path.basename(file.path, '.css'); | |
return stream.pipe( concatCSS(filename + '.min.css') ) | |
}) | |
) | |
// Autoprefix | |
.pipe( autoprefixer() ) | |
// minify CSS | |
.pipe( cssnano() ) | |
// Save out the new file | |
.pipe( gulp.dest('css/') ); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See http://stackoverflow.com/questions/35847023/gulp-js-and-variable-file-names or https://www.facebook.com/groups/advancedwp/permalink/1106251519437061/