2017-06-20 40 views
0

任務不工作:咕嘟咕嘟 - 保存不同的文件,以不同的路徑如預期

gulp.task('css', function() { 
    return gulp.src([ 
      'node_modules/bootstrap/dist/css/bootstrap.min.css' 
     ]) 
     .pipe(gulp.dest('public/assets/css')) 
     .pipe(gulp.src(['node_modules/bootstrap/dist/fonts/*'])) 
     .pipe(gulp.dest('public/assets/fonts')) 
}); 

預計產出將是

- assets/css 
    > bootstrap.min.css 
- assets/fonts 
    > glyphicons-halflings-regular.eot 
    > glyphicons-halflings-regular.svg 
    > glyphicons-halflings-regular.ttf 
    > glyphicons-halflings-regular.woff 
    > glyphicons-halflings-regular.woff2 

而是我所得到的是

- assets/css 
    > bootstrap.min.css 
- assets/fonts 
    > bootstrap.min.css 
    > glyphicons-halflings-regular.eot 
    > glyphicons-halflings-regular.svg 

注意

  • 引導CSS複製到Fonts目錄下,同時它不應該
  • 不是所有的字體被複制

這有什麼錯我的任務是什麼?

回答

1

你不能添加這樣的來源。當你添加.pipe(gulp.src)時,你仍然在處理上一個流,所以你的新src會被追加到前面的src中。你必須做的是從當前流出來。

gulp.task('css', function() { 
     gulp.src([ 
      'node_modules/bootstrap/dist/css/bootstrap.min.css' 
     ]) 
     .pipe(gulp.dest('public/assets/css')) 
     return gulp.src(['node_modules/bootstrap/dist/fonts/*']) 
     .pipe(gulp.dest('public/assets/fonts')) 
}); 

Gulpjs參考

https://github.com/gulpjs/gulp/blob/master/docs/recipes/using-multiple-sources-in-one-task.md

測試腳本

gulp.task('copy:csstest', function() { 
    gulp.src(['bower_components/bootstrap-sass/assets/stylesheets/_bootstrap.scss']).pipe(gulp.dest("build/scripts/folder1")); 
    return gulp.src(['bower_components/bootstrap-sass/assets/fonts/bootstrap/*']).pipe(gulp.dest("build/scripts/folder2")); 
}); 

enter image description here

+0

您的代碼不解決,因爲你設置的字體DST之前返回。但是,你的鏈接確實是合適的解決方案。也許編輯你的答案? – brazorf

+0

@brazorf你確定嗎?這個版本幾乎解決了這個問題。我附上我的測試腳本和結果。我正在使用gulp-3.9.0 – karthick