2016-11-25 29 views
0

我有一口任務的問題:咕嘟咕嘟具有文件夾被命名爲喜歡的文件

gulp.task('css-dependencies', function() { 
    return gulp.src(['bower_components/**/*.css','!bower_components/**/*.min.css']) 
     .pipe(rename({dirname: './css'})) 
     .pipe(gulp.dest('./')); 
}); 

但是我想用animate.css並通過亭子加把它夾在工作正常的所有其他部件,所謂animate.css

Project 
|  
+-- bower_components 
    | 
    +-- animate.css 
     | 
     +--animate.css 
     +--animate.min.css (etc) 

導致的重命名任務一飲而盡失敗:

Error: EISDIR: illegal operation on a directory, open ‘~/css/animate.css' at Error (native)

除了特別豁免之外,我該如何解決這個問題?

+0

您需要粘貼不僅僅是代碼工作正常,你已經嘗試的代碼。 – catssay

+0

@catssay我的代碼不適用於我描述的情況。我可以爲它設置一個特定的用例,這將起作用,但不可擴展。由於src是一個模式匹配(我相信)我不能想辦法只匹配文件,而不是目錄。 – Rudiger

+0

我已經尋找吞的源代碼和描繪路徑的解釋,這是一個所謂的模塊[圓頂封裝體親本(https://github.com/es128/glob-parent)時,'bower_components/**/* .css'會給你的'bower_components'不bower_components/*',所以它實際上是在'歸還所有css文件bower_components'不'bower_components/*',如果你想在完全相同的文件'bower_components/*'父路徑,你需要像'bower_components/\ * */*。css'一樣轉義'*'。你可以在gulp項目中引發一個問題。 – catssay

回答

0

你的問題是,在gulp.src()模式兩樣東西相匹配:

  1. 目錄bower_component/animate.css
  2. 文件bower_component/animate.css/animate.css

然後你繼續做rename({dirname: './css'})這意味着你結束了:

  1. 目錄css/animate.css
  2. 的文件css/animate.css

兩者不能同時存在明顯。

你需要確保你在gulp.src()模式不匹配任何目錄本身(只有在這些目錄中的文件)的。

gulp.src()在內部使用glob,並且將gulp.src()的選項傳遞給glob。這意味着你可以使用globnodir option防止目錄被匹配:

return gulp.src(['bower_components/**/*.css','!bower_components/**/*.min.css'], {nodir:true}) 
    .pipe(rename({dirname: './css'})) 
    .pipe(gulp.dest('dist'));