問題描述
我正在嘗試使用 Gulp 將文件從一個文件夾復制到另一個文件夾:
I am trying to copy files from one folder to another folder using Gulp:
gulp.task('move-css',function(){
return gulp.src([
'./source/css/one.css',
'./source/other/css/two.css'
]).pipe(gulp.dest('./public/assets/css/'));
});
以上代碼是復制one.css
&two.css
到 public/assets/css
文件夾.
The above code is copying one.css
& two.css
to the public/assets/css
folder.
如果我使用 gulp.src('./source/css/*.css')
它會將所有 CSS 文件復制到 public/assets/css
這不是我想要的文件夾.
And if I use gulp.src('./source/css/*.css')
it will copy all CSS files to the public/assets/css
folder which is not what I want.
如何選擇多個文件并保持文件夾結構?
How do I select multiple files and keep the folder structure?
推薦答案
為此請指定base
.
? base - 指定相對于 cwd 的文件夾.默認是 glob 開始的地方.這用于在 .dest()
? base - Specify the folder relative to the cwd. Default is where the glob begins. This is used to determine the file names when saving in
.dest()
<小時>
在你的情況下是:
In your case it would be:
gulp.task('move-css',function(){
return gulp.src([
'./source/css/one.css',
'./source/other/css/two.css'
], {base: './source/'})
.pipe(gulp.dest('./public/assets/'));
});
文件夾結構:
.
├── gulpfile.js
├── source
│ ├── css
│ └── other
│ └── css
└── public
└── assets
這篇關于如何使用 Gulp 復制多個文件并保持文件夾結構的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!