0

我使用Gulp自動複製/捆綁/編譯我的文件,我基本上將整個文件夾結構從基礎文件夾(MyProject/Scripts)複製到wwwroot/js。在Gulp中將輸出目錄/文件更改爲小寫

在複製/處理過程中,我想將輸出路徑/文件名重命名爲小寫。我發現ChangeCase模塊和重命名模塊,但我無法讓它在我的設置下面工作。

gulp.task("compile:less", function() { 
    return gulp.src(paths.lessSrc) 
     .pipe(less()) 
     //how can I get to currentdirectory so I can use it for the rename? maybe there is another way 
     //.pipe(rename({ dirname: changeCase.lowerCase(??currentdir??) })) 
     .pipe(gulp.dest(paths.cssTarget)); 
}); 

gulp.task("compile:js", function() { 
    return gulp.src(paths.jsOrigin) 
     //simple copy of folders and files but how to rename all to lowercase? 
     .pipe(gulp.dest(paths.jsTarget)); 
}); 
+0

你嘗試只是把那種語法:目錄名稱:changeCase.lowerCase()?所以你只需使用函數進行dirname重命名。 – Prototype

+0

還沒有嘗試,但回答下面工作:)謝謝 – user2713516

回答

2

你可以傳遞一個回調函數來gulp-rename

gulp.task("compile:js", function() { 
    return gulp.src(paths.jsOrigin) 
    .pipe(rename(function(path) { 
     path.dirname = changeCase.lowerCase(path.dirname); 
     path.basename = changeCase.lowerCase(path.basename); 
     path.extname = changeCase.lowerCase(path.extname); 
    })) 
    .pipe(gulp.dest(paths.jsTarget)); 
}); 
+0

這工作:)謝謝 – user2713516

相關問題