Gulp 获得;“文件基本名称”;吞咽替换任务

Gulp 获得;“文件基本名称”;吞咽替换任务,gulp,Gulp,我正在处理一组文件,并使用gulp replacer任务根据管道中当前文件的基本名称或路径,将已处理文件的内容替换为“字符串” 如何获取管线中当前文件的属性 gulp.task('svgbuild', function() { return gulp.src('./src/*.svg') .pipe(replace({ patterns: [ { match: /STRING_TO_M

我正在处理一组文件,并使用gulp replacer任务根据管道中当前文件的基本名称或路径,将已处理文件的内容替换为“字符串”

如何获取管线中当前文件的属性

gulp.task('svgbuild', function() {
    return gulp.src('./src/*.svg')
        .pipe(replace({
          patterns: [
            {
                match:       /STRING_TO_MATCH/g,
                replacement: function() {
                    // how to get the basename of the "file" in the stream;
                    var str = 'file.basename'              
                    // manipulate to get replacement string based on basename
                    var repl = str.toUpperCase()+'-inc'    
                    return repl;
                }
            }
            ]
        }))
});

我认为您必须在Node.js中寻找解决方案。也许这会有所帮助:?

比我希望的要晚一些,但似乎我找到了一个解决问题的方法。这就是我的gulpfile.js的样子:

var gulp = require('gulp'),
    path = require('path'),
    replace = require('gulp-replace-task'),
    tap = require('gulp-tap');

gulp.task('svgbuild', function () {
    return gulp.src('*.txt')
        .pipe(tap(function (file) {
            return gulp.src(file.path)
                .pipe(replace({
                    patterns: [
                        {
                            match: /foo/g,
                            replacement: function () {
                                var ext = path.extname(file.path),
                                    base = path.basename(file.path, ext);

                                return base.toUpperCase() + '-inc'
                            }
                        }
                    ]
                }))
            .pipe(gulp.dest('build'));
        }));
});

如果我有一个path对象,那将很有帮助。我试着“仅仅”使用它,但没有用。我试着调试插件,看看哪些变量/对象有意义并且可以使用,但没有找到任何变量/对象