是否可以将父目录的名称传递给gulp-rename或任何其他重命名插件?我正在尝试以编程方式连接'src'文件夹中的所有文件,并使用其父目录的名称重命名它们。以下代码是我目前所拥有的。
gulp.task('js-test', function() {
return gulp.src('dev/scripts/**/src/*.min.js')
.pipe(concat('interim-name.js'))
.pipe(rename('How do I give it the name of the parent directory of src'))
.pipe(gulp.dest('dev/scripts'))
});
最终结果如下:
答案 0 :(得分:0)
gulp-rename可以选择使用函数,例如来自文档:
// rename via function
gulp.src("./src/**/hello.txt")
.pipe(rename(function (path) {
path.dirname += "/ciao";
path.basename += "-goodbye";
path.extname = ".md"
}))
.pipe(gulp.dest("./dist")); // ./dist/main/text/ciao/hello-goodbye.md
所以我会注销path.dirname然后处理字符串操作:
.pipe(rename(function (path) {
// I use nodePath.sep here but you may have to require path for it to work
// var nodePath = require('path');
// but maybe just path.sep without the require will work just fine
var temp = path.dirname.split(nodePath.sep);
path.basename = temp[some index here];
}))