Renaming files with Gulp w / Specific template
I have a Gulp task that is supposed to copy content from one directory to another and rename each file with a specific template. Basically, if I have main.css, I need to create a copy of main.css and name it main_main_bk.css (don't ask - this is a convention I need to follow). To be clear, I need to add _, followed by the name of the file currently being processed, and then _bk. How can I find out what the name of the current file is in Gulp?
var gulp = require('gulp');
var rename = require('gulp-rename');
gulp.task('copit', function() {
gulp.src('asset/css/*.css')
.pipe(rename({suffix: '_' + ??? + '_bk'}))
.pipe(gulp.dest('asset/test'));
});
So,
asset / css / main.css -> asset / test / main_main_bk.css
asset / css / style.css -> asset / test / style_style_bk.css
Etc.
+3
source to share
1 answer
You can use the base name and rename it using the function
var gulp = require('gulp');
var rename = require('gulp-rename');
gulp.task('copit', function() {
gulp.src('asset/css/*.css')
.pipe(rename(function (path) {
path.basename += "_" + path.basename + "_bk";
}))
.pipe(gulp.dest('asset/test'));
});
+4
source to share