我正在尝试使用 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模板网!
Browserify,Babel 6,Gulp - 传播运算符上的意外令牌Browserify, Babel 6, Gulp - Unexpected token on spread operator(Browserify,Babel 6,Gulp - 传播运算符上的意外令牌)
是否可以将标志传递给 Gulp 以使其以不同的方式Is it possible to pass a flag to Gulp to have it run tasks in different ways?(是否可以将标志传递给 Gulp 以使其以不同的方式运行任务
为什么我们需要在全局和本地安装 gulp?Why do we need to install gulp globally and locally?(为什么我们需要在全局和本地安装 gulp?)
如何一个接一个地依次运行 Gulp 任务How to run Gulp tasks sequentially one after the other(如何一个接一个地依次运行 Gulp 任务)
由于 MIME 类型而未加载样式表Stylesheet not loaded because of MIME-type(由于 MIME 类型而未加载样式表)
打开 Javascript 文件时 Visual Studio 2015 崩溃Visual Studio 2015 crashes when opening Javascript files(打开 Javascript 文件时 Visual Studio 2015 崩溃)