問題描述
我有一個應用程序.我的應用源代碼結構如下:
I have an app. My app source code is structured like this:
./
gulpfile.js
src
img
bg.png
logo.png
data
list.json
favicon.ico
web.config
index.html
deploy
我正在嘗試使用 Gulp 復制兩個文件:./img/bg.png 和 ./data/list.json.我想將這兩個文件復制到部署目錄的根目錄.也就是說,任務的結果應該是:
I am trying to use Gulp to copy two files: ./img/bg.png and ./data/list.json. I want to copy these two files to the root of the deploy directory. In other words, the result of the task should have:
./
deploy
imgs
bg.png
data
list.json
如何編寫 Gulp 任務來進行這種類型的復制?讓我感到困惑的是,我希望我的任務復制兩個單獨的文件,而不是適合某個模式的文件.我知道如果我有一個模式,我可以這樣做:
How do I write a Gulp task to do this type of copying? The thing that is confusing me is the fact that I want my task to copy two seperate files instead of files that fit a pattern. I know if I had a pattern, I could do this:
var copy = require('gulp-copy');
gulp.task('copy-resources', function() {
return gulp.src('./src/img/*.png')
.pipe(gulp.dest('./deploy'))
;
});
但是,我仍然不確定如何處理兩個單獨的文件.
Yet, I'm still not sure how to do this with two seperate files.
謝謝
推薦答案
您可以為每個目標目錄創建單獨的任務,然后使用通用的復制資源"任務將它們組合起來.
You can create separate tasks for each target directory, and then combine them using a general "copy-resources" task.
gulp.task('copy-img', function() {
return gulp.src('./src/img/*.png')
.pipe(gulp.dest('./deploy/imgs'));
});
gulp.task('copy-data', function() {
return gulp.src('./src/data/*.json')
.pipe(gulp.dest('./deploy/data'));
});
gulp.task('copy-resources', ['copy-img', 'copy-data']);
這篇關于使用 gulp 復制文件的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!