如何使用 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/'));
我希望看到复制的所有文件.但是它使目录结构变平 - 所有目录都被复制,但每个文件都放在根目录 /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
需要为你的 gulp.src()
方法.
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屋!