如何用gulp递归复制目录? [英] How do I copy directories recursively with gulp?
问题描述
我正在尝试从一个工作目录到一台服务器(同一台机器)进行一个项目。使用以下代码:
I am trying to stage a project from a working directory to a server (same machine). Using the following code:
gulp.src([
'index.php',
'css/**',
'js/**',
'src/**',
])
.pipe(gulp.dest('/var/www/'));
我希望看到所有的文件被复制。然而,它平坦的dir结构 - 所有的目录被复制,但每个文件都放在根 / var / www
I would expect to see all the files copied. However it flattens the dir structure - all directories are copied but every file is placed in the root /var/www
Gulp似乎是一个很好的构建工具,但复制项目应该是一个简单的过程?
Gulp seems like a great build tool but copying items should be a simple process surely?
推荐答案
需要为您的 gulp.src()
方法提供目录结构 gulp
。
Turns out that to copy a complete directory structure gulp
needs to be provided with a base for your gulp.src()
method.
所以 gulp.src([files],{base:。})
可以在上面的结构中使用复制所有的目录。
So gulp.src( [ files ], { "base" : "." })
can be used in the structure above to copy all the directories recursively.
如果像我一样,你可能会忘记这一点,然后尝试:
If, like me, you may forget this then try:
gulp.copy=function(src,dest){
return gulp.src(src, {base:"."})
.pipe(gulp.dest(dest));
};
这篇关于如何用gulp递归复制目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!