Gulp - 重命名文件扩展名

时间:2018-04-15 18:29:00

标签: gulp

场景:我有两个配置文件。使用gulp-rename,我想将它们从.config重命名为config.disabled

var rename = require("gulp-rename");
gulp.task("zzz_Remove-Useless-Files", function () {
    var files = [config.websiteRoot + "/App_config/ConnectionStrings.config", config.websiteRoot + "/App_config/RewriteRules.config"];
    return gulp.src(files).pipe(
        foreach(function (stream, file) {
            return gulp.src(file.path)
                .pipe(debug({ title: "Disabling " }))
                .pipe(rename(function (path) {
                    path.extname = ".config.disabled"
                }))
                .pipe(gulp.dest(file.base))
                .pipe(debug({ title: "Stream is now " }));
        })
    );
});

运行此任务会将文件重命名为.config.disabled;但是,它通过复制原始文件来实现。喜欢这个

config files

我做错了什么?

1 个答案:

答案 0 :(得分:1)

gulp-rename没有remove the src files。为了做到这一点,我必须这样做:

    var vinylPaths = require('vinyl-paths');
    var del = require("del");
    gulp.task("zzz_Remove-Useless-Files", function () {
        var files = [config.websiteRoot + "/App_config/ConnectionStrings.config", config.websiteRoot + "/App_config/RewriteRules.config"];
        return gulp.src(files).pipe(
            foreach(function (stream, file) {
                return gulp.src(file.path)
                    .pipe(debug({ title: "Disabling " }))
                    .pipe(rename(function (path) {
                        path.extname = ".config.disabled"
                    }))
                    .pipe(gulp.dest(file.base))
                    .pipe(debug({ title: "Stream is now " }))
                    .pipe(vinylPaths(del));
            })
        );
    });