Reputation: 24562
Here's what I am doing now. It works but if I want to rename more flies then I am going to end up with a lot of tasks:
gulp.task('rename_bundle_css', ['make_css_bundle'], function () {
return gulp.src('content/bundles/css.min.css')
.pipe(rename('css-' + md5File('content/bundles/css.min.css') + '.min.css'))
.pipe(gulp.dest('content/bundles/'));
});
gulp.task('rename_bundle_css_zip', ['rename_bundle_css'], function () {
return gulp.src('content/bundles/css.min.css.gz')
.pipe(rename('css-' + md5File('content/bundles/css.min.css') + '.min.css.gz'))
.pipe(gulp.dest('content/bundles/'));
});
Is there a way I can combine these two into one or some way I an rename (or copy) more than one file in one task?
Upvotes: 0
Views: 89
Reputation: 30564
You can pass a function to gulp-rename
which receives an object with the following properties for each file in the stream:
dirname
: path to the directory that the file is inbasename
: name of file without file extensionextname
: file extensionChanging any of these renames the file.
Your example rewritten in this fashion could look like this:
gulp.task('rename_bundle_css', ['make_css_bundle'], function () {
return gulp.src(['content/bundles/css.min.css',
'content/bundles/css.min.css.gz'])
.pipe(rename(function(file) {
var original = file.basename + file.extname.replace(/\.gz$/, '');
var hash = md5File('content/bundles/' + original);
file.basename = file.basename.replace(/^css/, 'css-' + hash);
}))
.pipe(gulp.dest('content/bundles/'));
});
Upvotes: 1